利用树莓派及开源项目nextcloud,搭建自己私人的数据云存储,自己的资料还是保存在自己的手里最安全。
一、可以更换国内软件源速度会快一些,或者直接使用系统的软件源
#编辑sudo vim /etc/apt/sources.list,添加中国科学技术大学源
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb-src http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
sudo apt-get update
sudo apt-get -y upgrade
二、采用apt方式安装mysql分支MariaDB
sudo apt-get install mysql-server mysql-client
#设置mysql的root账户密码
sudo mysqladmin version #查看mysql相关版本信息,如果没有密码将能查看到结果
sudo mysqladmin password xxxxxx #设置密码
sudo mysql -uroot -p #登录mysql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '12345678' WITH GRANT OPTION; #给root增加远程访问权限
flush privileges; #刷新权限
#MariaDB默认配置文件
/etc/mysql/mariadb.conf.d目录下,50-server.cnf的bind-address=0.0.0.0
三、采用apt方式安装php7
apt-get install php7.0 php7.0-fpm php7.0-mysql php7.0-common
apt-get install php7.0-intl php7.0-mcrypt php-imagick php7.0-xml
apt-get install php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring php7.0-zip
#php配置文件位置
/etc/php/7.0/fpm/php.ini
#相关配置文件位置
/etc/php/7.0/fpm
四、采用apt方式安装nginx
sudo apt-get install nginx
#相关文件位置
nginx默认web站点目录 /var/www/html
nginx配置文件位置 /etc/nginx/nginx.conf
nginx可执行文件位置 /usr/sbin/nginx
nginx.conf文件内容
user www-data;
worker_processes 4;
worker_cpu_affinity 0001 0010 0011 0100;
pid /run/nginx.pid;
worker_rlimit_nofile 65535;
include /etc/nginx/modules-enabled/*.conf;
error_log /var/log/nginx/error.log;
events {
worker_connections 2048;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
gzip on;
gzip_disable "msie6";
server {
listen 80;
root /var/www/html;
access_log /var/log/nginx/nextcloud.log;
#index index.html index.htm index.nginx-debian.html;
#server_name XXXXXX;
location / {
index index.html index.htm index.php;
}
location ~\.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
}
五、添加软件使树莓派能写入ntfs分区信息
apt-get install ntfs-3g
六、挂载exFAT格式的硬盘
sudo apt-get install exfat-fuse
七、去掉树莓派图形界面的自动挂载移动硬盘
图形界面的文件管理器 -> 编辑 -> 偏好设置 -> 卷管理 -> 去掉 三个选择项的对勾
八、让树莓派系统开机自动挂载移动硬盘
fdisk -l #查看移动硬盘的id
#编辑挂载命令
echo '/dev/sda1 /data ext4 defaults 0 0' >> /etc/fstab #开机后移动硬盘/dev/sda1自动挂载在/data目录上
九、nextcloud的nginx配置
user www-data;
worker_processes 4;
worker_cpu_affinity 0001 0010 0011 0100;
pid /run/nginx.pid;
worker_rlimit_nofile 65535;
include /etc/nginx/modules-enabled/*.conf;
error_log /var/log/nginx/error.log;
events {
worker_connections 4096;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 600;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
root /var/www/nextcloud/;
server_name cloud.example.com;
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;
fastcgi_hide_header X-Powered-By;
fastcgi_hide_header X-Powered-By;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
client_max_body_size 8000M;
fastcgi_buffers 64 4K;
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;
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/.+|ocs-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;
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
#fastcgi_pass php-handler;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
location ~ \.(?:css|js|woff|svg|gif)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
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;
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$request_uri;
access_log off;
}
}
}