Raspberry Pi(中文名“樹莓派”),是只有信用卡大小的微型電腦,其系統基於Linux。為了改善學校宿舍的上網環境(校園網登陸系統導致不能用路由器多設備通用網絡),通過樹莓派訪問校園網登陸系統上網並且24小時開機分享熱點實現24小時多設備上網。
1、准備材料:
我所用到的設備
(1)一塊樹莓派以及電源
(2)一根HDMI線
(3)一根網線
(4)一塊500G硬盤
(5)硬盤座
(6)顯示器
(7)筆記本電腦
(8)tf卡讀卡器
2、下面按照我的使用步驟進行記錄:
- 樹莓派安裝操作系統
- 用讀卡器將樹莓派NOOBS操作系統解壓縮至tf卡中。注意!不要把解壓后的文件夾拖入tf卡中,應該點進文件夾,同時按ctrl+A將所有文件復制進tf卡中;
- 將tf卡插入樹莓派,將除了電源以外的線都接好,包括散熱風扇、硬盤、屏幕HDMI線等,其中網線接在宿舍上網端口上,最后接上電源,樹莓派啟動;
- 最后,根據系統提示安裝好操作系統,進入桌面;
- 樹莓派初始的登錄用戶名:pi初始密碼:raspberry
-
sudo passwd root #設置root密碼
sudo passwd -u root #解鎖root用戶
- 樹莓派通過HDMI連接顯示器
- 很明顯,使用顯示器的我發現有一點不對勁,樹莓派桌面顯示居然有黑邊,於是上網查找解決辦法;
- 打開config.txt:sudo nano /boot/config.txt;
- 在默認情況下,取消注釋(取消“#”)修改下面這段,
overscan_left=-16
overscan_right=-16
overscan_top=-16
overscan_bottom=-16
樹莓派的顯示輸出就占滿了屏,關於后面的“-16”這個數字,根據自己的屏實際情況來確定。
- 樹莓派通過VNC由筆記本控制
- 輸入命令行sudo raspi-config;
- 選擇5.Interfacing Options;
- 找到VNC(遠程桌面),選擇 Yes(是)。
- 樹莓派安裝熱點分享程序create_ap
- 將代碼clone到本地
sudo git clone https://github.com/oblique/create_ap cd create_ap sudo make install
- 安裝依賴的庫
sudo apt-get install util-linux procps hostapd iproute2 iw haveged dnsmasq
- 打開熱點(此時,樹莓派wifi開着,但沒有連wifi)
sudo create_ap wlan0 eth0 熱點名 密碼
- 此時不出意外熱點將會開啟,但是會有warn,可以執行以下代碼
sudo create_ap --no-virt wlan0 eth0 m熱點名 熱點
- 以服務方式啟動,執行開機自啟
#1.修改服務配置,添加--no-virt參數 sudo vi /usr/lib/systemd/system/create_ap.service # 將 ExecStart=/usr/bin/create_ap --config /etc/create_ap.conf # 修改為 ExecStart=/usr/bin/create_ap --no-virt --config /etc/create_ap.conf #2.默認配置文件/etc/create_ap.conf,將下面兩橫改為自己的ssid和密碼即可,修改自己的dhcp網關 sudo vi /etc/create_ap.conf # 將 GATEWAY=10.0.0.1 SSID=MyAccessPoint PASSPHRASE=12345678 # 修改為 GATEWAY=192.168.123.1 SID=dzxj PASSPHRASE=11111111 # 啟動一個服務: systemctl start create_ap.service # 關閉一個服務: systemctl stop create_ap.service # 重啟一個服務: systemctl restart create_ap.service # 顯示一個服務的狀態: systemctl status create_ap.service # 在開機時啟用一個服務: systemctl enable create_ap.service # 在開機時禁用一個服務: systemctl disable create_ap.service # 查看服務是否開機啟動: systemctl is-enabled create_ap.service
- 異常一:WARN: brmfmac driver doesn't work properly with virtual interfaces and it can cause kernel panic. For this reason we disallow virtual interfaces for your adapter.For more info: https://github.com/oblique/create_ap/issues/203
ERROR: Your adapter can not be a station (i.e. be connected) and an AP at the same time處理:sudo nmcli dev dis wlan0
- 異常二:
sudo create_ap wlan0 eth0 my_raspi 88166908
WARN: brmfmac driver doesn't work properly with virtual interfaces and it can cause kernel panic. For this reason we disallow virtual interfaces for your adapter. For more info: https://github.com/oblique/create_ap/issues/203 WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt Config dir: /tmp/create_ap.wlan0.conf.cDxIozig PID: 1132 Network Manager found, set wlan0 as unmanaged device... DONE/bin/create_ap: line 1669: dnsmasq: command not foundERROR: Wrong version format!
處理: sudo yum install dnsmasq -y
- 異常三:
sudo create_ap wlan0 eth0 my_raspi 12345678
WARN: brmfmac driver doesn't work properly with virtual interfaces andit can cause kernel panic. For this reason we disallow virtual interfaces for your adapter. For more info: https://github.com/oblique/create_ap/issues/203 WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt Config dir: /tmp/create_ap.wlan0.conf.gC5KSqVQ PID: 2497 Sharing Internet using method: nat hostapd command-line interface: hostapd_cli -p /tmp/create_ap.wlan0.conf.gC5KSqVQ/hostapd_ctrl Configuration file: /tmp/create_ap.wlan0.conf.gC5KSqVQ/hostapd.conf處理: sudo create_ap --no-virt wlan0 eth0 my_raspi 12345678
Failed to create interface mon.wlan0: -95 (Operation not supported)
- 將代碼clone到本地
- 樹莓派安裝seafile,首先seafile-7.0.4安裝包有一個bug,在自定義輸入seafile依賴文件夾時會出錯。查詢相關問題解決辦法后發現依然沒用。。。。那我就退而求其次安裝了seafile-6.3.4,以后有時間再研究7.0.4版本。
- 掛載移動硬盤
#確認硬盤已經插好,查看狀態 sudo fdisk -l #找到硬盤的Device項目,應該為/dev/sda1,然后 df -h #發現硬盤並未掛載,下面創建掛載目錄 sudo mkdir /home/pi/toshiba #然后把硬盤掛載在這個目錄 sudo mount /dev/sda1 /home/pi/toshiba #再次 df -h #發現硬盤以及掛載在了相應的目錄了,但是我們的硬盤是NTFS格式的,Linux不能直接讀取,下面安裝NTFS格式可讀寫軟件 sudo aptitude install ntfs-3g #加載內核模塊 modprobe fuse #讓移動硬盤開機自動掛載 sudo nano /etc/fstab #在文件的最后一行添加 /dev/sda1 /home/pi/toshiba ntfs-3g defaults,noexec,umask=0000 0 0 #有時若掛載出錯,報錯Mount is denied,用命令 sudo fuser -m -u /dev/sda1sudo kill 1308 #再按照步驟重新掛載。
- 安裝seafile所需依賴
sudo apt-get update sudo apt-get install python2.7 libpython2.7 python-setuptools python-imaging python-ldap python-urllib3 sqlite3 python-requests
至此,樹莓派的環境已經初始化完畢,適合安裝seafile。
- 安裝並部署seafile
先將seafile安裝包在官網上現在下來,放在/home/pi/seafile文件夾中。
cd /home/pi/seafile
然后解壓文件夾
sudo tar -xzf seafile-server_6.3.4_stable_pi.tar.gz
接着安裝seafile
cd seafile-server-6.3.4 sudo ./setup-seafile.sh
之后根據提示填寫信息部署seafile
Press [Enter] to continue#此處按回車繼續 [sever name]: #此處給服務器起一個名字 [This server’s ip or domain]: #輸入局域網內樹莓派的IP Where would you like to store your seafile data?Note: Please use a volume with enough free space.[default: /home/pi/seafile/seafile-data ]#高度注意!!此處是在指定seafile的數據存放位置,因為之前掛載了硬盤,切不可直接按默認設置,需要改到硬盤目錄下,你可以填寫/home/pi/toshiba/seafile-data What tcp port do you want to use for seafile fileserver?8082 is the recommended port.[default: 8082 ]# seafile服務器的端口號,默認8082,回車表示默認即可,若自行修改則要額外開放端口 If you are OK with the configuration, press [ENTER] to continue.# 這里確認你的seafile服務器配置,沒問題繼續回車----------------------------------------------------------------- Seahub is the web interface for seafile server.Now let's setup seahub configuration. Press [ENTER] to continue ----------------------------------------------------------------- # 這里開始安裝seahub,回車繼續----------------------------------------------------------------- Your seafile server configuration has been completed successfully. ----------------------------------------------------------------- # 已經安裝完成了,下邊是告訴你怎么啟動安裝好的程序。 run seafile server: ./seafile.sh { start | stop | restart } run seahub server: ./seahub.sh { start <port> | stop | restart <port> } ----------------------------------------------------------------- If the server is behind a firewall, remember to open these tcp ports: ----------------------------------------------------------------- # 下邊是程序要使用的端口,如果開啟了防火牆,需要開放這兩個端口。 port of seafile fileserver: 8082 port of seahub: 8000
這時安裝並沒有結束,由於seafile-6.3.4所需python-urllib3版本為1.23,而現在已經到了1.25版本,所以還需執行以下代碼:
sudo pip install urllib3==1.23
- 開啟seafile
執行下列代碼:
cd /home/pi/seafile/seafile-server-6.3.4 sudo ./seafile.sh start sudo ./seahub.sh start
此時需要配置管理員賬號和密碼,按要求輸入即可。
最后可以在瀏覽器訪問:IP:8000 到達seafile“雲盤”管理頁面。 - 開啟重新啟動
#首先創建seafile服務文件 sudo nano /etc/systemd/system/seafile.service #輸入下列內容 [Unit] Description=Seafile # add mysql.service or postgresql.service depending on your database to the line below After=network.target [Service] Type=oneshot ExecStart=${seafile_dir}/seafile-server-latest/seafile.sh start ExecStop=${seafile_dir}/seafile-server-latest/seafile.sh stop RemainAfterExit=yes User=seafile Group=seafile [Install] WantedBy=multi-user.target #再創建seahub啟動文件 sudo nano /etc/systemd/system/seahub.service 輸入下列內容 [Unit] Description=Seafile hub After=network.target seafile.service [Service] # change start to start-fastcgi if you want to run fastcgi ExecStart=${seafile_dir}/seafile-server-latest/seahub.sh start ExecStop=${seafile_dir}/seafile-server-latest/seahub.sh stop User=seafile Group=seafile Type=oneshot RemainAfterExit=yes [Install] WantedBy=multi-user.target #最后設置開機自啟動 sudo systemctl enable seafile.service sudo systemctl enable seahub.service
這樣開機自啟動就設置完成了
- 掛載移動硬盤
3、總結
由於樹莓派3b+硬件的限制,通過開熱點上網網速有點慢,不過不玩lol等游戲,對我的影響不大。做seafile主要是為了利用一下從舊電腦上拆下來的500G的硬盤,局域網內seafile上傳的文件被進行分塊加密,同時下載速度感人,估計筆記本手機在線看電影是不可能的了。下一步可能會利用雲服務器DDNS服務內網穿透一下,再看看樹莓派有什么新玩法。
4、感謝
非常感謝知乎用戶ddch對我的幫助,其中seafile有關內容來自ddch文章“樹莓派3B+部署seafile的實錄”。
https://zhuanlan.zhihu.com/p/57202972