tips:以下所有安装都切换到root用户
所需设备
1树莓派一个
2笔记本电脑一个 远程连接服务器
3域名一个
4公网服务器一个(ecs)
apt-get install exfat-fuse
mkdir -p /media/www-data/
vi /etc/fstab
# /dev/sda1 根据自己实际的硬盘位置 sudo fdisk -l 查看 不能出错!!!
/dev/sda1 /media/www-data auto defaults,noatime,uid=33,gid=33,umask=7007 0 0
mkdir -p /data/nginx/
mkdir -p /data/nginx/conf.d/
mkdir -p /data/nginx/ssl/
vi /data/nginx/nginx.conf
添加以下内容
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
配置反向代理
vi /data/nginx/conf.d/default.conf
添加
upstream nextcloud{
server 192.168.0.104:8888; #此处填写nextcloud云盘的 ip:port 如果是本机填写 localhost
}
server {
listen 443 ssl http2; #nginx监听443端口
#listen [::]:443 ssl http2;
server_name 192.168.0.104; #此处填写nextcloud云盘的ip 如果是本机填写 localhost
#ssl on;
#listen 443 ssl;
ssl_certificate /etc/nginx/ssl/nginx.crt;#填下面生成的证书路径
ssl_certificate_key /etc/nginx/ssl/nginx.key;#填下面生成的证书路径
client_max_body_size 100G;
proxy_buffer_size 2m;
proxy_buffers 8 1m;
proxy_busy_buffers_size 2m;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
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;
}
location / {
proxy_redirect off;
proxy_pass http://nextcloud;
proxy_set_header Host $http_host;
}
location = /.htaccess {
return 404;
}
}
生成ssl证书
openssl genrsa -out /data/nginx/ssl/nginx.key 2048
openssl req -new -key /data/nginx/ssl/nginx.key -out /data/nginx/ssl/nginx.csr
openssl x509 -req -days 36500 -in /data/nginx/ssl/nginx.csr -signkey /data/nginx/ssl/nginx.key -out /data/nginx/ssl/nginx.crt
vi Dockerfile
添加以下内容
FROM nextcloud:latest
LABEL maintainer="engr-z"
RUN apt update && apt upgrade -y
RUN apt install ffmpeg smbclient libsmbclient-dev -y
RUN pecl install smbclient
RUN docker-php-ext-enable smbclient
vi docker-compose.yml
version: "3.5"
services:
nginx:
container_name: nginx
hostname: nginx
image: nginx
ports:
- 8081:8081
- 443:443
restart: always
volumes:
- /data/nextcloud:/usr/share/nginx/html
- /data/nginx/nginx.conf:/etc/nginx/nginx.conf
- /data/nginx/conf.d/:/etc/nginx/conf.d
- /data/nginx/ssl:/etc/nginx/ssl
- /data/nginx/log:/var/log/nginx
nextcloud:
build:
context: .
dockerfile: ./Dockerfile
ports:
- "8888:80"
restart: always
volumes:
- /data/nextcloud/themes:/var/www/html/themes/
- /data/nextcloud/apps:/var/www/html/custom_apps
- /data/nextcloud/config:/var/www/html/config
- /data/nextcloud/data:/var/www/html/data
environment:
- POSTGRES_HOST=nc-postgres # HERE
- POSTGRES_DB=nextcloud_db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=Pg123
depends_on:
- db
redis:
image: redis
container_name: nextcloud_redis
hostname: redis
restart: always
ports:
- "6379:6379"
aria2:
image: wahyd4/aria2-ui:nextcloud
container_name: nextcloud_aria2
hostname: aria2
ports:
- "8000:80"
- "6800:6800"
volumes:
- /data/aria2/app/conf:/root/conf
- /data/aria2/data:/data
environment:
- DOMAIN=:80
# - SSL=true
# - RPC_SECRET=Hello
# - ARIA2_USER=111111
# - ARIA2_PWD=111111
# - ENABLE_AUTH=true
restart: always
db:
image: postgres
restart: always
container_name: nextcloud_postgres
hostname: 'nc-postgres' # AND HERE
volumes:
- /data/postgresql:/var/lib/postgresql/data
environment:
- POSTGRES_DB=nextcloud_db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=Pg123
docker-compose build
docker-compose up -d
查看进程
docker ps
http://ip:8888 ip换成树莓派的ip
初始化完成后,如果点击登陆还是跳转到登陆页面,那么可以尝试清空浏览器缓存
docker exec -it nextcloud bash
apt update
apt install ffmpeg
apt install smbclient libsmbclient-dev
pecl install smbclient
docker-php-ext-enable smbclient
vi /etc/data/nextcloud/data/config.php
添加配置
'overwriteprotocol' => 'https', #只能使用https访问
'memcache.local' => '\OC\Memcache\Redis',
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => array(
'host' => 'redis', #如果是在本机就是localhost,如果是docker,要和Redis的名一致
'port' => 6379,
),
'allow_local_remot_servers' => true,
'enable_previews' => true,
'enabledPreviewProviders' =>
array (
0 => 'OC\\Preview\\Image',
1 => 'OC\\Preview\\Movie',
2 => 'OC\\Preview\\TXT',
),
frpc.ini参考
[common]
server_addr = #填写frps服务器的域名或者公网ip
server_port = 7000 #填写frps服务端口
log_file = ./frpc.log
log_level = trace
log_max_days = 3
token = #填写frps服务密码
[ssh_mypi] #可以不配置
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 5922
[pi_nextcloud] #这里只配置了http转发
type = http
local_port = 8888 #netxcloud本地端口
custom_domains = #填写frps服务器的域名
https的转发自行百度
配置frpc自启动
vi /etc/systemd/system/frpc.service
添加如下配置
[Unit]
Description=Frp Client Service
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=5s
ExecStart=/usr/local/frp_0.27.0_linux_arm/frpc -c /usr/local/frp_0.27.0_linux_arm/frpc.ini #frpc的路径自行修改
ExecReload=/usr/local/frp_0.27.0_linux_arm/frpc reload -c /usr/local/frp_0.27.0_linux_arm/frpc.ini #frpc的路径自行修改
[Install]
WantedBy=multi-user.target
启动
systemctl enable /etc/systemd/system/frpc.service
systemctl start frpc.service
‘onlyoffice’ =>
array (
‘verify_peer_off’ => TRUE,
),
cat /proc/cpuinfo| grep Hardware
根据型号安装
BCM2708 https://imiku.me/2017/01/19/47.html
BCM2835 https://blog.csdn.net/m0_37509650/article/details/8797835
这里讲下安装BCM2835
vi /etc/modules
添加
bcm2835_wdt
sudo apt-get install watchdog
vi /etc/watchdog.conf
添加或者修改
max-load-1 = 24
watchdog-device = /dev/watchdog
temperature-device = /sys/class/thermal/thermal_zone0/temp #这里的temperature-device 新版已经改成temperature-sensor
max-temperature = 75000
watchdog-timeout = 15
realtime = yes
priority = 1
sudo systemctl enable watchdog.service
验证
sudo dmesg -c | grep watchdog
死机代码
:(){ :|:& };:
问题
1、笔记本出门只能通过公网ip访问
2、在家通通过局域网访问更快,并且可以防止浪费frps服务器的流量
3、回到家里后需要手动切换笔记本上的nextcloud客户端的连接地址,而且nextcloud客户端会提示之前的同步目录已经被使用
那怎么通过一个域名,在外的时候走的是公网ip,在家的时候走的是局域网呢?
1、安装dnsmasq
2、配置笔记本连接的家中的wifi的dns,指向dnsmasq服务,dnsmasq服务会将笔记本访问的域名解析成指定的ip
apt-get install dnsmasq
vi /etc/dnsmasq.conf
添加
cache-size=10240
vi /etc/hosts
添加
192.168.0.104 test.com #test.com 填自己的域名 192.168.0.104 nextcloud(树莓派)在局域网的ip
启动
systemctl enable dnsmasq
systemctl start dnsmasq
自行百度,其实就是dns添加一个ip地址,192.168.0.104 (树莓派/dnsmasq 的ip地址)
笔记本验证 自行百度
其他树莓派配置dns,验证 可以实现有问题
vi /etc/dhcpcd.conf
iface wlan0 inet static
static ip_address=192.168.0.103/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.104 192.168.1.1 #首选dns(dnsmasq) 和备选dns(无线路由器)
service dhcpcd restart
验证
apt-get install dnsutils
dig www.baidu.com
出现如下代表正确
;; Query time: 9 msec
;; SERVER: 192.168.0.104#53(192.168.0.104)
;; WHEN: Wed Nov 03 17:23:25 CST 2021
;; MSG SIZE rcvd: 104
NextCloud 自带的数据目录在列目录时都是通过数据库查询,如果需要手动在磁盘目录上添加文件并使用nextcloud列出就需要手动扫描。
在nextcloud安装目录下使用如下命令扫描,就可以看到新添加的文件
#cp /usr/local/etc/php/php.ini-development /usr/local/lib/php/php.ini
docker exec nextcloud su - www-data -s /bin/bash -c 'php -d memory_limit=-1 -f /var/www/html/occ files:scan --all'
docker exec -u 33 apache_app_1 /bin/bash -c 'php occ config:app:set files max_chunk_size --value 0'
sudo -u www-data php occ files:scan --all