Skip to content

Instantly share code, notes, and snippets.

@penzoiders
Last active January 1, 2021 14:13
Show Gist options
  • Save penzoiders/105c6ac92912bd6b3367eef9d1201e04 to your computer and use it in GitHub Desktop.
Save penzoiders/105c6ac92912bd6b3367eef9d1201e04 to your computer and use it in GitHub Desktop.
Install OnlyOffice Document Server on clean CentOS 7 base without asking anything + oneliner to get SSL cert from Let's Encrypt
#!/bin/bash
# Install OnlyOffice Document Server on clean CentOS 7 base (may not work on non fresh systems) without asking anything
# HOW TO: just open a root terminal and brutally copy/paste this gist to your shell.
# SSL READY: featuring also a lazy-boy-style oneliner to get SSL cert from Let's Encrypt ( see bottom of this gist )
curl -sL https://rpm.nodesource.com/setup_8.x | bash -
cat << EOF > /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/\$basearch/
gpgcheck=0
enabled=1
EOF
yum install -y nginx epel-release postgresql postgresql-server firewalld
cat << EOF > /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
EOF
service postgresql initdb
systemctl enable postgresql
sed -i 's#host all all 127.0.0.1/32 ident#host all all 127.0.0.1/32 trust#;s#host all all ::1/128 ident#host all all ::1/128 trust#' /var/lib/pgsql/data/pg_hba.conf
systemctl restart postgresql
cd /tmp
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;"
yum install -y redis rabbitmq-server
systemctl start redis
systemctl enable redis
systemctl start rabbitmq-server
systemctl enable rabbitmq-server
yum install -y http://download.onlyoffice.com/repo/centos/main/noarch/onlyoffice-repo.noarch.rpm
yum install -y onlyoffice-documentserver
systemctl start supervisord
systemctl enable supervisord
systemctl start nginx
systemctl enable nginx
cat /usr/bin/documentserver-configure.sh | sed 's/read -e/#read -e/' | sed 's/^read_saved_params$/DB_PWD=onlyoffice\nRABBITMQ_PWD=guest\nread_saved_params/' > /tmp/documentserver-configure-unattended.sh
bash /tmp/documentserver-configure-unattended.sh
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload
yum update -y
reboot
# You can secure it using Let's Encrypt SSL certificates with this single line here.
# NOTE: do this after reboot, you'll need to have a proper DNS record and ports 80 and 443 reachable from public IP
# you also need a DNS record to be published for that IP before launching the following command
# firewall-cmd --zone=public --add-service=https --permanent && firewall-cmd --reload && yum install -y python2-certbot-nginx && certbot --nginx certonly && systemctl stop nginx && cat /etc/onlyoffice/documentserver/nginx/onlyoffice-documentserver-ssl.conf.template | sed 's#{{SSL_CERTIFICATE_PATH}}#/etc/letsencrypt/live/'$(ls /etc/letsencrypt/live | head -n 1)'/fullchain.pem#' | sed 's#{{SSL_KEY_PATH}}#/etc/letsencrypt/live/'$(ls /etc/letsencrypt/live | head -n 1)'/privkey.pem#' > /etc/nginx/conf.d/onlyoffice-documentserver.conf && systemctl start nginx
@greavette
Copy link

Hello Lorenzo and thank you for making this script available for all to use. Very much appreciate your hard work to create this sccript.

Would you be able to confirm if this script is still working and will install the latest version of OnlyOffice Document Server so that I may point my Nextcloud to it for my OnlyOffice connector?

Also, could you assist with what address I should be using to connect to this OnlyOffice document server to confirm it is working? When I put into my browser the IP address of my CentOS 7 server where I've run your script I get an error that this site cannot be reached. I haven't added my SSL cert yet as I will be using Reverse Proxy for SSL. But I would have thought even using port 80 to access the IP of my server where I've run this script I should see OnlyOffice Document server running.

Thank you in advance for any advice you can provide me.

@penzoiders
Copy link
Author

in theory, if you skip last line, you should end up with a document server on port 80.
then it's up to you to proxy it and put an SSL.

This script is still valid for latest version on Centos7

@penzoiders
Copy link
Author

keep in mind that with nextcloud hub you can have the document server directly inside of nextcloud instance.
https://nextcloud.com/blog/how-to-install-onlyoffice-in-nextcloud-hub-and-new-integration-feature/

at present time it's not handling file revisions but worth using it to avoid running 2 servers.

@greavette
Copy link

greavette commented Apr 25, 2020

Thank you very much for taking the time to reply to my question. I've used this script on a CentOS 7 minimal install and it appears to work with no errors reported as it runs except for a reference to line 35 which command not found. I tried accessing the site over port 80 using my IP but had an error page.

So I've issued the bash documentserver-configure.sh command again and confirmed the setup. Now when I reference the sever using my ip I can see that document server is now running. I do see your script running this bash script but for some reason my webpage wouldn't work unless I ran it again.

I very much appreciate you providing this script. for my usecase I do see that Nextcloud 18 does come with a documentserver app we can use for OnlyOffice. Sadly that app of OnlyOffice does not include a spellcheck and having an online document editing system without spellcheck won't work for me. Until the documentserver app has been updated with spellcheck I will prefer to use your script to install to install OnlyOffice on a separate server.

Do you know if your script could be used to upgrade OnlyOffice as well?

Thank you in advance for any advice you can provide me.

@penzoiders
Copy link
Author

penzoiders commented Apr 26, 2020

can't replicate the line 35 error you mention, anyway if running again fix the thing it's not a big deal.

to update the server you just need to do it via normal yum update no other config or custom script required.

@greavette
Copy link

Appreciate the feedback! Thanks again for providing this script for all. Take care.

@ingenetic
Copy link

ingenetic commented Jan 1, 2021

Hi,penzoiders, i've just install onlyoffice document server, but after reboot , i can't access to onlyoffice document server.
and when i excecute latest line for SSL , after complete . nginx can not starting :

cat: /etc/onlyoffice/documentserver/nginx/onlyoffice-documentserver-ssl.conf.template: No such file or directory
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

Please advice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment