NextCloud+OnlyOffice搭建

NextCloud搭建

初始化环境LAMP

安装apache(如果为nginx)

yum -y install httpd
systemctl enable httpd
systemctl start httpd && systemctl status httpd
# 如果为nginx
vim /etc/yum.repos.d/mginx.repo
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    [nginx-mainline]
    name=nginx mainline repo
    baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
yum -y install nginx
systemctl enable nginx && systemctl start nginx && systemctl status nginx

安装mariadb

yum -y install mariadb mariadb-server
systemctl enable mariadb
systemctl start mariadb && systemctl status mariadb

初始化数据库

mysql_secure_installation
# 此处直接按回车即可(一开始没有密码,以后改密码则需要输入已设定的密码)
# 然后会要求你输入两次密码,然后回车
# 然后一路按Y加回车
# 直到出现Thanks for using MariaDB
systemctl restart mariadb && systemctl status mariadb

安装php以及相关组件

yum -y install php72w php72w-mysql php72w-gd php72w-ldap php72w-odbc php72w-pear php72w-xml php72w-xmlrpc php72w-mbstring php72w-bcmath php72w-mhash libjpeg* 
systemctl restart mariadb && systemctl status mariadb
systemctl restart httpd && systemctl status httpd
# nginx
systemctl restart nginx && systemctl status nginx

搭建NextCloud

新建数据库

mysql -u root -p
	show databases;
	create database nextcloud; 
	exit

下载nextcloud文件并解压

yum -y install unzip
cd /usr/local/src
wget https://download.nextcloud.com/server/releases/nextcloud-18.0.4.zip
unzip nextcloud-18.0.4.zip -d /var/www/html/
cd /var/www/html/
chmod 777 nextcloud -Rf
chown apache:apache nextcloud
systemctl restart mariadb && systemctl status mariadb
systemctl restart httpd && systemctl status httpd
# 如果为nginx
chown nginx:nginx nextcloud
systemctl restart nginx && systemctl status nginx

解决 “通过不被信任的域名访问”

方法一:

1. 打开 ../nextcloud/config/config.php
2. 找到 trusted_domains
3. 增加一项:
preg_match('/cli/i',php_sapi_name())?'127.0.0.1':$_SERVER['SERVER_NAME']
//完整的代码
//索引数字顺延就可以
'trusted_domains' => array(
	0 => '127.0.0.1',
    1 => preg_match('/cli/i',php_sapi_name())?'127.0.0.1':$_SERVER['SERVER_NAME'],
),
4. 解释:$_SERVER[‘SERVER_NAME’] 为获得当前访问的域名或IP,最初只设置了server_name,后来在查看cron任务时,发现在cli模式下是无法获得的,所以增加了cli模式判断,cli模式直接给个本地IP忽悠程序,正常模式将当前访问的域名或IP动态的添加的信任的域名中。

方法二:

'trusted_domains' =>
array (
  0 => '47.95.219.151:8080',
  1 => '172.17.145.245:8080',
),

OnlyOffice搭建

onlyoffice硬件要求

【参考】http://blog.51yip.com/server/2174.html
要求不低

CPU dual core 2 GHz or better  
RAM 2 GB or more  
HDD at least 40 GB of free space  
Additional requirements at least 4 GB of swap  
OS RHEL 7 or CentOS 7  
Additional requirements  
  PostgreSQL: version 9.1 or later  
  NGINX: version 1.3.13 or later  
  Node.js: version 8.12.0  
  Redis  
  RabbitMQ 

安装epel源

yum install epel-release

安装nginx源

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

安装依赖

yum -y install gcc-c++ automake autoconf gcc make  

安装nodejs12源(可以不安装,epel中有)

curl -sL https://rpm.nodesource.com/setup_12.x | bash -

安装nginx,配置nginx.conf

yum -y install nginx  
# vim /etc/nginx/nginx.conf  
#     user nginx;  
#     worker_processes auto;  
#     error_log /var/log/nginx/error.log;  
#     pid /run/nginx.pid;  
# 
#     # Load dynamic modules. See /usr/share/nginx/README.dynamic.  
#     include /usr/share/nginx/modules/*.conf;  
# 
#     events {  
#         worker_connections 1024;  
#     }  
# 
#     http {  
#         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  /var/log/nginx/access.log  main;  
#         sendfile            on;  
#         keepalive_timeout   65;  
#         include             /etc/nginx/mime.types;  
#         default_type        application/octet-stream;  
#         include /etc/nginx/conf.d/*.conf;  
# 
#     } 

安装启动redis,rabbitmq-server

yum -y install redis rabbitmq-server  
systemctl enable redis 
systemctl enable rabbitmq-server  
systemctl start redis && systemctl status redis
systemctl start rabbitmq-server && systemctl status rabbitmq-server 

安装postgresql,并创建数据库

yum -y install postgresql postgresql-server 
systemctl enable postgresql
service postgresql initdb  # 初始化数据库
vim /var/lib/pgsql/data/pg_hba.conf  
    host all all 127.0.0.1/32 trust # ident换成trust  
    host all all ::1/128 trust # ident换成trust  
systemctl start postgresql
# vim /usr/lib/systemd/system/postgresql.service
# 	将"Environment=PGDATA=/var/lib/pgsql/data"修改为"Environment=PGDATA=/tmp"
cd /tmp #防止could not change directory to "/root"从根目录运行时发出警告。然后必须创建数据库和用户
sudo -u postgres psql -c "CREATE DATABASE onlyoffice;"  
sudo -u postgres psql -c "CREATE USER onlyoffice WITH password 'onlyoffice';"  
sudo -u postgres psql -c "GRANT ALL privileges ON DATABASE onlyoffice TO onlyoffice;"  

安装onlyoffice源

yum install https://download.onlyoffice.com/repo/centos/main/noarch/onlyoffice-repo.noarch.rpm

安装配置onlyoffice

yum install onlyoffice-documentserver  
bash documentserver-configure.sh  
    Configuring PostgreSQL access...  
    Host: localhost 
    Database name: onlyoffice  
    User: onlyoffice  
    Password:onlyoffice  
    Trying to establish PostgreSQL connection... OK  
    Installing PostgreSQL database... OK  
    Configuring redis access...  
    Host: localhost  

    Trying to establish redis connection... OK  
    Configuring RabbitMQ access...  
    Host: localhost  
    User: guest  
    Password:guest  
    Trying to establish RabbitMQ connection... OK  
    Restarting services... OK  
systemctl enable supervisord
systemctl start supervisord  
# 浏览器访问:http://服务器IP/web-apps/apps/api/documents/api.js

配置nginx https(可以不配置)

cd /etc/onlyoffice/documentserver/nginx  
cp ds-ssl.conf.tmpl ds-ssl.conf  
ln -s /etc/onlyoffice/documentserver/nginx/ds-ssl.conf /etc/nginx/conf.d/  
vim /etc/nginx/conf.d/ds-ssl.conf
    include /etc/nginx/includes/http-common.conf;  
    ## Normal HTTP host  
    server {  
     listen 80;  
     server_name onlineoffice.netjoy.com;  
     server_tokens off;  

     ## Redirects all traffic to the HTTPS host  
     root /nowhere; ## root doesn't have to be a valid path since we are redirecting  
     rewrite ^ https://$host$request_uri? permanent;  
    }  

    #HTTP host for internal services  
    server {  
     listen 127.0.0.1:80;  
     listen [::1]:80;  
     server_name localhost;  
     server_tokens off;  

     include /etc/nginx/includes/ds-common.conf;  
     include /etc/nginx/includes/ds-docservice.conf;  
    }  

    ## HTTPS host  
    server {  
     listen 443;  
     server_name onlineoffice.netjoy.com;  
     server_tokens off;  
     root /usr/share/nginx/html;  

     ## Strong SSL Security  
     ## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html  
     ssl on;  
     ssl_certificate /etc/nginx/cert/office.pem;  
     ssl_certificate_key /etc/nginx/cert/office.key;  
     ssl_verify_client off;  

     ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";  

     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;  
     ssl_session_cache builtin:1000 shared:SSL:10m;  

     ssl_prefer_server_ciphers on;  

     add_header Strict-Transport-Security max-age=31536000;  
     # add_header X-Frame-Options SAMEORIGIN;  
     add_header X-Content-Type-Options nosniff;  

     ## [Optional] If your certficate has OCSP, enable OCSP stapling to reduce the overhead and latency of running SSL.  
     ## Replace with your ssl_trusted_certificate. For more info see:  
     ## - https://medium.com/devops-programming/4445f4862461  
     ## - https://www.ruby-forum.com/topic/4419319  
     ## - https://www.digitalocean.com/community/tutorials/how-to-configure-ocsp-stapling-on-apache-and-nginx  
     # ssl_stapling on;  
     # ssl_stapling_verify on;  
     # ssl_trusted_certificate /etc/nginx/ssl/stapling.trusted.crt;  
     # resolver 208.67.222.222 208.67.222.220 valid=300s; # Can change to your DNS resolver if desired  
     # resolver_timeout 10s;  

     ## [Optional] Generate a stronger DHE parameter:  
     ## cd /etc/ssl/certs  
     ## sudo openssl dhparam -out dhparam.pem 4096  
     ##  
     # ssl_dhparam /etc/ssl/certs/dhparam.pem;  

     include /etc/nginx/includes/ds-*.conf;  

    }  
systemctl restart nginx  

下载nextcloud-onlyoffice插件

cd nextcloud路径/apps/  
git clone https://github.com/ONLYOFFICE/onlyoffice-owncloud.git onlyoffice  

安装日志

=====================================================================
 Package                    架构    版本            源          大小
=====================================================================
正在安装:
 onlyoffice-documentserver  x86_64  5.5.1-76        onlyoffice 363 M
为依赖而安装:
 GConf2                     x86_64  3.2.6-8.el7     base       1.0 M
 adwaita-cursor-theme       noarch  3.28.0-1.el7    base       641 k
 adwaita-icon-theme         noarch  3.28.0-1.el7    base        11 M
 at-spi2-atk                x86_64  2.26.2-1.el7    base        81 k
 at-spi2-core               x86_64  2.28.0-1.el7    base       158 k
 atk                        x86_64  2.28.1-2.el7    base       263 k
 avahi-libs                 x86_64  0.6.31-20.el7   base        62 k
 cairo                      x86_64  1.15.12-4.el7   base       741 k
 cairo-gobject              x86_64  1.15.12-4.el7   base        26 k
 colord-libs                x86_64  1.3.4-2.el7     base       186 k
 cups-libs                  x86_64  1:1.6.3-43.el7  base       358 k
 dconf                      x86_64  0.28.0-4.el7    base       106 k
 dejavu-fonts-common        noarch  2.33-6.el7      base        64 k
 dejavu-sans-fonts          noarch  2.33-6.el7      base       1.4 M
 fontconfig                 x86_64  2.13.0-4.3.el7  base       254 k
 fontpackages-filesystem    noarch  1.44-8.el7      base       9.9 k
 fribidi                    x86_64  1.0.2-1.el7_7.1 base        79 k
 gdk-pixbuf2                x86_64  2.36.12-3.el7   base       570 k
 glib-networking            x86_64  2.56.1-1.el7    base       145 k
 gnutls                     x86_64  3.3.29-9.el7_6  base       680 k
 graphite2                  x86_64  1.3.10-1.el7_3  base       115 k
 gsettings-desktop-schemas  x86_64  3.28.0-3.el7    base       606 k
 gtk-update-icon-cache      x86_64  3.22.30-5.el7   base        27 k
 gtk3                       x86_64  3.22.30-5.el7   base       4.4 M
 harfbuzz                   x86_64  1.7.5-2.el7     base       267 k
 hicolor-icon-theme         noarch  0.12-7.el7      base        42 k
 jasper-libs                x86_64  1.900.1-33.el7  base       150 k
 jbigkit-libs               x86_64  2.0-11.el7      base        46 k
 json-glib                  x86_64  1.4.2-2.el7     base       134 k
 lcms2                      x86_64  2.6-3.el7       base       150 k
 libICE                     x86_64  1.0.9-9.el7     base        66 k
 libSM                      x86_64  1.2.2-2.el7     base        39 k
 libXScrnSaver              x86_64  1.2.2-6.1.el7   base        24 k
 libXcomposite              x86_64  0.4.4-4.1.el7   base        22 k
 libXcursor                 x86_64  1.1.15-1.el7    base        30 k
 libXdamage                 x86_64  1.1.4-4.1.el7   base        20 k
 libXdmcp                   x86_64  1.1.2-6.el7     base        34 k
 libXext                    x86_64  1.3.3-3.el7     base        39 k
 libXfixes                  x86_64  5.0.3-1.el7     base        18 k
 libXfont2                  x86_64  2.0.3-1.el7     base       143 k
 libXft                     x86_64  2.3.2-2.el7     base        58 k
 libXi                      x86_64  1.7.9-1.el7     base        40 k
 libXinerama                x86_64  1.1.3-2.1.el7   base        14 k
 libXmu                     x86_64  1.1.2-2.el7     base        71 k
 libXrandr                  x86_64  1.5.1-2.el7     base        27 k
 libXrender                 x86_64  0.9.10-1.el7    base        26 k
 libXt                      x86_64  1.1.5-3.el7     base       173 k
 libXtst                    x86_64  1.2.3-1.el7     base        20 k
 libXxf86vm                 x86_64  1.1.4-1.el7     base        18 k
 libepoxy                   x86_64  1.5.2-1.el7     base       211 k
 liberation-fonts-common    noarch  1:1.07.2-16.el7 base        27 k
 liberation-mono-fonts      noarch  1:1.07.2-16.el7 base       227 k
 libfontenc                 x86_64  1.1.3-3.el7     base        31 k
 libglvnd                   x86_64  1:1.0.1-0.8.git base        89 k
 libglvnd-egl               x86_64  1:1.0.1-0.8.git base        44 k
 libglvnd-glx               x86_64  1:1.0.1-0.8.git base       125 k
 libgusb                    x86_64  0.2.9-1.el7     base        40 k
 libmodman                  x86_64  2.0.1-8.el7     base        28 k
 libproxy                   x86_64  0.4.11-11.el7   base        64 k
 libsoup                    x86_64  2.62.2-2.el7    base       411 k
 libthai                    x86_64  0.1.14-9.el7    base       187 k
 libtiff                    x86_64  4.0.3-32.el7    base       171 k
 libusbx                    x86_64  1.0.21-1.el7    base        61 k
 libwayland-client          x86_64  1.15.0-1.el7    base        33 k
 libwayland-cursor          x86_64  1.15.0-1.el7    base        20 k
 libwayland-egl             x86_64  1.15.0-1.el7    base        13 k
 libwayland-server          x86_64  1.15.0-1.el7    base        39 k
 libxkbcommon               x86_64  0.7.1-3.el7     base       108 k
 libxkbfile                 x86_64  1.0.9-3.el7     base        83 k
 libxshmfence               x86_64  1.2-1.el7       base       7.2 k
 mesa-libEGL                x86_64  18.3.4-7.el7_8. updates    109 k
 mesa-libGL                 x86_64  18.3.4-7.el7_8. updates    165 k
 mesa-libgbm                x86_64  18.3.4-7.el7_8. updates     39 k
 mesa-libglapi              x86_64  18.3.4-7.el7_8. updates     46 k
 nettle                     x86_64  2.7.1-8.el7     base       327 k
 pango                      x86_64  1.42.4-4.el7_7  base       280 k
 pixman                     x86_64  0.34.0-1.el7    base       248 k
 psmisc                     x86_64  22.20-16.el7    base       141 k
 pwgen                      x86_64  2.08-1.el7      epel        26 k
 python-backports           x86_64  1.0-8.el7       base       5.8 k
 python-backports-ssl_ma... noarch  3.5.0.1-1.el7   base        13 k
 python-ipaddress           noarch  1.0.16-2.el7    base        34 k
 python-meld3               x86_64  0.6.10-1.el7    epel        73 k
 python-setuptools          noarch  0.9.8-7.el7     base       397 k
 rest                       x86_64  0.8.1-2.el7     base        63 k
 supervisor                 noarch  3.4.0-1.el7     epel       498 k
 trousers                   x86_64  0.3.14-2.el7    base       289 k
 xkeyboard-config           noarch  2.24-1.el7      base       834 k
 xorg-x11-server-Xvfb       x86_64  1.20.4-10.el7   base       854 k
 xorg-x11-server-common     x86_64  1.20.4-10.el7   base        55 k
 xorg-x11-xauth             x86_64  1:1.0.9-1.el7   base        30 k
 xorg-x11-xkb-utils         x86_64  7.7-14.el7      base       103 k

onlyoffice安装中文字体的问题

  1. 在windows中的目录C:\Windows\Fonts下查找所需要的的字体或者从网络下下载所需要的的字体
  2. 准备软件FontCreator
  3. 如果字体文件是.ttf,则直接使用FontCreator打开字体文件,然后修改:字体--属性--识别--字体族,此处如果为中文则不需要修改,如果为英文则需要修改为相应的中文(中文字体修改为中文,如果是英文或者其他字体则不需要修改)。如果字体文件是.ttc,则需要先使用FontCreator将字体文件提取成.ttf,可以只提取里面需要的字体,不需要全部提取。
  4. 将onlyoffice服务器本身的字体库中的字体暂时迁移到别的地方mkdir /tmp/fontbak && mv /usr/share/fonts/* /tmp/fontbak(如果编辑文档时需要这些字体,则不需要迁移,第8部也就不需要了)
  5. 删除/var/www/html/documentserver/fonts下面的所有文件rm -rf /var/www/html/documentserver/fonts/*
  6. 如果需要onlyoffice自带的字体,则不需要删除/var/www/html/documentserver/core-fonts中的文件,如果不需要则可以直接清空此目录,然后将自己修改好的字体文件上传至此目录
  7. 执行documentserver-generate-allfonts.sh生成字体缓存文件
  8. 将onlyoffice服务器本身的字体迁移回去mv /tmp/fontbak/* /usr/share/fonts

nextcloud插件安装

  1. 插件官方下载地址https://apps.nextcloud.com/,选择需要安装的插件进行下载注意要下载对应nextcloud的版本的插件
  2. 找到需要下载的插件放到nextcloud目录下面的apps下面
  3. 登陆管理界面,在已禁用的应用中就可以找到导入的插件,点击启用即可