nextcloud----安裝

  • 管理
  • 		<div class="blogStats">
    			
    			<!--done-->
    

    隨筆-
    42 
    文章-

    評論-

    		</div><!--end: blogStats -->
    	</div><!--end: navigator 博客導航欄 -->
    	<div id="post_detail">
    

    基於LNMP平臺部署NextCloud私有云盤

    	</h1>
    	<div class="clear"></div>
    	<div class="postBody">
    

    一、NextCloud概述

    雲盤這個詞無論是做技術出身的朋友還是普通的網民,想必已經聽的非常多了,在日常生活當中我們用的最多的雲盤莫過於百度網盤了

    在前幾年百花齊放的網盤市場,到現如今只剩下了百度網盤,說起百度網盤大家並不陌生,特別是它限速的特徵,讓廣大朋友久久不能忘懷啊

    不過也沒辦法,任何企業都是以盈利爲目的,你既然享受了線上存儲給你帶來的便利,那你就得交錢,不交錢就給你限速,限到你哭暈在廁所

    另一方面我們需要知道,做存儲也是非常燒錢的,譬如給用戶提供數據存儲的磁盤開銷,以及給用戶提供數據上傳與下載的帶寬開銷,所以大家也得諒解


    有限速?不安全?要會員? 基於這幾點大家可能會想到部署個人存儲,部署個人存儲的程序大家可能又會想到 Seafile、dropbox、OwnCloud、Syncbox,這其中有些是開源的,有些是收費的

    今天寫的這篇文章是基於 NextCloud 這個開源程序的,那NextCloud又是啥呢?NextCloud 由原 OwnCloud 團隊所打造,號稱是下一代存儲,用過之後也算是實至名歸

    如果要部署個人雲存儲,那麼使用 NextCloud 絕對是一個非常好的選擇,開源這個特點咱們就拋開不說了,NextCloud 使用PHP與JavaScript 所編寫

    支持多種數據庫類型,包括:MySQL、Oracle、Mariadb、SQLite、PostgreSQL 等主流的數據庫

    與此同時 NextCloud 也爲 Linux、Windows、Android、ios、Mac 等各種主流平臺提供了相應的客戶端

    從而實現了跨平臺的設備數據共享與同步,不僅如此 NextCloud 還提供了許多應用軟件與插件的安裝,包括 office文檔、日曆、郵件、思維導圖、在線編輯、文件管理、等豐富的附加功能

    所以要是自己部署私有云存儲,或者團隊需要進行數據共享,那麼 NextCloud 可以稱得上是首選


    說了那麼多,下面進入正題,本文基於(CentOS7+Nginx-1.16.1+MySQL-5.6.45+PHP-7.3.13+Redis-3.2.13)來部署NextCloud

    所採用的部署方式均爲源碼(.tar.gz),因爲使用源碼部署,在後面需要安裝某些軟件的擴展時非常方便、需要注意:這裏的PHP版本需要5.X以上的,否則部署完成以後,在瀏覽訪問會提示版本過低


    二、NextCloud部署

    1)準備工作

    1、關閉相應的安全軟件、否則放行相應的流量

    1
    2
    [root@nextcloud ~]# setenforce 0
    [root@nextcloud ~]# systemctl stop firewalld

    2、提前安裝所有的依賴包

    1
    2
    3
    4
    5
    6
    [root@nextcloud ~]# yum clean all && yum makecache
    [root@nextcloud ~]# yum -y install libss-devel libstdc++-devel dbus-devel libaio-devel \
    bison-devel libverto-devel curl curl-devel openssl openssl-devel bzip2 bzip2-devel \
    icu libicu-devel gmp gmp-devel readline readline-devel pcre pcre-devel zlib zlib-devel gcc gcc-c++ ncurses-devel \
    libaio-devel freetype freetype-devel ImageMagick ImageMagick-devel autoconf m4 libgcc e2fsprogs perl-Data-Dumper \
    libcurl libcurl-devel libxml2 libxml2-devel gd gd-devel libjpeg libjpeg-devel libpng libpng-devel libxslt libxslt-devel

    3、爲MySQL與Nginx創建專門的運行用戶

    1
    2
    3
    [root@nextcloud ~]# groupadd mysql
    [root@nextcloud ~]# useradd -M -s /sbin/nologin nginx
    [root@nextcloud ~]# useradd -M -s /sbin/nologin mysql -g mysql

    2)部署Nginx

    1、下載並安裝Nginx

    1
    2
    3
    4
    [root@nextcloud ~]# wget -c http://www.nginx.org/download/nginx-1.16.1.tar.gz
    [root@nextcloud ~]# tar xf nginx-1.16.1.tar.gz -C /usr/src/
    [root@nextcloud ~]# cd /usr/src/nginx-1.16.1/
    [root@nextcloud nginx-1.16.1]# ./configure --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module && make -j 8 && make install -j 8 && cd ~

    2、添加Nginx至環境變量、並將其添加爲系統服務

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    [root@nextcloud ~]# echo 'export PATH=/etc/nginx/sbin:$PATH' >> /etc/profile
    [root@nextcloud ~]# source /etc/profile && nginx
     
    [root@nextcloud ~]# cat > /usr/lib/systemd/system/nginx.service << EOF
    [Unit]
    Description=nginx
    After=network.target
     
    [Service]
    Type=forking
    PIDFile=/etc/nginx/logs/nginx.pid
    ExecStart=/etc/nginx/sbin/nginx
    ExecReload=killall -s HUP $(cat /etc/nginx/logs/nginx.pid)
    ExecStop=killall -s QUIT $(cat /etc/nginx/logs/nginx.pid)
    PrivateTmp=Flase
     
    [Install]
    WantedBy=multi-user.target
    EOF
     
    [root@nextcloud ~]# systemctl daemon-reload && pkill -9 nginx
    [root@nextcloud ~]# systemctl restart nginx && systemctl enable nginx
    Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

    3)部署MySQL

    1、安裝MySQL之前、我們先安裝cmake工具

    1
    2
    3
    4
    [root@nextcloud ~]# wget -c https://cmake.org/files/v2.8/cmake-2.8.12.tar.gz
    [root@nextcloud ~]# tar xf cmake-2.8.12.tar.gz -C /usr/src/
    [root@nextcloud ~]# cd /usr/src/cmake-2.8.12/
    [root@nextcloud cmake-2.8.12]# ./configure && gmake -j 8 && gmake install && cd

    2、下載並安裝MySQL

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    [root@nextcloud ~]# wget -c https://downloads.mysql.com/archives/get/file/mysql-5.6.45.tar.gz
    [root@nextcloud ~]# tar xf mysql-5.6.45.tar.gz -C /usr/src/
    [root@nextcloud ~]# cd /usr/src/mysql-5.6.45/
    [root@nextcloud mysql-5.6.45]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DSYSCONFDIR=/etc \
    -DMYSQL_DATADIR=/usr/local/mysql/data \
    -DENABLED_LOCAL_INFILE=ON \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_EXTRA_CHARSETS=all \
    -DWITH_DEBUG=0 \
    -DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock
    make -j 8 && make install -j 8 && cd ~

    3、將MySQL添加至環境變量、並創建對應的存儲目錄、授予對應的權限

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [root@nextcloud ~]# mkdir /usr/local/mysql/tmp
    [root@nextcloud ~]# mkdir /usr/local/mysql/log
    [root@nextcloud ~]# mkdir /usr/local/mysql/pid
    [root@nextcloud ~]# mkdir /usr/local/mysql/binlog
    [root@nextcloud ~]# mkdir /usr/local/mysql/relaylog
    [root@nextcloud ~]# mkdir /usr/local/mysql/tmpdata
    [root@nextcloud ~]# chown -R mysql:mysql /usr/local/mysql
    [root@nextcloud ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
    [root@nextcloud ~]# source /etc/profile
    [root@nextcloud ~]# mv /etc/my.cnf /etc/my.cnf.bak
    [root@nextcloud ~]# cd /usr/src/mysql-5.6.45 && cp support-files/my-default.cnf /etc/my.cnf

    4、優化MySQL配置文件以提升性能

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    [root@nextcloud mysql-5.6.45]# cat > /etc/my.cnf << EOF
    [client]
    port = 3306
    socket = /usr/local/mysql/tmp/mysql.sock
     
    [mysqld]
    user = mysql
    port = 3306
    bind_address = 0.0.0.0
    max_connections = 3600
    max_connect_errors = 200
    autocommit = ON
    skip-name-resolve
    symbolic-links = 0
    skip-external-locking
    explicit_defaults_for_timestamp = ON
    basedir = /usr/local/mysql
    datadir = /usr/local/mysql/data
    socket = /usr/local/mysql/tmp/mysql.sock
    innodb_tmpdir = /usr/local/mysql/tmpdata
    pid-file = /usr/local/mysql/pid/mysql.pid
    log-error = /usr/local/mysql/log/mysql_error.log
     
    character-set-server = utf8
    init_connect = SET NAMES utf8
    collation-server = utf8_general_ci
     
    slow_query_log = ON
    long_query_time = 1
    relay_log_recovery = 1
    log_slow_admin_statements = 1
    log_slow_slave_statements = 1
    min_examined_row_limit = 960
    log_queries_not_using_indexes = OFF
    slow_query_log_file = /usr/local/mysql/log/mysql_slow.log
     
    server-id = 11
    sync_binlog = 0
    expire_logs_days = 9
    max_binlog_size = 512M
    max_binlog_cache_size = 8M
    transaction_isolation = repeatable-read
     
    back_log = 300
    max_allowed_packet = 64M
    sort_buffer_size = 1M
    join_buffer_size = 1M
    read_buffer_size = 2M
    read_rnd_buffer_size = 2M
    thread_cache_size = 64
    thread_stack = 256K
    query_cache_size = 32M
    query_cache_limit = 2M
    query_cache_min_res_unit = 2k
    tmp_table_size = 64M
    max_heap_table_size = 64M
    table_open_cache = 4096
    open_files_limit = 65535
    table_open_cache_instances = 8
    connect_timeout = 9
    interactive_timeout = 21600
    wait_timeout = 21600
     
    default-storage-engine = InnoDB
    innodb_buffer_pool_size = 2G
    innodb_log_file_size = 128M
    innodb_log_files_in_group = 3
    innodb_log_buffer_size = 16M
    innodb_flush_log_at_trx_commit = 2
    innodb_file_per_table = 1
    innodb_read_io_threads = 8
    innodb_write_io_threads = 8
    innodb_flush_method = O_DIRECT
    innodb_thread_concurrency = 16
    innodb_large_prefix = ON
    innodb_file_format = barracuda
    EOF

    5、對MySQL進行初始化

    1
    2
    3
    [root@nextcloud mysql-5.6.45]# BASEDIR="/usr/local/mysql"
    [root@nextcloud mysql-5.6.45]# DATADIR="/usr/local/mysql/data"
    [root@nextcloud mysql-5.6.45]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=$BASEDIR --datadir=$DATADIR

    6、將MySQL添加爲系統服務

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    [root@nextcloud mysql-5.6.45]# cp support-files/mysql.server /usr/local/mysql/bin/mysql.sh
    [root@nextcloud mysql-5.6.45]# chmod +x /usr/local/mysql/bin/mysql.sh && cd ~
    [root@nextcloud ~]# cat > /usr/lib/systemd/system/mysql.service << EOF
    [Unit]
    Description=MySQL
    After=network.target
     
    [Service]
    User=mysql
    Group=mysql
    LimitNOFILE=65535
     
    Type=forking
    ExecStart=/usr/local/mysql/bin/mysql.sh start
    ExecStop=/usr/local/mysql/bin/mysql.sh stop
     
    [Install]
    WantedBy=multi-user.target
    EOF

    7、啓動MySQL服務

    1
    2
    3
    4
    5
    6
    [root@nextcloud ~]# systemctl start mysql
    [root@nextcloud ~]# netstat -anput | grep mysql
    tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      32584/mysqld
     
    [root@nextcloud ~]# systemctl enable mysql
    Created symlink from /etc/systemd/system/multi-user.target.wants/mysql.service to /usr/lib/systemd/system/mysql.service.

    4)安裝libzip庫

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    [root@nextcloud ~]# wget -c https://nih.at/libzip/libzip-1.2.0.tar.gz
    [root@nextcloud ~]# tar xf libzip-1.2.0.tar.gz -C /usr/src/
    [root@nextcloud ~]# cd /usr/src/libzip-1.2.0/
    [root@nextcloud libzip-1.2.0]# ./configure && make -j 8 && make install -j 8 && cd ~
    [root@nextcloud ~]# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
    [root@nextcloud ~]# cat > /etc/ld.so.conf.d/local.conf << EOF
    /usr/local/lib64
    /usr/local/lib
    /usr/lib
    /usr/lib64
    EOF
    [root@nextcloud ~]# ldconfig -v

    5)部署PHP

    1、下載並安裝PHP

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    [root@nextcloud ~]# wget -c https://www.php.net/distributions/php-7.3.13.tar.gz
    [root@nextcloud ~]# tar xf php-7.3.13.tar.gz -C /usr/src/
    [root@nextcloud ~]# cd /usr/src/php-7.3.13/
    [root@nextcloud php-7.3.13]# ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7 --enable-mbstring --enable-fpm \
    --with-gd --with-zlib --enable-inline-optimization --with-jpeg-dir=/usr/lib --disable-debug --disable-rpath \
    --enable-shared --with-libxml-dir --with-xmlrpc --enable-soap  --with-openssl --enable-exif --enable-fileinfo \
    --enable-filter --with-pcre-dir --enable-ftp --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir \
    --with-freetype-dir --with-gettext --with-gmp --enable-json --enable-mbregex --enable-mbregex-backtrack \
    --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir  --with-pdo-sqlite  --enable-session --enable-shmop \
    --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip \
    --enable-mysqlnd-compression-support --with-pear --enable-opcache --with-mhash --with-pcre-regex --with-sqlite3 --enable-bcmath --with-iconv --with-bz2 \
    --enable-calendar --with-curl --with-cdb --enable-dom --without-pear --disable-phar && make -j 8 && make install -j 8

    2、複製參考文件、併爲PHP創建軟鏈接

    1
    2
    3
    [root@nextcloud php-7.3.13]# cp php.ini-production /usr/local/php7/php.ini
    [root@nextcloud php-7.3.13]# ln -s /usr/local/php7/bin/* /usr/local/bin/
    [root@nextcloud php-7.3.13]# ln -s /usr/local/php7/sbin/* /usr/local/sbin/ && cd ~

    6)部署redis

    1、下載並安裝redis

    1
    2
    3
    4
    [root@nextcloud ~]# wget -c http://download.redis.io/releases/redis-3.2.13.tar.gz
    [root@nextcloud ~]# tar xf redis-3.2.13.tar.gz -C /usr/src/
    [root@nextcloud ~]# cd /usr/src/redis-3.2.13/
    [root@nextcloud redis-3.2.13]# make -j 8 && make PREFIX=/usr/local/redis install && cd ~

    2、創建對應的存儲目錄、並做好軟連接

    1
    2
    3
    4
    5
    6
    7
    8
    [root@nextcloud ~]# mkdir /usr/local/redis/conf
    [root@nextcloud ~]# mkdir /usr/local/redis/pid
    [root@nextcloud ~]# mkdir /usr/local/redis/log
    [root@nextcloud ~]# mkdir /usr/local/redis/tmp
    [root@nextcloud ~]# mkdir /usr/local/redis/data
    [root@nextcloud ~]# cp /usr/src/redis-3.2.13/redis.conf /usr/local/redis/conf/
    [root@nextcloud ~]# cp /usr/local/redis/conf/redis.conf /usr/local/redis/conf/redis.conf.bak
    [root@nextcloud ~]# ln -s /usr/local/redis/bin/* /usr/local/bin/

    3、定義redis配置文件以優化性能

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    [root@nextcloud ~]# cat > /usr/local/redis/conf/redis.conf << EOF
    bind 0.0.0.0
    port 6379
    timeout 180
    daemonize yes
    maxclients 6500
    protected-mode yes
    requirepass abc-123
    tcp-backlog 2048
    tcp-keepalive 300
    databases 16
     
    supervised no
    syslog-enabled yes
    syslog-ident redis
    syslog-facility local0
    loglevel notice
    logfile "/usr/local/redis/log/redis.log"
    pidfile "/usr/local/redis/pid/redis.pid"
    unixsocketperm 755
    unixsocket "/usr/local/redis/tmp/redis.sock"
    slowlog-log-slower-than 5000
    slowlog-max-len 128
    dir "/usr/local/redis/data"
     
    save 900 1
    save 300 10
    save 60 10000
    rdbcompression yes
    rdbchecksum no
    dbfilename dump.rdb
    stop-writes-on-bgsave-error no
     
    appendonly yes
    appendfsync everysec
    aof-load-truncated yes
    appendfilename appendonly.aof
    no-appendfsync-on-rewrite no
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    aof-rewrite-incremental-fsync yes
     
    repl-diskless-sync no
    repl-diskless-sync-delay 5
    repl-disable-tcp-nodelay no
    repl-backlog-size 1mb
    repl-backlog-ttl 3600
    slave-priority 100
     
    hz 10
    maxmemory-policy noeviction
    activerehashing yes
    hash-max-ziplist-value 64
    hash-max-ziplist-entries 512
    list-compress-depth 0
    lua-time-limit 5000
    notify-keyspace-events ""
    list-max-ziplist-size -2
    latency-monitor-threshold 0
    set-max-intset-entries 512
    zset-max-ziplist-entries 128
    zset-max-ziplist-value 64
    hll-sparse-max-bytes 3000
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit pubsub 32mb 8mb 60
    client-output-buffer-limit slave 256mb 64mb 60
    EOF

    4、將redis添加爲系統服務、最後啓動redis服務即可

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    [root@nextcloud ~]# cat > /usr/lib/systemd/system/redis.service << EOF
    [Unit]
    Description=redis
    After=network.target
     
    [Service]
    Type=forking
    LimitNOFILE=10240
    ExecStart=/usr/local/bin/redis-server /usr/local/redis/conf/redis.conf
     
    [Install]
    WantedBy=multi-user.target
    EOF
    systemctl enable redis
    systemctl start redis

    7)安裝intl模塊、因爲部署OwnCloud要用到、這裏部署的是NextCloud 所以這個也可以不安裝

    1
    2
    3
    4
    5
    6
    7
    8
    9
    [root@nextcloud ~]# cd /usr/src/php-7.3.13/ext/intl/
    [root@nextcloud intl]# /usr/local/php7/bin/phpize
    Configuring for:
    PHP Api Version:         20180731
    Zend Module Api No:      20180731
    Zend Extension Api No:   320180731
    [root@nextcloud intl]# ./configure --with-php-config=/usr/local/php7/bin/php-config && make -j 8 && make install -j 8
    [root@nextcloud intl]# cp /usr/local/php7/lib/php/extensions/no-debug-non-zts-20180731/intl.so /usr/local/php7/include/php/ext/
    [root@nextcloud intl]# sed -i '3i extension=intl.so' /usr/local/php7/php.ini && cd

    8)安裝imagick模塊、用於圖像處理

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [root@nextcloud ~]# wget -c https://pecl.php.net/get/imagick-3.4.4.tgz
    [root@nextcloud ~]# tar xf imagick-3.4.4.tgz -C /usr/src/
    [root@nextcloud ~]# cd /usr/src/imagick-3.4.4/
    [root@nextcloud imagick-3.4.4]# /usr/local/php7/bin/phpize
    Configuring for:
    PHP Api Version:         20180731
    Zend Module Api No:      20180731
    Zend Extension Api No:   320180731
    [root@nextcloud imagick-3.4.4]# ./configure --with-php-config=/usr/local/php7/bin/php-config && make -j 8 && make install -j 8
    [root@nextcloud imagick-3.4.4]# cp  /usr/local/php7/lib/php/extensions/no-debug-non-zts-20180731/imagick.so /usr/local/php7/include/php/ext/
    [root@nextcloud imagick-3.4.4]# sed -i '4i extension=imagick.so' /usr/local/php7/php.ini && cd

    9)安裝opcache模塊、用於提升性能

    1
    2
    3
    4
    5
    6
    7
    8
    [root@nextcloud ~]# cd /usr/src/php-7.3.13/ext/opcache/
    [root@nextcloud opcache]# /usr/local/php7/bin/phpize
    Configuring for:
    PHP Api Version:         20180731
    Zend Module Api No:      20180731
    Zend Extension Api No:   320180731
    [root@nextcloud opcache]# ./configure --with-php-config=/usr/local/php7/bin/php-config && make -j 8 && make install -j 8 && cd ~
    [root@nextcloud ~]# cp /usr/local/php7/lib/php/extensions/no-debug-non-zts-20180731/opcache.so /usr/local/php7/include/php/ext/

    10)安裝redis模塊、用於緩存數據、提升性能

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [root@nextcloud ~]# wget -c http://pecl.php.net/get/redis-3.1.6.tgz
    [root@nextcloud ~]# tar xf redis-3.1.6.tgz -C /usr/src/
    [root@nextcloud ~]# cd /usr/src/redis-3.1.6/
    [root@nextcloud redis-3.1.6]# /usr/local/php7/bin/phpize
    Configuring for:
    PHP Api Version:         20180731
    Zend Module Api No:      20180731
    Zend Extension Api No:   320180731
    [root@nextcloud redis-3.1.6]# ./configure --with-php-config=/usr/local/php7/bin/php-config && make -j 8 && make install -j 8 && cd ~
    [root@nextcloud ~]# cp /usr/local/php7/lib/php/extensions/no-debug-non-zts-20180731/redis.so /usr/local/php7/include/php/ext/
    [root@nextcloud ~]# sed -i '5i extension=redis.so' /usr/local/php7/php.ini

    11)編輯PHP配置文件、優化相應的參數以提升性能

    注意:這裏面的配置項、在PHP的配置文件當中幾乎都有了、但都是註釋的、只需將其打開並調整相應參數即可、最後的那個 zend_extension 需要添加在 [opcache] 下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [root@nextcloud ~]# cp /usr/local/php7/php.ini /usr/local/php7/php.ini.bak
    [root@nextcloud ~]# vim /usr/local/php7/php.ini
    memory_limit = 1024M
    max_execution_time = 0
    post_max_size = 10800M
    upload_max_filesize = 10240M
    opcache.enable=1
    opcache.enable_cli=1
    opcache.fast_shutdown = 1
    opcache.save_comments = 1
    opcache.revalidate_freq = 5
    opcache.validate_timestamps = 0
    opcache.memory_consumption = 512
    opcache.interned_strings_buffer = 8
    opcache.max_accelerated_files = 10000
    zend_extension = /usr/local/php7/include/php/ext/opcache.so

    12)複製模板文件、並將PID的路徑改爲絕對路徑

    1
    2
    3
    [root@nextcloud ~]# cp /usr/local/php7/etc/php-fpm.conf.default  /usr/local/php7/etc/php-fpm.conf
    [root@nextcloud ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default  /usr/local/php7/etc/php-fpm.d/www.conf
    [root@nextcloud ~]# sed -i 's#;pid = run/php-fpm.pid#pid = /usr/local/php7/var/run/php-fpm.pid#' /usr/local/php7/etc/php-fpm.conf

    13)更改屬主與屬組、並開啓動態模式、調整動態參數、最後需要打開環境變量、打開變量、不然在NextCloud檢測中、會提示找不到路徑

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    [root@nextcloud ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf /usr/local/php7/etc/php-fpm.d/www.conf.bak
    [root@nextcloud ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf
    user = nginx
    group = nginx
    pm = dynamic
    pm.max_children = 130
    pm.start_servers = 15
    pm.min_spare_servers = 6
    pm.max_spare_servers = 35
     
    env[HOSTNAME] = $HOSTNAME
    env[PATH] = /usr/local/bin:/usr/bin:/bin
    env[TMP] = /tmp
    env[TMPDIR] = /tmp
    env[TEMP] = /tmp

    14)啓動 php-fpm 服務的時候、大家先使用 -t 選項 檢查一下、然後即可啓動 php-fpm 服務、如果有錯誤、那就根據提示進行排查、最後使用 -m 選項 查看自己安裝了那些模塊

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    [root@nextcloud ~]# /usr/local/sbin/php-fpm -t  #檢查
    [20-Dec-2019 15:14:12] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful
    [root@nextcloud ~]# echo $?
    0
     
    [root@nextcloud ~]# /usr/local/sbin/php-fpm    #以上檢查成果之後就使用此命令啓動 php-fpm 服務
     
    [root@nextcloud ~]# /usr/local/sbin/php-fpm -m  #使用 -m 選項、查看自己安裝了那些模塊
    bcmath
    bz2
    calendar
    cgi-fcgi
    Core
    ctype
    curl
    date
    dba
    dom
    exif
    fileinfo
    filter
    ftp
    gd
    gettext
    gmp
    hash
    iconv
    imagick
    intl
    json
    libxml
    mbstring
    mysqli
    mysqlnd
    openssl
    pcre
    PDO
    pdo_mysql
    pdo_sqlite
    posix
    redis
    Reflection
    session
    shmop
    SimpleXML
    soap
    sockets
    SPL
    sqlite3
    standard
    sysvmsg
    sysvsem
    sysvshm
    tokenizer
    wddx
    xml
    xmlreader
    xmlrpc
    xmlwriter
    xsl
    zip
    zlib

    15)下載 NextCloud 軟件包、並解壓至 Nginx 相關目錄、最後授予相應的權限

    1
    2
    3
    4
    [root@nextcloud ~]# wget -c https://download.nextcloud.com/server/releases/nextcloud-17.0.2.zip
    [root@nextcloud ~]# unzip nextcloud-17.0.2.zip > /dev/null
    [root@nextcloud ~]# mv nextcloud /etc/nginx/html/cloud
    [root@nextcloud ~]# chown -R nginx:nginx /etc/nginx/html/cloud

    16)定義 Nginx 配置文件、將訪問目錄指向 NextCloud 剛剛解壓的目錄

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    [root@nextcloud ~]# cp /etc/nginx/conf/nginx.conf /etc/nginx/conf/nginx.conf.bak
    [root@nextcloud ~]# vim /etc/nginx/conf/nginx.conf
    user  nginx;   
     
    worker_processes  8;
    worker_rlimit_nofile 65535;
    worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
     
    pid     /etc/nginx/logs/nginx.pid;      #自定義
    error_log   /etc/nginx/logs/error.log  info;    #自定義
     
     
    events  {
        use epoll;
        worker_connections  65535;
    }
     
     
    http    {
        include       mime.types;
        default_type  application/octet-stream;
     
        log_format mds  '$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  mds;
     
            sendfile        on;
            tcp_nopush      on;
            tcp_nodelay     on;
            send_timeout        10;
            keepalive_timeout   60;
            server_tokens       off;
            client_max_body_size  512m;
            fastcgi_buffers 64 4K;
            client_header_buffer_size  15k;
            large_client_header_buffers  4 128k;
            open_file_cache_valid  30s;
            open_file_cache_min_uses 2;
            open_file_cache max=65535 inactive=20s;
     
            gzip  on;
            gzip_min_length     3k;
            gzip_buffers     4  16k;
            gzip_http_version   1.1;
            gzip_comp_level     1;
            gzip_vary       on;
            gzip_types  text/plain application/x-javascript text/css application/xml;
     
        server  {
            listen          80;     #自定義
                server_name     www.mds.com;    #自定義
                charset     utf-8;
                root /etc/nginx/html/cloud; #自定義
              add_header Referrer-Policy "no-referrer" always;
                add_header X-Content-Type-Options "nosniff" always;
                add_header X-Download-Options "noopen" always;
                add_header X-Frame-Options "SAMEORIGIN" always;
                add_header X-Permitted-Cross-Domain-Policies "none" always;
                add_header X-Robots-Tag "none" always;
                add_header X-XSS-Protection "1; mode=block" always;
                fastcgi_hide_header X-Powered-By;
     
     
            location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
                fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
                            set $path_info $fastcgi_path_info;
                try_files $fastcgi_script_name =404;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $path_info;
                fastcgi_param modHeadersAvailable true;
                fastcgi_param front_controller_active true;
                fastcgi_intercept_errors on;
                fastcgi_request_buffering off;
                fastcgi_pass 127.0.0.1:9000;    #自定義
                    }
                     
            rewrite /.well-known/carddav /remote.php/dav permanent;
            rewrite /.well-known/caldav /remote.php/dav permanent;
     
            location / {
                    rewrite ^ /index.php;
                }
             
                    location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
                            try_files $uri /index.php$request_uri;
                            access_log off;
                    }
     
            location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
                try_files $uri/ =404;
                index index.php;
                    }
             
                location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
                    deny all;
                }
     
                location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
                    deny all;
                }
     
            location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
                    try_files $uri /index.php$request_uri;
                    add_header Cache-Control "public, max-age=15778463";
                    add_header Referrer-Policy "no-referrer" always;
                    add_header X-Content-Type-Options "nosniff" always;
                    add_header X-Download-Options "noopen" always;
                    add_header X-Frame-Options "SAMEORIGIN" always;
                    add_header X-Permitted-Cross-Domain-Policies "none" always;
                    add_header X-Robots-Tag "none" always;
                    add_header X-XSS-Protection "1; mode=block" always;
                    access_log off;
                }  
        }
    }

    17)添加hosts映射、最後重啓 Nginx 服務即可

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    [root@nextcloud ~]# echo "10.2.3.11 www.mds.com" >> /etc/hosts
    [root@nextcloud ~]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    10.2.3.11 www.mds.com
     
    [root@nextcloud ~]# nginx -t
    nginx: the configuration file /etc/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/conf/nginx.conf test is successful
    [root@nextcloud ~]#
    [root@nextcloud ~]# systemctl restart nginx
    [root@nextcloud ~]#
    [root@nextcloud ~]# netstat -anput | grep nginx
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      106307/nginx: maste
    [root@nextcloud ~]#
    [root@nextcloud ~]# systemctl | grep nginx
    nginx.service                                                                       loaded active running   nginx

    18)爲 NextCloud 創建數據存儲目錄、併爲其設置權限

    1
    2
    [root@nextcloud ~]# mkdir -p /opt/cloud/data
    [root@nextcloud ~]# chown -R nginx:nginx /opt/cloud/data/

    19)創建 NextCloud 所使用的數據庫、併爲其授權、最後重啓MySQL服務即可

    1
    2
    3
    4
    5
    [root@nextcloud ~]# mysqladmin -u root password 'abc-123' 2> /dev/null
    [root@nextcloud ~]# mysql -u root -pabc-123 -e"drop database test;" 2> /dev/null
    [root@nextcloud ~]# mysql -u root -pabc-123 -e"create database cloud;" 2> /dev/null
    [root@nextcloud ~]# mysql -u root -pabc-123 -e"grant all privileges on cloud.* to 'cloud'@'10.2.3.%' identified by 'abc-123'" 2> /dev/null
    [root@nextcloud ~]# systemctl restart mysql

    20)確認所有服務都已全部啓動

    1
    2
    3
    4
    5
    6
    7
    [root@nextcloud ~]# netstat -anput
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
    tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      106095/php-fpm: mas
    tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      107289/mysqld      
    tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      107484/redis-server
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      106307/nginx: maste

    三、NextCloud使用

    1、初始化 NextCloud

    提示:在瀏覽器中、輸入 www.mds.com 即可出現如下界面、按照提示添加完成以後、點擊安裝完成即

     2、初始化完成以後、即可跳到如下界面

     3、上傳軟件包

     4、設置頭像、設置郵件、設置語言

     5、查看 NextCloud 日誌、如果有錯誤、請按照提示進行解決

     6、查看系統負載情況

     7、爲 NextCloud 添加 redis 緩存、內容需要放在括號內、不要放在括號外、最後重啓各個服務即可

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    [root@nextcloud ~]# cp /etc/nginx/html/cloud/config/config.php /etc/nginx/html/cloud/config/config.php.bak
    [root@nextcloud ~]# vim /etc/nginx/html/cloud/config/config.php
      'memcache.local' => '\OC\Memcache\Redis',
      'redis' => array (
      'host' => '10.2.3.11',
      'port' => '6379',
      'password' => 'abc-123',
      'timeout' => 1.5,
      'memcache.locking' => '\OC\Memcache\Redis',
      ),
     
     
    [root@nextcloud ~]# pkill -9 php-fpm
    [root@nextcloud ~]# /usr/local/sbin/php-fpm
    [root@nextcloud ~]# systemctl restart nginx mysql redis

    8、點擊概覽、可以看見有兩個提示、第一個是要求使用 https 、這裏主要解決的是第二個警告

    注意:它要求使用 https 因爲我這裏是虛擬機、不是雲服務器、所以這裏我就不再贅述、如果是雲服務器、那就自己去申請證書即可、而下面的配置主要就是解決第二個警告、只需執行如下命令即可

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [root@nextcloud ~]# sudo -u nginx /usr/local/bin/php /etc/nginx/html/cloud/occ db:convert-filecache-bigint
    The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php
    Following columns will be updated:
     
    * mounts.storage_id
    * mounts.root_id
    * mounts.mount_id
     
    This can take up to hours, depending on the number of files in your instance!
    Continue with the conversion (y/n)? [n] y  #回答 y 即可

    9、確認所有警告都已解決、如下所示

     10、對 NextCloud 配置郵件測試

    注意:這一步是配置發件人、而收件人是剛剛在個人信息裏面所配置的郵箱

     11、查看發送的郵件

    12、將 NextCloud 掛載到本地

    注意:需要先修改註冊表

    路徑爲:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\WebClient\Parameters、裏面有個名爲 BasicAuthLevel 的項、值本爲1、將其修改爲 2 即可、接下來去服務裏面開啓 WebClieent 服務

     

     進入 NextCloud 複製這個 URL 連接

    接下來就直接在 Windows 當中映射即可、如下所示

     輸入用戶名和密碼、這裏登錄 NextCloud 的密碼

     可以看到、映射成功、並且可以正常複製文件、這樣就可以像使用本地磁盤一樣來使用 NextCloud 了

     

    【只是爲了打發時間】

    分類: 網站應用
    <div id="blog_post_info">
    
    0
    0
    <div class="clear"></div>
    <div id="post_next_prev">
    
    <a href="https://www.cnblogs.com/lvthinks/p/12068144.html" class="p_n_p_prefix">« </a> 上一篇:    <a href="https://www.cnblogs.com/lvthinks/p/12068144.html" title="發佈於 2019-12-19 15:38">yum倉庫配置與內網源部署記錄</a>
    <br>
    <a href="https://www.cnblogs.com/lvthinks/p/12103091.html" class="p_n_p_prefix">» </a> 下一篇:    <a href="https://www.cnblogs.com/lvthinks/p/12103091.html" title="發佈於 2019-12-26 16:59">CentOS使用465端口發送郵件</a>
    
    posted @ 2019-12-20 10:37  懷嶺以南  閱讀(473)  評論(0編輯  收藏
        <div id="google_ads_iframe_/1090369/C2_0__container__" style="border: 0pt none;"><iframe id="google_ads_iframe_/1090369/C2_0" title="3rd party ad content" name="google_ads_iframe_/1090369/C2_0" width="468" height="60" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;" data-google-container-id="2" data-load-complete="true"></iframe></div></div>
    </div>
    <div id="under_post_kb">
    
    </div><!--end: forFlow -->
    </div>
    
    發表評論
    所有評論
    還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
    相關文章