部署Nextcloud私有云

以CentOS 7、MariaDB、PHP 7、Nginx为环境部署Nextcloud。

一、安装操作系统

首先安装操作系统,Nextcloud只支持Linux,由于个人习惯的原因,选择了CentOS 7,使用最小化安装(为了保证之后的步骤能在只有最小化安装的VPS上重现,也为了节约硬件资源)。

最小化的CentOS 7安装完毕后,默认是没有启用网卡的,在本地登录系统后,首先进入网络配置目录,列出目录中的网卡配置文件

cd  /etc/sysconfig/network-scripts/
ll | grep ifcfg-

运行结果

[root@localhost network-scripts]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ll | grep ifcfg
-rw-r--r--. 1 root root   312 Aug 30 10:01 ifcfg-enp0s3
-rw-r--r--. 1 root root   254 Sep 12  2016 ifcfg-lo

除了ifcfg-lo以外的那个文件就是网卡配置文件,具体名称可能会有所不同。

然后使用vi编辑该文件,将最后一行“ONBOOT=no”改成“ONBOOT=yes”并保存退出。

通过命令重启网络服务,是配置生效

service network restart

如果不想通过DHCP动态获取IP地址,也可以在网络配置文件中添加以下配置项指定网络参数

IPADDR0=192.168.21.128  #设置IP地址
PREFIXO0=24  #设置子网掩码
GATEWAY0=192.168.21.2  #设置网关
DNS1=8.8.8.8  #设置主DNS
DNS2=8.8.4.4  #设置备DNS

网卡启用后,就可以通过SSH远程操作、通过yum方便的安装程序了。

查看ip地址,可以通过ip命令

ip addr

二、安装配置环境

1、安装基本工具

安装yum额外源、wget、unzip、gcc等基本工具

yum -y install epel-release wget unzip gcc
yum -y install libsmbclient libsmbclient-devel redis

关闭SELinux,可先通过sestatus -v命令查看SELinux是否开启

/usr/sbin/sestatus -v

修改/etc/selinux/config,将’SELINUX=enforcing’改为’SELINUX=disabled’,重启系统即可生效,或者本次可以使用’setenforce 0’临时关闭。

2、安装MariaDB

通过yum安装MariaDB

yum -y install mariadb mariadb-server

开启、启动服务,运行管理工具

systemctl enable mariadb.service
systemctl start mariadb.service
mysql_secure_installation

mysql_secure_installation的输入如下,牢记自己的数据库root密码

Set root password? [Y/n] Y
New password:
Re-enter new password:Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

登录到mysql shell为Nextcloud创建用户和数据库。

mysql -u root -p

验证root密码后,在mysql shell执行

create database nextcloud_db;
create user nextclouduser@localhost identified by 'nextclouduser@';
grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by 'nextclouduser@';
flush privileges;
exit

这样就创建了一个nextcloud_db数据库和nextclouduser用户,用户密码为’nextclouduser@’。

3、安装Nginx

通过yum安装Nginx

yum -y install nginx
mkdir /var/www
chown -R nginx:nginx /var/www

开启、启动Nginx服务

systemctl enable nginx.service
systemctl start nginx.service

使用nginx -s reload可以重载配置而不需要重启nginx

开放防火墙HTTP、HTTPS端口

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
systemctl restart firewalld

4、安装PHP

添加PHP7-FPM webtatic仓库,安装php7主体以及nextcloud需要的一些模块。

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php71w-fpm php71w-cli php71w-gd php71w-mcrypt php71w-mysql php71w-pear php71w-xml php71w-mbstring php71w-pdo php71w-json php71w-opcache php71w-pecl-apcu php71w-pecl-apcu-devel php71w-pecl-igbinary php71w-pecl-igbinary-devel php71w-pecl-imagick php71w-pecl-imagick-devel php71w-pecl-redis php71w-pecl-redis-devel
vi /etc/php-fpm.d/www.conf

编辑/etc/php-fpm.d/www.conf

;修改user和group这两行,大概在8行左右
user = nginx
group = nginx;取消这几行的注释,大概在第370行左右
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

建立相关目录,修改相关目录权限

mkdir -p /var/lib/php/session
chown -R nginx:nginx /var/lib/php/session/
vi /etc/php.d/opcache.ini

修改/etc/php.d/opcache.ini,将以下行注释去掉,并修改为对应的配置值

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=1
opcache.save_comments=1

安装smbclient扩展模块

yum -y install libsmbclient libsmbclient-devel
pecl install smbclient
vi /etc/php.d/smbclient.ini

新建/etc/php.d/smbclient.ini,添加如下内容

extension=smbclient.so

开启、启动php-fpm服务

systemctl enable php-fpm.service
systemctl start php-fpm.service

三、安装Nextcloud

1、下载并解压到www目录

wget https://download.nextcloud.com/server/releases/nextcloud-12.0.2.zip
unzip nextcloud-12.0.2.zip
mv nextcloud /var/www/
chown -R nginx:nginx /var/www

2、生成SSL证书

mkdir -p /etc/nginx/cert/
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*

3、在Nginx配置

修改nginx服务配置文件/etc/nginx/nginx.conf为以下内容,将“yourname.domain”替换为自己的域名,修改client_max_body_size可以设置最大可上传的文件大小

#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       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  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;upstream php-handler {server 127.0.0.1:9000;#server unix:/var/run/php5-fpm.sock;}server {listen 80;server_name yourname.domain;# enforce httpsreturn 301 https://$server_name$request_uri;}server {listen 443 ssl http2;server_name yourname.domain;ssl_certificate /etc/nginx/cert/nextcloud.crt;ssl_certificate_key /etc/nginx/cert/nextcloud.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;# Path to the root of your installationroot /var/www/nextcloud/;location = /robots.txt {allow all;log_not_found off;access_log off;}# 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;location = /.well-known/carddav {return 301 $scheme://$host/remote.php/dav;}location = /.well-known/caldav {return 301 $scheme://$host/remote.php/dav;}# set max upload sizeclient_max_body_size 512M;fastcgi_buffers 64 4K;# Enable gzip but do not remove ETag headersgzip 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$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;#Avoid sending the security headers twicefastcgi_param modHeadersAvailable true;fastcgi_param front_controller_active true;fastcgi_pass php-handler;fastcgi_intercept_errors on;fastcgi_request_buffering off;}location ~ ^/(?:updater|ocs-provider)(?:$|/) {try_files $uri/ =404;index index.php;}# Adding the cache control header for js and css files# Make sure it is BELOW the PHP blocklocation ~ \.(?:css|js|woff|svg|gif)$ {try_files $uri /index.php$uri$is_args$args;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;# Optional: Don't log access to assetsaccess_log off;}location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {try_files $uri /index.php$uri$is_args$args;# Optional: Don't log access to other assetsaccess_log off;}}}

让Nginx重新载入配置

nginx -s reload

4、初始化

使用域名或者IP访问,就会出现初始设置页面,在这里设置Nextcloud管理员用户名和密码,然后选择使用的数据库为MySQL/MariaDB,填入之前设置数据库时的用户名(nextclouduser)、密码(nextclouduser@)、数据库名称(nextcloud_db),然后确认进行初始化后就可以使用了。

5、添加信任域名

Nextcloud本身的安全机制,会检查访问的域名,如果没有配置在信任域名中,会提示正在通过不信任的域名访问。

Nextcloud初始化完毕后,会生成“/var/www/nextcloud/config/config.php”配置文件,里面的’trusted_domains’配置项为信任域名,初始化完毕后只有一项,为主机的IP地址。可以修改该配置项,添加绑定的域名

'trusted_domains' =>
array (0 => '192.168.56.101',1 => 'yourname.domain',
),

6、开启内存缓存

开启内存缓存,可以提升响应速度。之前我们已经通过yum安装了redis服务,通过pecl安装了php的apcu、redis组件,下面先把redis设置为系统服务,再修改Nextcloud的配置。

安装、配置redis服务,设置服务自启、启动服务

yum -y install redis
systemctl enable redis
systemctl start redis

修改/var/www/nextcloud/config/config.php文件,在配置加入

'memcache.local' => '\OC\Memcache\APCu',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => array('host' => 'localhost','port' => 6379,),

让Nginx重新载入配置

nginx -s reload

部署Nextcloud私有云相关推荐

  1. 树莓派--搭建nextcloud私有云

    树莓派–搭建nextcloud私有云 网上已有很多的教程是关于nextcloud或owncloud的私有云的搭建,但是都是零零碎碎,并不完整,这里以树莓派raspbain 10 buster系统为例, ...

  2. Ubuntu服务器上部署kodexplorer私有云盘

    阅读目录 一.准备 二.下载安装xampp 三.下载安装可道云kodexplorer 注意:云服务器部署和普通的Ubuntu上部署有一些区别,因为云服务器上只能使用命令行,没有界面. 一.准备 首先, ...

  3. docker安装Nextcloud私有云盘

    1 nextcoud简介 官方网站:https://nextcloud.com/ github地址:https://github.com/nextcloud Nextcloud,所有数据的安全之家!根 ...

  4. 搭建nextcloud私有云盘

    要搭建Nextcloud,需要在服务器上安装和配置Nginx.PHP和SQLite3.下面是一些基本步骤: 安装Nginx 可以使用包管理器进行安装.例如,在Ubuntu上可以运行以下命令: sudo ...

  5. 用vcap部署cloudfoundry私有云

    [color=indigo] 研究cloudfoundry已经有一段时间了,在前期部署上确实遇到了很多问题,也走了很多弯路,现在就总结一下: 首先说的是,cloudfoundry现在还处于bete版本 ...

  6. CentOS 7 搭建Nextcloud私有云

    Nextcloud 简介: 对于私人网盘,其中最出名的就是 seafile.owncloud和nextcloud.seafile是国人开发的,有免费和企业版,免费的功能有限:nextcloud是own ...

  7. 在AWS云服务器上部署Docker,并使用Docker部署ownCloud私有云盘

    1.启动实例(Ubuntu 20.04) 2.Mac 终端听过ssh方式连接AWS云服务器 2.1 2.2复制到终端 2.3:记得加上.ssh 2.4:链接成功 3.下载Docker 3.1:进入ro ...

  8. Nextcloud私有云 - 零基础搭建私有云盘

    文章目录 摘要 视频教程 1. 环境搭建 2. 测试局域网访问 3. 内网穿透 3.1 ubuntu本地安装cpolar 3.2 创建隧道 3.3 测试公网访问 4 配置固定http公网地址 4.1 ...

  9. 燕麦私有云,应用最广泛的私有云存储方案

    每当提及燕麦企业云盘,大家很自然的会联想到燕麦片这一绿色.健康且富含营养的食品.其实此燕麦非彼燕麦,燕麦企业云盘(OATOS企业网盘)是基于云计算技术,面向政企用户的云端文件管理与协同工作平台.燕麦私 ...

最新文章

  1. python 字典操作 内存占用,python - 如何强行释放字典使用的内存? - SO中文参考 - www.soinside.com...
  2. python 提交form-data之坑
  3. 【AndroidSupport】LinearLayoutCompat
  4. datetimepicker控件怎么改变hover颜色_VBA入门课程,ActiveX控件系列知识,复合框的属性与常见VBA代码...
  5. Android打包的那些事
  6. [转载]轻松玩转LCD12864-基于AVR单片机的LCD12864串行显示
  7. Maven与IDEA结合
  8. WebStorm 9 配置 Live Edit 功能与浏览器实现同步
  9. mysql存储过程自定义结构体_(转)MySQL存储过程/存储过程与自定义函数的区别...
  10. 工程数学(数值分析)第六讲:数值微积分
  11. 【Vue2.0】—Vue脚手架配置代理(二十二)
  12. 对比iOS中的四种数据存储
  13. WebService 常用免费调用接口 与 JWS(Java Web Service) 调用第三方 webService 天气服务
  14. 去除lcd图片的摩尔纹_送上妊娠纹的最强攻略!几十款热门产品大测评!
  15. java ArrayList添加元素全部一样
  16. STM32--舵机(SG90)
  17. 配置vhost、https、重定向
  18. 三、Windows Server 2016各版本说明
  19. 明日之后无限金条服务器,明日之后:无限金条bug 你值得收藏
  20. Excel2013打印时怎么固定表头及表尾让打印后的每页都可以看得到

热门文章

  1. 《机器人爱好者(第1辑)》——机器人领域新动态
  2. c语言动态结构体数组
  3. 中国石油大学 2018-2019赛季多校联合新生训练赛第一场 题解与补题
  4. 程序员只能吃“青春饭”?IT行业年龄焦虑如何破局?
  5. 手机访问电脑文件_彻底解决手机-电脑互传大文件的难题 电脑-手机快捷互联互通...
  6. 无人驾驶11:行为规划
  7. GBTC牛市中的天使,熊市中恶魔!
  8. 统计大写的辅音字母 C语言
  9. linux强行安装软件,linux软件安装
  10. Google创始人佩奇和布林简介