基本环境:
centos 7.7
mariadb 5.5
nginx 1.61
php 7.2
redis 3.2

安装步骤:
一、安装依赖包:

yum install -y epel-release yum-utils unzip curl wget \
bash-completion policycoreutils-python mlocate bzip2

二、更新系统:

yum update -y

三、安装nginx

yum install -y nginx
systemctl enable nginx
systemctl start nginx

# 创建证书目录
mkdir -p /etc/nginx/cert
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/pan.51itop.cn.crt -keyout /etc/nginx/cert/pan.51itop.cn.key
# 修改权限
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*

四、安装php并配置php

yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php72
yum -y install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql php-mbstring \
php-intl php-pecl-apcu php-mysqlnd php-pecl-redis php-imagick  php-fpm php-zip php-xml php-process \
php-pear php-pdo php-json php-devel php-xmlrpc php-soap php-ldap php-memcached

vim /etc/php-fpm.d/www.conf
# 将用户和组都改为nginx
user = nginx
group = nginx

# 注意:php-fpm所监听的端口为9000
listen = 127.0.0.1:9000

# 去掉下面几行注释
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

vim /etc/php.ini
# 每个脚本可以消耗的时间,单位也是秒
max_input_time = 60

#在/var/lib目录下为session路径创建一个新的文件夹,并将用户名和组设为nginx
mkdir -p /var/lib/php/session
chown pi:pi -R /var/lib/php/session/

五、安装数据库并配置数据库

yum install -y mariadb mariadb-server
systemctl enable mariadb.service
systemctl start mariadb.service

mysql -uroot -p                  #mariadb第一次登录不需要密码就可以进入
update mysql.user set password=password("123123")where user='root'; #更新root密码
create database nextcloud;
create user 'nextcloud'@'localhost' identified by '123123';
grant all privileges on nextcloud.* to 'nextcloud'@'localhost';
flush privileges;

六、下载并解压安装包到指定目录

wget https://download.nextcloud.com/server/releases/nextcloud-17.0.1.zip
unzip nextcloud-17.0.1.zip
cp -R nextcloud/ /var/www/                      #因为用的是apache的,拷贝默认网页目录
mkdir /var/www/nextcloud/data
chown -R nginx:nginx /var/www/nextcloud/

七、创建nextcloud的nginx配置文件

[root@test12 config]# cat /etc/nginx/conf.d/nextcloud.conf 
upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php/php7.2-fpm.sock;
}

server {
    listen 80;
    listen [::]:80;
    server_name pan.51itop.cn;
    # enforce https
    return 301 https://$server_name:443$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name pan.51itop.cn;

    # Use Mozilla's guidelines for SSL/TLS settings
    # https://mozilla.github.io/server-side-tls/ssl-config-generator/
    # NOTE: some settings below might be redundant
    ssl_certificate /etc/nginx/cert/pan.51itop.cn.crt;
    ssl_certificate_key /etc/nginx/cert/pan.51itop.cn.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=15552000; includeSubDomains; preload;" always;
    #
    # 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 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;

    # Remove X-Powered-By, which is an information leak
    fastcgi_hide_header X-Powered-By;

    # Path to the root of your installation
    root /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;

    # The following rule is only needed for the Social app.
    # Uncomment it if you're planning to use this app.
    #rewrite ^/.well-known/webfinger /public.php?service=webfinger last;

    location = /.well-known/carddav {
      return 301 $scheme://$host:$server_port/remote.php/dav;
    }
    location = /.well-known/caldav {
      return 301 $scheme://$host:$server_port/remote.php/dav;
    }

    # set max upload size
    client_max_body_size 512M;
    fastcgi_buffers 64 4K;

    # Enable gzip but do not remove ETag headers
    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;

    # Uncomment if your server is build with the ngx_pagespeed module
    # This module is currently not supported.
    #pagespeed off;

    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\/.+|oc[ms]-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 twice
        fastcgi_param modHeadersAvailable true;
        # Enable pretty urls
        fastcgi_param front_controller_active true;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    }

    location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
        try_files $uri/ =404;
        index index.php;
    }

    # Adding the cache control header for js, css and map files
    # Make sure it is BELOW the PHP block
    location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
        try_files $uri /index.php$request_uri;
        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;" always;
        #
        # 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 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;

        # Optional: Don't log access to assets
        access_log off;
    }

    location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
        try_files $uri /index.php$request_uri;
        # Optional: Don't log access to other assets
        access_log off;
    }
}

[root@test12 ~]# nginx -t
[root@test12 ~]# nginx -s reload

八、web登录一下,我设置的域名为https://pan.51itop.cn , 填写前面步骤五创建的数据库名、用户及密码!完成安装!

九、根据下图提示,优化一下:

[root@test12 config]#yum install -y redis
[root@test12 config]#systemctl enable redis.service
[root@test12 config]#systemctl start redis.service
[root@test12 config]# vim config.php
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\APCu',
'redis' => array(
  'host' => 'localhost',
  'port' => 6379,
),

[root@test12 config]# vim /etc/php.ini
memory_limit = 4096M

[root@test12 config]# vim /etc/php.d/10-opcache.ini
opcache.enable=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

#提示:所使用的数据库为MySQL但没有对4字节字符的支持。为正确处理文件名或评论中使用的4字节字符(比如emoji表情),建议开启MySQL的4字节字符支持。详细信息请阅读相关文档页面
#请参考以下链接(https://docs.nextcloud.com/server/17/admin_manual/configuration_database/mysql_4byte_support.html "参考页面")
#注意,参考链接上涉及的occ的要写occ文件夹的绝对路径

[root@test12 config]# systemctl restart php-fpm

十、安装smbclient扩展模块

yum -y install libsmbclient libsmbclient-devel php-smbclient
pecl install smbclient

十一、安装collabora online

#安装docker
yum install -y yum-utils
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
yum makecache fast
yum -y install docker-ce
systemctl start docker
#拉取镜像
docker pull collabora/code
#运行镜像
#注意:domain为你的nextcloud服务器地址,此处为授权的意思,并注意域名部分中的“.”要加转义字符“\”,多个域名之间用“|”隔开
docker run -t -d -p 9980:9980 -e 'domain=owncloud\\.domain\\.com\' --restart always --cap-add MKNOD collabora/code

十二、nginx反向代理collabora online

server {
    listen       443 ssl;
    server_name  office.example.com;

    ssl_certificate /path/to/certficate;
    ssl_certificate_key /path/to/key;

    # static files
    location ^~ /loleaflet {
        proxy_pass https://localhost:9980;
        proxy_set_header Host $http_host;
    }

    # WOPI discovery URL
    location ^~ /hosting/discovery {
        proxy_pass https://localhost:9980;
        proxy_set_header Host $http_host;
    }

   # main websocket
   location ~ ^/lool/(.*)/ws$ {
       proxy_pass https://localhost:9980;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
       proxy_set_header Host $http_host;
       proxy_read_timeout 36000s;
   }

   # download, presentation and image upload
   location ~ ^/lool {
       proxy_pass https://localhost:9980;
       proxy_set_header Host $http_host;
   }

   # Admin Console websocket
   location ^~ /lool/adminws {
       proxy_pass https://localhost:9980;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
       proxy_set_header Host $http_host;
       proxy_read_timeout 36000s;
   }
}

十三、在nextcloud应用中下载并启用collabora online

十四、在nextcloud应用中启用并配置ldap认证,默认已经下载。

文档更新时间: 2019-12-27 11:04   作者:子木