刷機(jī)步驟
1.從build-imou-sn1下載喜歡的linux發(fā)現(xiàn)版本,用balenaetcher寫(xiě)盤(pán)工具寫(xiě)入U(xiǎn)盤(pán)(特定U盤(pán)才有效(我的是EAGET16G))
2.接上網(wǎng)線,插上U盤(pán)USB2.0口后上電啟動(dòng),
3.通過(guò)ssh or TTL 連接登錄到alpine恢復(fù)系統(tǒng)。
ssh root@imou-sn1
4.在alpine系統(tǒng)中執(zhí)行emmc-install.sh,寫(xiě)入固件
等燈變?yōu)榘咨赐瓿伞?/p>
imou-sn1:~# emmc-install.sh
flash emmc mbr...
1+0 records in
1+0 records out
512 bytes copied, 0.00471775 s, 109 kB/s
flash emmc ext4 fs...
848MiB 0:00:39 [21.5MiB/s] [==========================>] 100%
0+6782 records in
0+6782 records out
889192448 bytes (889 MB, 848 MiB) copied, 62.0352 s, 14.3 MB/s
flash done, please poweroff now then unplug USB drive!
5.寫(xiě)入完成后,根據(jù)提示執(zhí)行poweroff命令關(guān)機(jī),斷電后拔出U盤(pán),再拔掉電源上電開(kāi)機(jī),刷機(jī)完成。
掛在以及格式化硬盤(pán)
因?yàn)闄C(jī)器自帶硬盤(pán)只有4G大小,能力有限,不知道有沒(méi)有方法可以擴(kuò)展root目錄,只有掛在硬盤(pán)只會(huì)mount,
1.使用fdisk -l查看目前磁盤(pán)情況,根據(jù)情況操作對(duì)應(yīng)磁盤(pán)。
root@imou-sn1:~# fdisk -l
Disk /dev/mmcblk1: 3.7 GiB, 3959422976 bytes, 7733248 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf6a78990
Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1 8192 7733247 7725056 3.7G 83 Linux
Disk /dev/sda: 74.54 GiB, 80026361856 bytes, 156301488 sectors
Disk model: Hitachi HTS54328
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
這里我用了一款80G的垃圾盤(pán)做測(cè)試,可以看到是/dev/sda
2.分區(qū)格式化
輸入命令fdisk /dev/sda
root@imou-sn1:~# fdisk /dev/sda
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
The old ext4 signature will be removed by a write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xc67aca5b.
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-156301487, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-156301487, default 156301487):
Created a new partition 1 of type 'Linux' and of size 74.5 GiB.
Command (m for help):
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
此處磁盤(pán)數(shù)據(jù)沒(méi)什么用直接全新操作。一頓輸入 m n 回車回車回車
最后w保存操作即完成。
接下來(lái)格式化為ext4文件系統(tǒng)
mkfs -t ext4 /dev/sda
操作步驟:y 然后一頓回車等待完成即可
root@imou-sn1:~# mkfs -t ext4 /dev/sda
mke2fs 1.45.5 (07-Jan-2020)
Found a dos partition table in /dev/sda
Proceed anyway? (y,N) y
Creating filesystem with 19537686 4k blocks and 4890624 inodes
Filesystem UUID: 3ad32c9e-60a7-4ab6-b54c-ed507cdeb546
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks):
done
Writing superblocks and filesystem accounting information: done
最終查看檢查一下ll /dev/sda
root@imou-sn1:~# ll /dev/sda
brw-rw---- 1 root disk 8, 0 Dec 4 22:20 /dev/sda
信息看出來(lái)sda為一個(gè)塊設(shè)備文件。8表示主設(shè)備號(hào)
3.掛在磁盤(pán)(因?yàn)槭莾?nèi)置硬盤(pán),使用永久掛載)
創(chuàng)建一個(gè)掛載目錄,即空文件夾,我這里使用/www目錄
使用永久掛載,就意味著它開(kāi)機(jī)會(huì)自動(dòng)掛載(編輯 /etc/fstab 文件)
命令:blkid:查看對(duì)應(yīng)分區(qū)的UUID(編號(hào))。UUID唯一標(biāo)識(shí)每一個(gè)分區(qū),防止錯(cuò)誤的掛載。除此之外,還會(huì)顯示分區(qū)的類型。(建議先復(fù)制一下sdb1的UUID,一會(huì)兒會(huì)用到)
使用vim編輯 /etc/fstab 在命令行直接輸入vim /etc/fstab 就可以編輯,實(shí)現(xiàn)開(kāi)機(jī)自動(dòng)掛載。
因?yàn)槭切孪到y(tǒng),沒(méi)有安裝vim就apt-get install vim -y還是不行無(wú)法安裝,更新一下apt-get update后,再次運(yùn)行apt-get install vim -y即可。
# UNCONFIGURED FSTAB FOR BASE SYSTEM
/dev/root / ext4 defaults,noatime,nodiratime,errors=remount-ro 0 1
UUID="3ad32c9e-60a7-4ab6-b54c-ed507cdeb546" /www ext4 defaults 0 0
重啟后lsblk檢查即可看到
root@imou-sn1:/www# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 74.5G 0 disk /www
mmcblk1 179:0 0 3.7G 0 disk
└─mmcblk1p1 179:1 0 3.7G 0 part /
mmcblk1boot0 179:32 0 2M 1 disk
mmcblk1boot1 179:64 0 2M 1 disk
當(dāng)你的目錄被掛載后,該目錄下會(huì)多出一個(gè)目錄lost+found。
lost+found:顧名思義,丟失然后找到。它是一個(gè)特殊的目錄,用來(lái)存放文件系統(tǒng)錯(cuò)誤導(dǎo)致文件丟失的目錄,因此我們的一些數(shù)據(jù)是可以通過(guò)它來(lái)找到的。這個(gè)目錄是在分區(qū)的根目錄上,就是我們掛載的分區(qū)。但這不是每個(gè)文件系統(tǒng)都有的目錄,ext2/3/4就有這個(gè)目錄,有些就沒(méi)有這個(gè)目錄。
安裝docker并修改docker文件路徑
# 官方腳本 使用阿里云源
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# 或國(guó)內(nèi)daocloud源
curl -sSL https://get.daocloud.io/docker | sh
安裝docker-compose
# 先安裝pip
apt install pip -y
# 使用 pip 安裝 docker-compose
sudo pip install docker-compose
# 測(cè)試是否安裝成功
docker-compose --version
修改docker路徑
# 查看docker 配置信息
docker info
# 修改docker配置文件路徑(沒(méi)有就新建)
vim /etc/docker/daemon.json
# 注入路徑地址代碼
{
"registry-mirrors": ["http://hub-mirror.c.163.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","https://9cpn8tt6.mirror.aliyuncs.com"],
"data-root": "/www/docker"
}
# 重啟再次查看是否生效
systemctl restart docker
docker info
配置nextcloud完整docker
配置教程
https://hexo.chensmallx.top/2021/04/08/nextcloud-on-docker/#%E4%BE%9D%E8%B5%96%E5%85%B3%E7%B3%BB
- fpm——fastCgi作為呈現(xiàn)層——版本的nextcloud
- nginx作為前置反向代理服務(wù)器提供https安全
- mysql/mariadb作為數(shù)據(jù)庫(kù),提高數(shù)據(jù)可靠性以及讀寫(xiě)性能
- redis作為熱點(diǎn)數(shù)據(jù)緩存服務(wù)器以及文件鎖管理器
依賴關(guān)系
- mariadb(目前mysql都過(guò)渡到mariadb了)
- redis
- nextcloud:fpm
- nginx
先安裝一個(gè)可視化管理面板
https://www.dockernb.com/
docker run --restart always --name fast -p 8081:8081 -d -v /var/run/docker.sock:/var/run/docker.sock wangbinxingkong/fast
但是面板依然不能拉取鏡像,不知道是什么問(wèn)題
用原作者一行代碼拉去也無(wú)效
一個(gè)一個(gè)拉取把!
docker pull mariadb
docker pull redis
docker pull nextcloud:fpm
docker pull nginx
其中需要明確一下每個(gè)容器在這一套系統(tǒng)中扮演的角色。
nextcloud作為此次的主角,也就是主體業(yè)務(wù)(app),它在存取數(shù)據(jù)的時(shí)候是會(huì)用到數(shù)據(jù)庫(kù)(db)和緩存(cache)系統(tǒng)的,那么可以得出nextcloud依賴于mysql和redis。
而mysql和redis之間各司其職,其中一個(gè)掛了不會(huì)影響到另一個(gè),所以優(yōu)先級(jí)相同,之間沒(méi)有依賴關(guān)系。
nginx作為代理業(yè)務(wù)和用戶之間溝通的主體,首先是需要業(yè)務(wù)(app)正常運(yùn)行才能夠正常提供它自己本身的服務(wù),所以nginx依賴于nextcloud。
# 依賴關(guān)系如下
/-> mysql
nginx -> nextcloud -|
\-> redis
# 啟動(dòng)順序則需要反過(guò)來(lái)
redix&mysql -> nextcloud -> nginx
docker-compose配置文件
docker-compose是一個(gè)代理用戶去管理docker的一個(gè)工具,使用docker-compose.yml配置文件就可以系統(tǒng)、方便地部署多容器項(xiàng)目,因?yàn)槲覀冞@次搭建的nextcloud也是基于多容器的,所以使用docker-compose進(jìn)行部署和調(diào)試以及重建最為方便。
完整的docker-compose配置參數(shù)文檔可以參考下面的這個(gè)文檔,講的還是比較細(xì)致,推薦給要深入docker-compose的同學(xué)學(xué)習(xí)。
以下就是本文輸出的docker-compose配置文件。
注:參數(shù)的解釋會(huì)通過(guò)備注的形式寫(xiě)在配置中
yml
version: '3.4'
services:
db: # 這里只是給每個(gè)容器單獨(dú)配置一個(gè)名稱
image: mariadb # 具體的鏡像名稱,可以使用“:”指定鏡像的版本
restart: unless-stopped # 重啟的選項(xiàng),分為no、on-failure、on-failure:x、always、unless-stopped,具體可以自行搜索查看區(qū)別
expose:
# expose僅將指定的端口暴露給links的容器,而不對(duì)宿主機(jī)開(kāi)放。
# 和ports的區(qū)別在于,ports可以映射宿主機(jī)別的端口到容器中。
- "3306"
volumes:
# volumes指的是將宿主機(jī)的路徑映射到容器中的指定位置
- ./db:/var/lib/mysql
environment:
# environment可以對(duì)容器創(chuàng)建指定多個(gè)環(huán)境變量
- MYSQL_ROOT_PASSWORD=root_password # 這里配置root密碼
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=user_name # 這里配置一個(gè)非root賬戶給nextcloud使用
- MYSQL_PASSWORD=user_password # 這里配置上面那個(gè)賬號(hào)的密碼
cache:
image: redis
restart: unless-stopped
expose:
- "6379"
volumes:
- ./cache:/data
command: redis-server --requirepass 'redis_password' # 這里的redis_password換成你要配置的redis密碼
# command指的是啟動(dòng)容器后代替默認(rèn)啟動(dòng)指令來(lái)啟動(dòng)服務(wù)的指令
app:
image: nextcloud:fpm
restart: unless-stopped
expose:
- "9000"
volumes:
- ./app/html:/var/www/html
- ./app/data:/var/www/html/data
- ./app/config:/var/www/html/config
- ./app/custom_apps:/var/www/html/custom_apps
links:
# links將容器與當(dāng)前容器鏈接起來(lái),以使得當(dāng)前容器可以訪問(wèn)目標(biāo)容器expose的端口
# 格式為 容器的原名:映射到當(dāng)前容器中的名稱
- db:db
- cache:cache
depends_on:
# 依賴的容器列表,只有這些容器都成功啟動(dòng)了,才會(huì)啟動(dòng)當(dāng)前容器
- db
- cache
proxy: # 叫做proxy是因?yàn)槭亲鳛榇韥?lái)提供服務(wù)
image: nginx
restart: unless-stopped
expose:
- "80"
ports:
# ports可將容器內(nèi)的端口映射到宿主機(jī)上
# 這里是將容器的443端口映射到宿主機(jī)的7788端口
- 7788:443
volumes:
- ./app/html:/var/www/html
- ./proxy/conf.d:/etc/nginx/conf.d:ro
- ./proxy/ssl_certs:/etc/nginx/ssl_certs:ro
links:
- app:app
depends_on:
- app
把這些內(nèi)容保存到docker-compose.yml文件中,然后將其放置在某個(gè)文件夾中,例如~/super_nextcloud/,我們之后就在這個(gè)路徑下做后續(xù)的操作。
Nginx配置文件
接著我們要準(zhǔn)備一下nginx的配置。需要?jiǎng)?chuàng)建兩個(gè)文件夾,一個(gè)是./proxy/conf.d,一個(gè)是./proxy/ssl_certs。
其中conf.d放置nginx的配置文件,可以起名叫做nextcloud.conf,ssl_certs放置域名對(duì)應(yīng)的SSL證書(shū)的pem和key文件。
mkdir -p ./proxy/conf.d ./proxy/ssl_certs
具體可以參考以下的配置來(lái)寫(xiě)nextcloud.conf,其中域名和SSL證書(shū)文件的名字需要替換成你自己的。
nginx
upstream php-handler {
server app:9000;
}
server {
listen 80;
listen [::]:80;
server_name 這里填寫(xiě)自己的域名;
# enforce https
return 301 https://$server_name:443$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name 這里填寫(xiě)自己的域名;
# Use Mozilla's guidelines for SSL/TLS settings
# https://mozilla.github.io/server-side-tls/ssl-config-generator/
# NOTE: some settings below might be redundant
ssl_certificate /etc/nginx/ssl_certs/這里填寫(xiě)SSL證書(shū)的名字.pem;
ssl_certificate_key /etc/nginx/ssl_certs/這里填寫(xiě)SSL證書(shū)的名字.key;
# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this
# topic first.
#add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
add_header Strict-Transport-Security 15552000;
#add_header X-Frame-Options SAMEORIGIN;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;
# Path to the root of your installation
root /var/www/html;
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
# The following rule is only needed for the Social app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/webfinger /public.php?service=webfinger last;
location = /.well-known/carddav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
location / {
rewrite ^ /index.php$request_uri;
}
location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
deny all;
}
location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
# Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
# Enable pretty urls
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
try_files $uri/ =404;
index index.php;
}
# Adding the cache control header for js, css and map files
# Make sure it is BELOW the PHP block
location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into
# this topic first.
#add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
# Optional: Don't log access to assets
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to other assets
access_log off;
}
}
準(zhǔn)備文件中需要證書(shū)文件,證書(shū)我是freessl申請(qǐng)的,因此需要轉(zhuǎn)換為pem+key,上傳到對(duì)應(yīng)位置。
文件都準(zhǔn)備好之后,文件結(jié)構(gòu)如下:
super_nextcloud
├── docker-compose.yml
└── proxy
├── conf.d
│ └── nextcloud.conf
└── ssl_certs
├── SSL證書(shū).key
└── SSL證書(shū).pem
創(chuàng)建&啟動(dòng)容器
此時(shí)準(zhǔn)備工作已經(jīng)完成。使用docker-compose代理對(duì)docker的容器進(jìn)行操作可以使用下面的命令:
docker-compose up -d # 創(chuàng)建所有容器并按順序啟動(dòng)
docker-compose down # 停止所有容器并刪除
docker-compose stop # 停止所有容器
docker-compose start # 按順序啟動(dòng)所有容器
docker-compose restart # 停止所有容器并按順序啟動(dòng)所有容器
所以這里我們使用docker-compose up -d啟動(dòng)我們的服務(wù)。在docker-compose輸出的提示中,所有目標(biāo)都顯示為done后,我們可以使用netstat查看nginx容器是否在監(jiān)聽(tīng)7788端口:
? netstat -tnlp | grep 7788
tcp6 0 0 :::7788 :::* LISTEN 5155/docker-proxy
如果沒(méi)有輸出,那就是創(chuàng)建容器有問(wèn)題。可以通過(guò)docker ps -a查看哪些容器在瘋狂重啟,然后通過(guò)docker logs [容器名or容器ID]進(jìn)到這個(gè)容器中查看容器服務(wù)日志,自行排障。
如果有輸出,并且和上面的內(nèi)容大致相同,那么恭喜你,構(gòu)建已經(jīng)成功大半了。
所有服務(wù)都啟動(dòng)起來(lái)開(kāi)始嘗試連接nextcloud時(shí)發(fā)現(xiàn)錯(cuò)誤。數(shù)據(jù)庫(kù)問(wèn)題
注冊(cè)錯(cuò)誤提示:nextcloud install Error while trying to initialise the database: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 4047 InnoDB refuses to write tables with ROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE.
解決方法:
這個(gè)解決辦法有個(gè)巨坑,每次重啟后都要重新執(zhí)行一個(gè)這個(gè)命令。
不然nextcloud就會(huì)出現(xiàn)內(nèi)部錯(cuò)誤,技術(shù)細(xì)節(jié)提示。真的很惡心!
但是我也不知道怎么把這個(gè)命令寫(xiě)入docker mariadb中。。。。
1.進(jìn)入mariadb控制臺(tái),鍵入以下命令并回車;
mysql -u root -p
2.輸入mariadb的root密碼,回車登錄;
3.輸入以下命令并回車;
SET GLOBAL innodb_read_only_compressed=OFF;
4.這時(shí)候再次注冊(cè)nextcloud,發(fā)現(xiàn)成功解決。
配置項(xiàng)目
配置站點(diǎn)
從地址和端口進(jìn)入站點(diǎn),通常是https+域名+端口,如果是內(nèi)網(wǎng)搭建并且不在意域名以及https的小鎖頭的話,則可以直接通過(guò)ip來(lái)訪問(wèn),但是需要注意的是,在nginx中配置了特定域名后,它會(huì)檢查訪問(wèn)時(shí)是否是正確的域名,如果不是正確的域名,那么就會(huì)拒絕訪問(wèn)網(wǎng)盤(pán)資源。
進(jìn)入后,我們就需要進(jìn)行網(wǎng)盤(pán)首次配置的一些操作,包括管理員的配置、數(shù)據(jù)庫(kù)的配置、應(yīng)用程序的配置等等。
其中需要注意的是,在數(shù)據(jù)庫(kù)配置部分,數(shù)據(jù)庫(kù)的地址需要填寫(xiě)我們?cè)赿ocker的links中映射marindb的主機(jī)名稱,即db;而賬號(hào)密碼則是在配置數(shù)據(jù)庫(kù)時(shí)制定的數(shù)據(jù)庫(kù)用戶密碼以及數(shù)據(jù)庫(kù)名稱。
使用上一步配置好的管理員賬號(hào)和密碼登錄網(wǎng)盤(pán),點(diǎn)擊頭像進(jìn)入設(shè)置,現(xiàn)將站點(diǎn)的參數(shù)配置好后再配置本賬號(hào)的參數(shù)。
修改Nginx配置
由于在網(wǎng)站上線后,需要配置一系列安全參數(shù),所以需要我們?cè)俅稳バ薷囊幌翹ginx的配置文件。
在proxy/conf.d/nextcloud.conf中找到這行(也就是上面那個(gè)nginx配置的41行),將前面的注釋解開(kāi),然后重啟nginx容器即可(也可以直接使用docker-compose restart重啟整個(gè)項(xiàng)目)。
nginx
# 如果需要使用手機(jī)APP來(lái)訪問(wèn)的話,還需要將54 54 59行解開(kāi)注釋
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
#rewrite ^/.well-known/webfinger /public.php?service=webfinger last;
配置緩存
由于nextcloud默認(rèn)使用的緩存機(jī)制是APCu,我們需要到配置中修改其使用Redis作為緩存。
將app/config/config.php中的內(nèi)容按照如下方法改動(dòng):
php
//'memcache.local' => '\\OC\\Memcache\\APCu' // 用本地式緩存使用APCu // 注釋這行
'memcache.local' => '\\OC\\Memcache\\Redis',
'memcache.distributed' => '\\OC\\Memcache\\Redis', // 分布式緩存使用Redis
'memcache.locking' => '\\OC\\Memcache\\Redis', // 啟用Redis緩存的文件鎖
'redis' => array(
'host' => 'cache', // 這里和mariadb的邏輯相同,填寫(xiě)容器links時(shí)映射的主機(jī)名
'port' => 6379,
'password' => 'redis_password' // 這是之前在配置docker-compose時(shí)配置的redis密碼
),
'filelocking.enabled' => 'true',
使用以下命令進(jìn)入nextcloud的docker容器,并將文件歸屬確認(rèn)改為www-data:
bash
docker exec -it [nextcloud容器的容器ID] /bin/bash
# 進(jìn)入docker容器之后
ls -l /var/www/html/config/config.php
-rw-r----- 1 www-data www-data 1646 Mar 30 07:27 /var/www/html/config/config.php
# 如果提示所有權(quán)不是www-data,那么就要改回www-data
chown www-data:www-data /var/www/html/config/config.php
這時(shí)候再去訪問(wèn)nextcloud的頁(yè)面,就是在使用redis做緩存了。
配置cron定時(shí)任務(wù)
由于nextcloud內(nèi)部的文件和配置會(huì)在用戶操作過(guò)程中產(chǎn)生變化,所以需要啟用一個(gè)定時(shí)任務(wù)去定期整理和歸檔這些數(shù)據(jù)到數(shù)據(jù)庫(kù)或者應(yīng)用到配置中。
先確定自己的nextcloud容器的容器ID或者容器名字,可以使用docker ps -a查看。
然后使用crontab -e或vim /etc/crontab打開(kāi)crontab的配置進(jìn)行編輯,加入如下內(nèi)容:
plain
# run nextcloud cron task every 5 min
*/5 * * * * docker exec -u 33 [容器ID或容器名] php -f /var/www/html/cron.php 2>&1 /dev/null
建議兩個(gè)地方都加一次,避免配置不生效。
至此,站點(diǎn)的基本內(nèi)容已經(jīng)配置完畢,可以滿足個(gè)人用于網(wǎng)盤(pán)、webdav等使用場(chǎng)景了。
手動(dòng)安裝拓展
nextcloud另一個(gè)吸引人的地方就是可以安裝很多拓展,但是由于nextcloud是從github上安裝拓展,國(guó)內(nèi)的網(wǎng)絡(luò)連接github又有許許多多的困難,所以直接在頁(yè)面上點(diǎn)擊安裝按鈕是絕對(duì)會(huì)報(bào)cURL的錯(cuò)的。
所以我想出了一個(gè)曲線救國(guó)的方法,雖然比直接點(diǎn)擊安裝要多了幾步,但著實(shí)可行,實(shí)施起來(lái)也沒(méi)有什么阻礙。(反倒是之前為了實(shí)現(xiàn)直接點(diǎn)頁(yè)面安裝而各種配置代理浪費(fèi)了不少時(shí)間,而且還有搞不出來(lái)…)
手動(dòng)安裝拓展程序的步驟大致可以分為下面幾個(gè)步驟:
- 確保當(dāng)前客戶機(jī)環(huán)境可通過(guò)代理訪問(wèn)github;
- 進(jìn)入nextcloud的應(yīng)用頁(yè)面,找到自己想裝的拓展應(yīng)用;
- 點(diǎn)擊想要安裝的應(yīng)用展開(kāi)詳情,進(jìn)入“訪問(wèn)網(wǎng)站”鏈接,此時(shí)一般會(huì)去到插件的github頁(yè)面或者nextcloud官方發(fā)布插件頁(yè)面;
- 進(jìn)入github項(xiàng)目的release頁(yè)面,下載最新的插件更新版本到當(dāng)前本機(jī)。按照nextcloud的插件發(fā)布標(biāo)準(zhǔn)應(yīng)該是一個(gè)
tar.gz文件; - 將下載下來(lái)的文件從nextcloud個(gè)人文件頁(yè)面上傳到網(wǎng)盤(pán)中;
- 進(jìn)入nextcloud容器。
docker exec -u 33 -it [container ID or container name] /bin/bash,其中[container ID or container name]要換成真實(shí)容器的ID或名字; - 到路徑下找到自己上傳的拓展插件。例如
/var/www/html/data/[username]/files/nextcloud_extension/metadata.tar.gz,其中[username]要換成用戶的名字。這里裝的是matadata插件,用于查看圖片各種元數(shù)據(jù)的; - 將其復(fù)制到
/var/www/html/apps。cp /var/www/html/data/[username]/files/nextcloud_extension/metadata.tar.gz /var/www/html/apps; - 解壓后刪除源壓縮文件
cd /var/www/html/apps && tar -xzf metadata.tar.gz && rm metadata.tar.gz; - 進(jìn)入nextcloud頁(yè)面的【應(yīng)用】-【已禁用的應(yīng)用】頁(yè)面,將其啟用。
按照以上步驟來(lái)操作就可以做到實(shí)現(xiàn)手動(dòng)安裝插件的目的了。
安裝jellyfin(主要應(yīng)用nextcloud的自動(dòng)同步功能將自動(dòng)下載的文件同步到服務(wù)器,然后服務(wù)器中的jellyfin調(diào)用)
運(yùn)行 jellyfin container
這里使用yml文件配置來(lái)實(shí)現(xiàn)jellyfin的docker,我的機(jī)器是arm所以拉取LinuxServer.io提供的鏡像,據(jù)說(shuō)不僅小巧而且沒(méi)有那么多漏洞,和權(quán)限。hwa等問(wèn)題。
建立工作目錄:
$ sudo mkdir -p /www/jellyfin/data/metadate #這里主要是為了方便管理,所有關(guān)于jellyfin的文件都會(huì)存放在jellyfin文件夾下
$ sudo chown -R 1000:1000 /www/jellyfin #修改權(quán)限,查了一下,這塊主要是docker的系統(tǒng)機(jī)制,他并不是虛擬機(jī),如果采用root權(quán)限,即不設(shè)置權(quán)限的話,存在一下安全問(wèn)題,就是docker容器的權(quán)限會(huì)提升到root權(quán)限有些風(fēng)險(xiǎn),所以按照這個(gè)權(quán)限配置uid為1000的用戶組和用戶。
定義container:
在jellyfin文件夾下創(chuàng)建一個(gè)yml文件:dc-jellyfin.yml
version: "3"
services:
jellyfin:
container_name: jellyfin
image: linuxserver/jellyfin:latest
# devices:
# - /dev/vc-mem:/dev/vc-mem
# - /dev/vchiq:/dev/vchiq
# networks:
# default:
# ipv4_address: 192.168.0.201
network_mode: "host" #使用host方式,放棄vlan
environment:
PUID: 1000
PGID: 1000
TZ: Asia/Shanghai
# HTTP_PROXY: "http://192.168.0.3:1081"
# HTTPS_PROXY: "http://192.168.0.3:1081"
# NO_PROXY: "127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12,139.198.0.0/16,localhost"
volumes:
- /srv/jellyfin:/config
- /media:/media
- /opt/vc/lib:/opt/vc/lib
restart: unless-stopped
#networks:
# default:
# external:
# name: ipvlan
因?yàn)槲业臋C(jī)器gpu沒(méi)有驅(qū)動(dòng),所以也就不想硬解了,其次代理問(wèn)題也不用考慮,有路由跳墻,至于網(wǎng)絡(luò)這塊,實(shí)在弄不懂怎么劃分vlan設(shè)置,就也拋棄。直接使用host。但是據(jù)說(shuō)docker的bridge網(wǎng)絡(luò)nat性能很差,所以等以后研究研究可以嘗試配置一下。
啟動(dòng)container:
$ docker-compose -f dc-jellyfin.yml up --no-start
$ docker container start jellyfin
總結(jié)
經(jīng)歷了這次搭建網(wǎng)盤(pán),算是初級(jí)入門(mén)了docker容器的部署,以及docker-compose的配置入門(mén)。
只能說(shuō),在開(kāi)始一個(gè)項(xiàng)目之前,還有許多東西需要實(shí)現(xiàn)考慮和準(zhǔn)備好,做好缺陷預(yù)防。這樣在真正上手做的時(shí)候,才會(huì)盡可能的少出差錯(cuò),以及處變不驚。
后記:
在我配置的時(shí)候因?yàn)樾薷膎extcloud的config.php文件可能出現(xiàn)了操作失誤,導(dǎo)致nextcloud出現(xiàn)內(nèi)部錯(cuò)誤,本來(lái)想全部重新來(lái)一遍的,想了想,既然只是nextcloud出了問(wèn)題,直接刪除nextcloud容器,重新建立一個(gè),因?yàn)榛旧吓渲梦募荚谕獠?,基本不影響,只需要重新設(shè)置一下賬號(hào)密碼以及數(shù)據(jù)庫(kù)連接,(此處由于數(shù)據(jù)庫(kù)也有nextcloud的問(wèn)題,數(shù)據(jù)庫(kù)也重建過(guò)一次,當(dāng)然我們?cè)趧h除容器之后也要把對(duì)應(yīng)的數(shù)據(jù)文件夾,比如nextcloud對(duì)應(yīng)的數(shù)據(jù)文件夾為app,app文件夾也要做整體刪除才行。)