nextcloud私有云盤的部署

nextcloud在centos系統下搭建本身的私有云盤php

搭建一套本身的私有云盤,讓數據存儲更加方便、可靠。本身搭建的雲存儲,首先沒有什麼容量、下載速度的限制,並且本地訪問速度很快。一開始覺得Nextcloud只是一個網盤雲存儲,後來看到Nextcloud內置了Office文檔、圖片相冊、日曆聯繫人、兩步驗證、文件管理、RSS閱讀等豐富的應用,我發現Nextcloud已經僅僅能夠用做我的或者團隊存儲與共享,還能夠打形成爲一個我的辦公平臺,幾乎至關於一個我的的Dropbox了。css

本身搭建私有云其實很簡單,首先須要一臺主機,而後須要選擇一個私有云軟件(好比ownCloud、nextCloud、seafile)。如下內容將介紹如何在 CentOS 7 服務器中安裝和配置Nextcloud,而且會經過 Nginx 和 PHP7-FPM 來運行 Nextcloud,同時使用 MariaDB 數據庫系統。具體部署方法以下:html

一 . 部署環境的系統是Centos7版本node

[root@nextcloud ~]# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core)mysql

二. 安裝並配置Nginx和php-fpmnginx

[root@nextcloud ~]# yum -y install epel-releaseweb

[root@nextcloud ~]# yum -y install nginxajax

添加一個yum源來安裝php-fpmredis

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmsql

安裝相關組件

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.d/www.conf
.....
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/cert/nextcloud.crt -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.com                                                 
    
而後將證書文件的權限設置爲660
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*
 
五. 下載並安裝Nextcloud
wget https://download.nextcloud.com/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/nginx/nginx.conf

#user nobody;
worker_processes 1;

events {

worker_connections 1024;
}

http {
  include mime.types;
  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.com;
  return 301 https://$server_name$request_uri;
  }


  server {
  listen 443 ssl;
  server_name nextcloud.lxplwh.com;

  ssl_certificate /etc/nginx/cert/nextcloud.crt;
  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 = /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 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;
  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/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@nextcloud ~]# systemctl restart nginx
 
七. 安裝Nextcloud
解析上面nginx中配置的域名nextcloud.lxplwh.com,邦定hosts. 訪問http: //nextcloud .lxplwh.com進行Nextcloud界面安裝.

 

設置賬號密碼,以及數據庫的鏈接信息。若是不報錯,便可安裝完成,進入。

到此安裝完成。

 

下面進行一些安全與性能優化

爲了您服務的安全和性能, 請將全部設置配置正確. 咱們將會進行一些自動化檢查以幫助您完成這項工做. 詳情請查看 "小提示" 部分及相關文檔.

  • HTTP 請求頭 "X-Frame-Options" 沒有配置爲 "SAMEORIGIN". 這是一個潛在的安全或隱私風險, 咱們建議您調整這項設置.
  • 內存緩存未配置. 若是可用, 請配置 memcache 以加強性能. 更多信息請查看咱們的文檔.
  • PHP 的組件 OPcache 沒有正確配置. 爲了提供更好的性能, 咱們建議在php.ini文件中使用下列設置:
    opcache.enable=1
    opcache.enable_cli=1
    opcache.interned_strings_buffer=8
    opcache.max_accelerated_files=10000
    opcache.memory_consumption=128
    opcache.save_comments=1
    opcache.revalidate_freq=1

修改程序目錄下的config目錄中的config.php文件,在配置文件中添加多個Memcached實例,也能夠添加一個:

'memcache.local'  => '\OC\Memcache\APCu',
'memcache.distributed'  => '\OC\Memcache\Memcached',
'memcached_servers'  => array(
      array( 'localhost' , 11211),
      array( 'server1.example.com' , 11211),
      array( 'server2.example.com' , 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。點擊右上角的設置圖標裏的"管理"-"其餘設置"

 

 

 

 

轉載自:https://www.cnblogs.com/lxplwh/p/8398522.html

相關文章
相關標籤/搜索