centos8一键安装nextcloud和onlyoffice脚本
时间: 2023-06-13 16:05:25 浏览: 171
以下是 CentOS 8 一键安装 Nextcloud 和 OnlyOffice 的脚本:
```bash
#!/bin/bash
# 安装 Nextcloud 和 OnlyOffice
# 本脚本仅适用于 CentOS 8
# 安装依赖
dnf install -y epel-release
dnf install -y wget unzip nginx mariadb-server php php-fpm php-mysqlnd php-gd php-mbstring php-zip php-intl php-opcache php-xml php-json redis php-pecl-redis
# 下载 Nextcloud
wget https://download.nextcloud.com/server/releases/latest.zip -O /tmp/nextcloud.zip
# 解压 Nextcloud
unzip /tmp/nextcloud.zip -d /usr/share/nginx/html/
# 设置权限
chown -R nginx:nginx /usr/share/nginx/html/nextcloud/
# 配置 Nginx
cat << EOF > /etc/nginx/conf.d/nextcloud.conf
server {
listen 80;
server_name your.domain.com;
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
fastcgi_hide_header X-Powered-By;
root /usr/share/nginx/html/nextcloud;
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/.+|ocs-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 HTTPS on;
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
fastcgi_read_timeout 300;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
location ~ \.(?:css|js|woff2?|svg|gif|png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$request_uri;
access_log off;
expires 360d;
add_header Cache-Control "public, max-age=31536000, immutable";
add_header Pragma public;
add_header ETag "";
}
location ~ \.(?:manifest|appcache|html|xml|json)$ {
add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0";
add_header Pragma no-cache;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}
EOF
# 重启 Nginx
systemctl restart nginx
# 配置 MariaDB
systemctl enable mariadb
systemctl start mariadb
mysql -u root << END
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
END
# 下载 OnlyOffice
wget https://github.com/ONLYOFFICE/DocumentServer/releases/download/v6.4.2/ONLYOFFICE-documentserver-opensource-src.v6.4.2.tar.gz -O /tmp/onlyoffice.tar.gz
# 解压 OnlyOffice
tar -zxvf /tmp/onlyoffice.tar.gz -C /usr/share/nginx/html/
# 设置权限
chown -R nginx:nginx /usr/share/nginx/html/documentserver/
# 配置 Nginx
cat << EOF > /etc/nginx/conf.d/onlyoffice.conf
server {
listen 80;
server_name document.domain.com;
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
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;
add_header Referrer-Policy no-referrer-when-downgrade;
add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'";
client_max_body_size 0;
location / {
proxy_pass https://127.0.0.1:8443;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header X-Forwarded-Host \$host;
}
}
EOF
# 生成 SSL 证书
dnf install -y certbot python3-certbot-nginx
certbot --nginx -d your.domain.com -d document.domain.com
# 重启 Nginx
systemctl restart nginx
```
在脚本中,您需要将以下内容替换为您自己的配置:
- `your.domain.com`:您的 Nextcloud 域名
- `document.domain.com`:您的 OnlyOffice 域名
- `password`:您的 Nextcloud 数据库密码
安装完成后,您可以通过 `https://your.domain.com` 访问 Nextcloud,通过 `https://document.domain.com` 访问 OnlyOffice。
阅读全文