溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

樹莓派3怎么安裝archlinux配置web與samba還有aria2

發(fā)布時(shí)間:2021-10-22 09:33:07 來(lái)源:億速云 閱讀:146 作者:柒染 欄目:互聯(lián)網(wǎng)科技

樹莓派3怎么安裝archlinux配置web與samba還有aria2,針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。

1.配置web服務(wù)(基于LAMP)

英文文檔比較豐富:https://wiki.archlinux.org/index.php/Apache_HTTP_Server

1.1 先安裝Apache、PHP

pacman -Sy php php-apache php-gd

【上面命令會(huì)自動(dòng)安裝Apache、PHP】

先啟動(dòng)一下Apache看報(bào)什么錯(cuò)誤

[root@alarm alarm]# apachectl

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::ba27:ebff:fe34:38d5. Set the 'ServerName' directive globally to suppress this message

配置apache:

vi /etc/httpd/conf/httpd.conf

查找ServerName,會(huì)看到#ServerName www.example.com:80。把前面的注釋#去掉,然后改成你自己的主機(jī)名,如果是本機(jī)可以改成:

SeverName localhost:80

https://wiki.archlinux.org/index.php/Apache_HTTP_Server

在 /etc/httpd/conf/httpd.conf中找到下面這行,并注釋掉:

#LoadModule mpm_event_module modules/mod_mpm_event.so

找到下面這行,把前面的#去掉。

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

To enable PHP, add these lines to /etc/httpd/conf/httpd.conf:

在 LoadModule 列表末尾加上下面兩句(我的是在185行后面,不同版本的配置文件不同,自己看):

LoadModule php7_module modules/libphp7.so
AddHandler php7-script .php

在 Include列表末尾加上下面這句:

Include conf/extra/php7_module.conf

sytemctl重啟 httpd.service 服務(wù).

sytemctl httpd.service restart

測(cè)試PHP的配置: 在你的Apache DocumentRoot 目錄 (譬如 /srv/http/ or ~/public_html) 中創(chuàng)建test.php 文件,內(nèi)容如下:

<?php phpinfo(); ?>

 可以通過(guò)如下命令直接創(chuàng)建

echo "<?php phpinfo(); ?>" /srv/http/test.php

注意目錄的文件權(quán)限屬性

sudo chmod +x -R /srv/http/

瀏覽器中輸入:

 http://localhost/test.php

1.2 安裝mysql(官方默認(rèn)mariadb)

具體配置見(jiàn):https://wiki.archlinux.org/index.php/MySQL

pacman -Sy mariadb

安裝完mariadb后,先別急著啟動(dòng)mariadb.service服務(wù),先運(yùn)行如下命令:

mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

現(xiàn)在可以啟動(dòng)mariadb.service服務(wù)了。

systemctl start mysqld

然后需要將MySQL設(shè)置開機(jī)啟動(dòng):

systemctl enable mysqld

接下來(lái)給mariadb進(jìn)行安全設(shè)置

mysql_secure_installation

先回車,然后一路y下去,期間兩次需要輸入root的密碼

新增普通用戶

$ mysql -u root -p
MariaDB> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
MariaDB> GRANT ALL PRIVILEGES ON mydb.* TO 'monty'@'localhost';
MariaDB> FLUSH PRIVILEGES;
MariaDB> quit
GRANT ALL PRIVILEGES ON *.* TO 'bysu'@'localhost' IDENTIFIED VIA unix_socket WITH GRANT OPTION;
GRANT PROXY ON ''@'%' TO 'bysu'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
 FLUSH PRIVILEGES;

顯示授權(quán)信息,我是按照root的來(lái)授權(quán)的。

SHOW GRANTS FOR 'yangfan'@'localhost';

1.3設(shè)置PHP支持mariadb

在 /etc/php/php.ini文件中取消其注釋(刪掉行首的;號(hào)即可):

extension=pdo_mysql.so
extension=mysqli.so

注意: mysql.so 在 PHP 7.0中已經(jīng)被移除了.

測(cè)試php是否連接mariadb。

vi /srv/html/conn.php #新建一個(gè)conn.php文件

把下面的內(nèi)容輸入conn.php文件中。 

<?php  
    $db = new mysqli('localhost', 'root', 'admin', 'test');  
    if (mysqli_connect_errno())  
    {  
        echo '<p>' . 'Connect DB error';  
        exit;  
    } 
    else{
        echo 'successful';
    }
?>
curl http://192.168.31.146/conn.php    #其中192.168.31.146為你本機(jī)的ip,請(qǐng)自行更改

不出意外的話,那么你會(huì)看到頁(yè)面輸入successful

如果需要通過(guò)上面這種方式(終端curl命令)查看php的版本號(hào)

更改上面的conn.php的內(nèi)容為

<?
phpinfo();
?>
或者使用phpversion()函數(shù)
<?
echo phpversion();
?>

其他配置參考官方文檔。下面從官方文檔摘選一部分。

1.4 Configuration files

MariaDB configuration options are read from the following files in the given order (according to mysqld --help --verbose output):

/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

Depending on the scope of the changes you want to make (system-wide, user-only...), use the corresponding file. See this entry of the KnowledgeBase for more information.

Grant remote access

Warning: This is not considered as best practice and may cause security issues. Consider using Secure Shell, VNC or VPN, if you want to maintain the MySQL-server outside and/or inside your LAN.

If you want to access your MySQL server from other LAN hosts, you have to edit the following lines in /etc/mysql/my.cnf:

[mysqld]
   ...
   #skip-networking
   bind-address = <some ip-address>
   ...

Grant any MySQL user remote access (example for root):

$ mysql -u root -p

Check current users with remote access privileged:

SELECT User, Host FROM mysql.user WHERE Host <> 'localhost';

Now grant remote access for your user (here root)::

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.%' IDENTIFIED BY 'my_optional_remote_password' WITH GRANT OPTION;

You can change the '%' wildcard to a specific host if you like. The password can be different from user's main password.

Disable remote access

The MySQL server is accessible from the network by default. If MySQL is only needed for the localhost, you can improve security by not listening on TCP port 3306. To refuse remote connections, uncomment the following line in /etc/mysql/my.cnf:

skip-networking

You will still be able to log in from the localhost.

2.安裝samba--搭建NAS

安裝samba

sudo pacman -S samba

查看samba的狀態(tài)

[bysu@centos-rpi3 ~]$ sudo systemctl status samba

samba服務(wù)設(shè)為開機(jī)啟動(dòng)

systemctl enable smb

systemctl start smb    #啟動(dòng)samba服務(wù)
systemctl restart smb  #重啟samba服務(wù)
systemctl stop smb     #停止samba服務(wù)

使用testparm測(cè)試samba配置是否正確

testparm

在Linux上測(cè)試

smbclient -L localhost   #root賬戶不用密碼

創(chuàng)建samba用戶,可以使用Linux原本的用戶

smbpasswd -a bysu

創(chuàng)建共享目錄

[root@base samba]# mkdir -p /smb/{guest,bysu}
[root@base samba]# chown nobody:nobody /media/samba/guest/
[root@base samba]# chown bysu:bysu /media/samba/bysu/

注意設(shè)置屬性,不然訪問(wèn)不了。

配置samba的配置文件

sudo vi /etc/samba/smb.conf

Samba 配置文件詳解,抄自

Samba 的配置文件 /etc/samba/smb.conf 分為兩大部分,一部分是 [global] ,即全局配置,另一部分是 [home] 、[printer] 、[自定義共享名] ,這些都是共享的部分,共享部分的設(shè)置優(yōu)先級(jí)高于全局配置,另外,Samba 默認(rèn)開啟本地用戶家目錄 [home] 和打印機(jī) [printer] 的共享,如果不需要你也可以關(guān)閉這兩個(gè)共享,然后在末行自己重新創(chuàng)建一個(gè)共享,下面是詳細(xì)的配置,你可以自定義一個(gè)共享,然后自己選擇需要哪些配置:

[pzk]                                      # 自定義共享名
comment = Home Directories                 # 描述符,是給系統(tǒng)管理員看的
path = /tmp                                # 共享的路徑
public = yes                               # 是否公開,也就是是否能在網(wǎng)上鄰居看到該共享
browseable = yes                           # 共享的目錄是否讓所有人可見(jiàn)
writable = yes                             # 是否可寫
guest ok = no                              # 是否拒絕匿名訪問(wèn),僅當(dāng)安全級(jí)別為 share 時(shí)才生效
workgroup = WORKGROUP                      # 工作組,要設(shè)置成跟 Windows 的工作組一致
server string = Samba Server Version %v    # 其他 Linux 主機(jī)查看共享時(shí)的提示符
netbios name = MYSERVER                    # 用于在 Windows 網(wǎng)上鄰居上顯示的主機(jī)名
hosts allow = 127. 192.168.12. 192.168.13. EXCEPT 192.168.13.13   # 指定允許訪問(wèn) samba 服務(wù)器的主機(jī)    
security = share                           # 定義安全級(jí)別
log file = /var/log/samba/log.%m           # 定義日志文件,每個(gè)訪問(wèn)的主機(jī)會(huì)產(chǎn)生獨(dú)立的日志文件,%m 是客戶端主機(jī)名
max log size = 50                          # 定義單個(gè)日志的最大容量(KB)
passdb backend = tdbsam                    # Samba 用戶的存儲(chǔ)方式,smbpasswd 表示明文存儲(chǔ),tdbsam 表示密文存儲(chǔ)
deadtime = 10                              # 客戶端在10分鐘內(nèi)沒(méi)有打開任何 Samba 資源,服務(wù)器將自動(dòng)關(guān)閉會(huì)話,在大量的并發(fā)訪問(wèn)環(huán)境中,這樣的設(shè)置可以提高服務(wù)器性能
display charset = UTF8                     # 設(shè)置顯示的字符集
max connections = 0                        # 設(shè)置最大連接數(shù),0表示無(wú)限制,如果超過(guò)最大連接數(shù)則拒絕連接
guest account = nobody                     # 設(shè)置匿名賬戶為nobody
load printers = yes                        # 是否在啟動(dòng) Samba 時(shí)就共享打印機(jī)    
cups options = raw                         # 設(shè)置打印機(jī)使用的方式
valid users = user1 user2    user3         # 指定哪些用戶可以訪問(wèn),如果不指定則所有用戶都可訪問(wèn)
invalid users = user1 user2                # 指定哪些用戶不可以訪問(wèn)
create mask = 0775                         # 客戶端上傳文件的默認(rèn)權(quán)限
directory mask = 0775                      # 客戶端創(chuàng)建目錄的默認(rèn)權(quán)限
write list = user1 user2 user3             # 設(shè)置可對(duì)文件進(jìn)行寫操作的用戶
admin users = user1                        # 設(shè)置共享目錄的管理員,具有完全權(quán)限
安全級(jí)別:
share :表示匿名用戶,不需要 samba 賬戶就可登陸 samba 服務(wù)器
user :系統(tǒng)賬戶要先添加進(jìn) samba 庫(kù)然后變成 samba 用戶,使用 samba 用戶來(lái)登陸,簡(jiǎn)單來(lái)講就是需要使用用戶密碼登錄
server :由另外一臺(tái) samba 服務(wù)器來(lái)對(duì)用戶進(jìn)行身份驗(yàn)證
domain :把 samba 服務(wù)器加入到 NT 域,由 NT 的域控制器來(lái)進(jìn)行身份驗(yàn)證
ADS :(Active Directory Service,活動(dòng)目錄服務(wù)),是 samba3.0 中新增的身份驗(yàn)證方式,采用 ADS 驗(yàn)證方式,samba 服務(wù)器集成到活動(dòng)目錄中

3.aria2的下載安裝、配置

sudo pacman -S aria2

創(chuàng)建aria2.conf和aria2.session

sudo vi /etc/aria2.conf
sudo vi /etc/aria2.session

編輯文件aria2.con,寫入如下內(nèi)容

# dir=/data/download         
#下載文件保存目錄,建議掛載移動(dòng)硬盤,SD卡經(jīng)不住這么玩兒

#因?yàn)槲覀兪且?nbsp;pi 用戶執(zhí)行的aria2c 進(jìn)程,所以這里此目錄的讀寫權(quán)限
  # sudo chown -R pi:pi /data/download
    
#打開rpc的目的是為了給web管理端用 
#configuration file for aria2c
enable-rpc=true
rpc-allow-origin-all=true
rpc-listen-all=true
  
#rpc-listen-port=6800
file-allocation=none
disable-ipv6=true
disk-cache=32M
 plit=3
 max-concurrent-downloads=3
 max-connection-per-server=3
 max-file-not-found=3
 ## 最大重試次數(shù),0代表可以無(wú)限次重試
 max-tries=5
 retry-wait=3
   continue=true
   check-integrity=true
   log-level=error
   log=/var/log/aria2.log
     
   input-file=/etc/aria2/aria2.session
   save-session=/etc/aria2/aria2.session
      
   dir=/media/pi/bysu

創(chuàng)建aria2.service文件(開機(jī)啟動(dòng)文件)

sudo vi /usr/lib/systemd/system/aria2.service

#加入如下內(nèi)容

[Unit]
Description=Aria2 Service
After=network.target

[Service]
ExecStart=/usr/bin/aria2c --enable-rpc --rpc-listen-all --rpc-allow-origin-all --save-session /etc/aria2/aria2.session --input-file /etc/aria2/aria2.session --conf-path=/etc/aria2/aria2.conf
#ExecStart=/usr/bin/aria2c --enable-rpc --rpc-listen-all --rpc-allow-origin-all --save-session %h/.config/aria2/session.lock --input-file %h/.config/aria2/session.lock --conf-path=%h/.config/aria2/aria2.conf

[Install]
WantedBy=default.target

啟動(dòng)aria2服務(wù)

sudo systemctl start aria2

#設(shè)為開機(jī)啟動(dòng)
sudo sytemctl enable aria2
  1. 終端輸入:

  2. aria2c  --enable-rpc  --rpc-listen-all #啟用監(jiān)聽RPC


    安裝aria2的頁(yè)面端webui

    cd /srv/html
    git clone https://github.com/ziahamza/webui-aria2.git


    用瀏覽器訪問(wèn) http://pi的IP地址或主機(jī)名 即可看到webui的界面,在此界面添加下載任務(wù)測(cè)試即可

  3. 在電腦上的chrome瀏覽器上安裝『百度云導(dǎo)出到aria2』插件,以方便在電腦上直接將百度云盤上的文件添加至aria2,插件下載地址為:

    https://github.com/acgotaku/BaiduExporter


    初次安裝完成后需要配置aria2 PRC地址,一般來(lái)說(shuō)是

    http://192.168.31.42/webui-aria2/index.html


    完成后使用導(dǎo)出按鈕來(lái)測(cè)試效果:樹莓派3怎么安裝archlinux配置web與samba還有aria2

  4. 添加定時(shí)下載的腳本

    cd /etc/aria2
    wget https://github.com/bostoneboy/raspberry_pi_stuff/raw/master/aria2/aria2_auto.py
    crontab -e
     * * * * /usr/bin/python2 /etc/aria2/aria2_auto.py


    此腳本的作用是每天晚上6時(shí)暫停所有正在下載的任務(wù),每天凌晨3時(shí)開始所有的下載任務(wù),即上班時(shí)候和凌晨才會(huì)開啟脫機(jī)下載功能,腳本里面的時(shí)候可以根據(jù)需要自己來(lái)修改。

 aria2上傳百度云盤-未完待續(xù)

(該節(jié)點(diǎn)內(nèi)容參考《開源硬件創(chuàng)客.15個(gè)酷應(yīng)用玩轉(zhuǎn)樹莓派》和朝聞道)

因?yàn)橛玫絧ython腳本,所以要配置好相關(guān)環(huán)境(前提已經(jīng)安裝好python,如果需要可以參考我前面的教程)。

安裝pip。

sudo pacman -Syyu       #更新系統(tǒng)
sudo pacman -S python-pip    #安裝python的pip包管理工具
sudo pip install rpi.gpio   #安裝python的GPIO庫(kù)
sudo pip install requests   #安裝python的Requests庫(kù)

下載百度云python客戶端

sudo git clone https://github.com/lyhonk/bypy.git       #我通過(guò)這種方式授權(quán)不成功
或者可以通過(guò)pip來(lái)安裝bypy
sudo pip install bypy                                   #通過(guò)這種方式安裝,我的授權(quán)成功了

下載完成之后,進(jìn)入bypy目錄

cd bypy

執(zhí)行

sudo python bypy.py info

 如果報(bào)如下錯(cuò)誤,需要更改系統(tǒng)的編碼

[bysu@alarm bypy]$ sudo python bypy.py -m info
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
WARNING: Can't detect the system encoding, assume it's 'UTF-8'.
Files with non-ASCII names may not be handled correctly.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[bysu@alarm bypy]$ sudo vi /etc/locale.conf

LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:en_GB:en"

[bysu@alarm bypy]$ sudo locale-gen

更改系統(tǒng)編碼之后,繼續(xù)運(yùn)行

[bysu@alarm bypy]$ sudo python bypy.py info
Please visit:
https://openapi.baidu.com/oauth/2.0/authorize?client_id=q8WE....lgMKNBn&response_type=code&redirect_uri=oob&scope=basic+netdisk
And authorize this app
Paste the Authorization Code here within 10 minutes.
Press [Enter] when you are done

如果修改系統(tǒng)的編碼還是不行的話,可以試著按照下面來(lái)設(shè)置python的編碼,先看一下python的編碼,可以看到使用的編碼卻是是跟上述提示的編碼一直,都是ANSI_X3.4-1968。

Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getpreferredencoding()
'ANSI_X3.4-1968'
>>> import sys
>>> sys.getfilesystemencoding()
'ascii'
>>>

可以通過(guò)export來(lái)設(shè)置,不過(guò)聽說(shuō)只能當(dāng)前環(huán)境有效,我就是通過(guò)這種方式臨時(shí)處理了一下

export PYTHONIOENCODING=UTF-8

網(wǎng)上針對(duì)python2.7的持久解決方案,python3.3+的暫時(shí)沒(méi)找到解決方案,我能想到的方案就是把系統(tǒng)的默認(rèn)python版本暫時(shí)更改為python2.7.

在python2.7的目錄新建文件
sudo vi /usr/lib/python2.7/site-packages/sitecustomize.py
內(nèi)容為:
import sys
reload(sys)
sys.setdefaultencoding('utf8')

在瀏覽器中登錄你的百度云盤,然后新建一個(gè)標(biāo)簽,把上面的

https://openapi.baidu.com...basic+netdisk行的內(nèi)容(鏈接),在新建的瀏覽器標(biāo)簽的地址欄訪問(wèn),得到一串授權(quán)碼,并于剛剛的linux終端中輸入,回車...可以看到successfully和云盤的總?cè)萘亢褪褂每臻g的大小。

Authorizing,please be patient,it may take upto None seconds...
Authorizing/refreshing with the OpenShift server...
OpenShift server failed,authorizing/refreshing with the Heroku server...
Successfully authorized
Quota:3.011TB
Used:2.928TB

如果提示相關(guān)授權(quán)的問(wèn)題,可以運(yùn)行bypy.py -c,刪除令牌文件,然后重新授權(quán)一次。如果還不行,去百度應(yīng)用授權(quán)里刪除bypy再重新授權(quán)。

上傳到百度云盤后,可以到云盤一下目錄查看

/我的應(yīng)用數(shù)據(jù)/bypy

到了這一步,差不多。最近熬夜甚多,為免猝死,暫且放下吧!

關(guān)于樹莓派3怎么安裝archlinux配置web與samba還有aria2問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI