nextcloud私有云盘的部署
nextcloud在centos系统下搭建⾃⼰的私有云盘
搭建⼀套⾃⼰的私有云盘,让数据存储更加⽅便、可靠。⾃⼰搭建的云存储,⾸先没有什么容量、下载速度的限制,⽽且本地访问速度很快。⼀开始以为Nextcloud只是⼀个⽹盘云存储,后来看到Nextcloud内置了Office⽂档、图⽚相册、⽇历联系⼈、两步验证、⽂件管理、RSS阅读等丰富的应⽤,我发现Nextcloud已经仅仅可以⽤作个⼈或者团队存储与共享,还可以打造成为⼀个个⼈办公平台,⼏乎相当于⼀个个⼈的Dropbox了。
⾃⼰搭建私有云其实很简单,⾸先需要⼀台主机,然后需要选择⼀个私有云软件(⽐如ownCloud、nextCloud、seafile)。以下内容将介绍如何在 CentOS 7 服务器中安装和配置Nextcloud,并且会通过 Nginx 和 PHP7-FPM 来运⾏ Nextcloud,同时使⽤ MariaDB 数据库系统。具体部署⽅法如下:
⼀ . 部署环境的系统是Centos7版本
[root@nextcloud ~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
⼆. 安装并配置Nginx和php-fpm
[root@nextcloud ~]# yum -y install epel-release
[root@nextcloud ~]# yum -y install nginx
添加⼀个yum源来安装php-fpm
rpm -Uvh mirror.webtatic/yum/el7/webtatic-release.rpm
安装相关组件
yum -y install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear php70w-xml php70w-mbstring php70w-pdo php70w-json php70w-pecl-apcu php70w-pecl-apcu-devel
完成后,检查⼀下php-fpm是否已正常安装
[root@nextcloud ~]# php -v
PHP 7.0.27 (cli) (built: Jan 14 2018 09:00:22) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
配置php-fpm
vim /etc/php-fpm.f
.....
user = nginx //将⽤户和组都改为nginx
group = nginx
.....
listen = 127.0.0.1:9000 //php-fpm所监听的端⼝为9000
......
env[HOSTNAME] = $HOSTNAME //去掉下⾯⼏⾏注释
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
在/var/lib⽬录下为session路径创建⼀个新的⽂件夹,并将⽤户名和组设为nginx
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
启动Nginx和php-fpm服务,并添加开机启动
systemctl start php-fpm
systemctl start nginx
systemctl enable php-fpm
systemctl enable nginx
三. 安装并配置MariaDB 或 mysql
使⽤MaraiDB作为Nextcloud数据库。yum安装MaraiDB服务
yum -y install mariadb mariadb-server
启动MariaDB服务并添加开机启动
systemctl start mariadb
systemctl enable mariadb
注意:确保本地登陆数据库的相关帐号及权限都OK。
Mysql需要设置为mixed模式:
set global binlog_format=mixed;
下⾯创建数据库:
MariaDB [(none)]> create database nextcloud;
MariaDB [(none)]> create user nextcloud@localhost identified by '123456';
MariaDB [(none)]> grant all privileges on nextcloud.* to nextcloud@localhost identified by '123456';
MariaDB [(none)]> flush privileges;
四. 配置Nextcloud⽣成⾃签名SSL证书
先为SSL证书创建⼀个新的⽂件夹:
cd /etc/nginx/cert/
penssl req -new -x509 -days 365 -nodes -out /etc/nginx/ -keyout /etc/nginx/cert/nextcloud.key .....
Country Name (2 letter code) [XX]:cn //国家
State or Province Name (full name) []:beijing //省份
Locality Name (eg, city) [Default City]:beijing //地区名字
Organization Name (eg, company) [Default Company Ltd]:lxplwh //公司名
Organizational Unit Name (eg, section) []:Technology //部门
Common Name (eg, your name or your server's hostname) []:lxplwh //CA主机名
Email Address []:lxplwh@126
然后将证书⽂件的权限设置为660
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*
五. 下载并安装Nextcloud
wget loud/server/releases/nextcloud-12.0.4.zip
unzip nextcloud-12.0.4.zip
mv nextcloud /usr/share/nginx/html/
并为Nextcloud创建data⽬录,将Nextcloud的⽤户和组修改为nginx
mkdir -p nextcloud/data/
chown nginx:nginx -R nextcloud/
六. 配置Nginx虚拟主机
[root@nextcloud ~]# vim /etc/f
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
pes;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream php-handler {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name nextcloud.lxplwh;
return 301 $server_name$request_uri;
}
server {
listen 443 ssl;
server_name nextcloud.lxplwh;
ssl_certificate /etc/nginx/;
ssl_certificate_key /etc/nginx/cert/nextcloud.key;
add_header Strict-Transport-Security "max-age=15768000;
includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
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;
root /usr/share/nginx/html/nextcloud/;
location = / {
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 512M;
fastcgi_buffers 64 4K;
gzip off;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location / {
rewrite ^ /index.php$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/.+|core/templates/40[34])\.php(?:$|/) {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
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_intercept_errors on;
nginx ssl证书配置 fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
add_header Strict-Transport-Security "max-age=15768000;includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
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;
access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
access_log off;
}
}
确保没有问题后重启Nginx服务
[root@nextcloud ~]# nginx -t
nginx: the configuration file /etc/f syntax is ok
nginx: configuration file /etc/f test is successful
[root@nextcloud ~]# systemctl restart nginx
七. 安装Nextcloud
解析上⾯nginx中配置的域名nextcloud.lxplwh,邦定hosts. 访问nextcloud.lxplwh进⾏Nextcloud界⾯安装.
设置帐号密码,以及数据库的连接信息。如果不报错,即可安装完成,进⼊。
到此安装完成。
下⾯进⾏⼀些安全与性能优化
为了您服务的安全和性能, 请将所有设置配置正确. 我们将会进⾏⼀些⾃动化检查以帮助您完成这项⼯作. 详情请查看 "⼩提⽰" 部分及相关⽂档.
HTTP 请求头 "X-Frame-Options" 没有配置为 "SAMEORIGIN". 这是⼀个潜在的安全或隐私风险, 我们
建议您调整这项设置.
内存缓存未配置. 如果可⽤, 请配置 memcache 以增强性能. 更多信息请查看我们的.
PHP 的组件 OPcache 没有正确配置. , 我们建议在php.ini⽂件中使⽤下列设置:
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
<_consumption=128
opcache.save_comments=1
修改程序⽬录下的config⽬录中的config.php⽂件,在配置⽂件中添加多个Memcached实例,也可以添加⼀个:
'memcache.local'=> '\OC\Memcache\APCu',
'memcache.distributed'=> '\OC\Memcache\Memcached',
'memcached_servers'=> array(
array('localhost', 11211),
array('ample', 11211),
array('ample', 11211),
),
添加redis缓存:
在配置⽂件中添加如下,这个是通过TCP连接的:
'memcache.local'=> '\OC\Memcache\Redis',
'redis'=> array(
'host'=> 'localhost',
'port'=> 6379,
),
还有性能更好的UNIX连接:
'memcache.local'=> '\OC\Memcache\Redis',
'redis'=> array(
'host'=> '/var/run/redis/redis.sock',
'port'=> 0,
'dbindex'=> 0,
'password'=> 'secret',
'timeout'=> 1.5,
)
,
同时,官⽅还推荐加⼊如下,来⽤于存储⽂件锁:
'memcache.locking'=> '\OC\Memcache\Redis',
Nextcloud的邮件发信设置
使⽤管理员账号登陆Nextcloud。点击右上⾓的设置图标⾥的"管理"-"其他设置"
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论