1.搭建环境说明
因为计划在CentOS系统下运行多个应用,所以方案选择会有一点不同。
详细组成:
• Nginx 1.16.1
• MySql 5.7.27
• Redis 5.0.6
• PHP 7.2.23 (fpm-fcgi)
还有就是,赋予部署用户是pi,需要自行创建该用户。
2.安装基础环境
安装基础依赖和工具。
yum install -y epel-release yum-utils unzip curl wget
bash-completion policycoreutils-python mlocate bzip2
2.1安装MySql
centos7 通过Yum安装MySql5.7并开启远程访问
6月 18, 2019
2,164 2 0
Last Updated on 2019年9月4日
前言
Mysql大家都懂的了,我就不过多做介绍了,直接进行mysql的安装吧,下面记录如果通过yum安装mysql5.7,此方法照样适用于安装8.0,5.6,5.5等mysql版本
正文
- 删除mariadb
centos7 默认会安装mysql的另一个分支版本mariadb,在安装mysql前,需要将其删除
查出mariadb的rpm包
$ rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
忽略依赖关系,删除此包
$ rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
2. 添加官方yum源并安装mysql
访问mysql官方yum源下载地址,选择系统,点击下载,进入页面,复制下载连接
下载安装此yum仓库
$ rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
安装完成后,此yum源仓库默认是安装mysql最新版8.0版本。
需要我们修改一下文件中的下列项,使其下载5.7版本,如果要安装别的版本,就打开对应版本,将别的版本关闭即可。
vim /etc/yum.repos.d/mysql-community.repo
Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/KaTeX parse error: Expected 'EOF', got '#' at position 24: …/ enabled=1 #̲ 这里将0改为1,开启5.7版…basearch/
enabled=0 # 这里将1改为0,关闭8.0版本
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
修改完成后,安装mysql5.7
$ yum install -y mysql-community-server
安装完成后,配置文件为 /etc/my.cnf 根据实际情况进行配置。
3. 启动服务,开启远程访问
启动mysql服务
$ systemctl start mysqld
设为开启自启动
$ systemctl enable mysqld
第一次启动mysql后,会自动生成一个初始密码在日志文件中,默认的日志文件路径为:/var/log/mysqld.log
找出初始化密码
$ cat /var/log/mysqld.log |grep password
2019-06-18T12:12:04.161088Z 1 [Note] A temporary password is generated for root@localhost: 2%w)IDysCVZQ
这里密码就是上面输出的那段,使用此密码登录mysql
$ mysql -u root -p
复制密码输出,进入mysql
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.26
Copyright © 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
修改密码,mysql5.7的默认密码强度很高,需要有大小写,符号和数字,长度大于6,缺一不可
mysql> alter user ‘root’@‘localhost’ identified by ‘Changjiu123!’;
Query OK, 0 rows affected (0.00 sec)
如果你不像要这么复杂的密码,修改密码强度设定为最低,即只判断密码长度
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
开启远程访问
$ grant all privileges on . to ‘root’@’%’ identified by ‘Changjiu123!’;
Query OK, 0 rows affected, 1 warning (0.00 sec)
刷新权限生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
到此就完成了mysql的最初设置了,现在就可以用账号密码,访问此mysql服务了
访问之前别忘了要打开数据库3306端口
$ firewall-cmd --add-port=3306/tcp --permanent
$ firewall-cmd --reload
结束
下面建一个nextcloud数据库。
进入myql
mysql -u root -p
create database nextcloud;
设置超强密码!!
create user nextcloud@’%’ identified by ‘****************’;
grant all privileges on nextcloud.* to nextcloud@’%’ identified by ‘****************’;
flush privileges;
quit;
2.2安装Redis
2.3安装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-FPM
vi /etc/php-fpm.d/www.conf
将用户和组都改为pi
user = pi
group = pi
注意: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
增加php内存
vi /etc/php.ini
每个脚本可以消耗的时间,单位也是秒
max_input_time = 60
脚本运行最大消耗的内存
memory_limit = 4096M
上载文件的最大许可大小
upload_max_filesize = 4096M
进入缓存设置
vi /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
-------END--------
3.nginx
在/var/lib目录下为session路径创建一个新的文件夹,并将用户名和组设为nginx
mkdir -p /var/lib/php/session
chown pi:pi -R /var/lib/php/session/
重启:systemctl restart php-fpm
开机自启:systemctl enable php-fpm
3.安装Nginx
先删除系统可能自带的PHP和nginx,用来面命令查找是否有安装
$ rpm -qa |grep nginx
强制删除软件包,软件包全称就是上面通过rpm -qa 查询到的软件包全名
$ rpm -e --nodeps {软件包全称}
安装yum的epel源,这里推荐用阿里云的镜像安装,包更全。
$ rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
安装nginx
$ yum install -y nginx
安装完nginx后,首先为Nextcloud生成自签名SSL证书,如果有就不需要自己生成,拷贝到对应目录下就好。
创建证书目录
mkdir -p /etc/nginx/cert
$ cd /etc/nginx/cert/ # 没有则创建此文件夹
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/1_nextcloud.kioye.cn_bundle.crt -keyout /etc/nginx/cert/2_nextcloud.kioye.cn.key
会出现下面的选项需要填写,可以随便填。
Country Name (2 letter code) [XX]:cn # 国家
State or Province Name (full name) []:guangdong # 省份
Locality Name (eg, city) [Default City]:guangzhou # 地区名字
Organization Name (eg, company) [Default Company Ltd]:Amos # 公司名
Organizational Unit Name (eg, section) []:Technology # 部门
Common Name (eg, your name or your server’s hostname) []:Amos # CA主机名
Email Address []:Amos@Amos.com # Email地址
修改证书和文件夹权限
$ chmod 600 /etc/nginx/cert/*
$ chmod 700 /etc/nginx/cert
3.3配置nginx。
进入nextcloud.conf编辑状态
vi /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 nextcloud.kioye.cn;
# enforce https
return 301 https://$server_name:443$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name nextcloud.kioye.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/1_nextcloud.kioye.cn_bundle.crt;
ssl_certificate_key /etc/nginx/cert/2_nextcloud.kioye.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;
}
}
重启:systemctl restart nginx
开机自启:systemctl enable nginx
4.安装Nextcloud
先下载
wget https://download.nextcloud.com/server/releases/nextcloud-17.0.0.zip
解压
unzip nextcloud-*.zip
移动到指定目录下
mv nextcloud /var/www/
修改权限
chown -R pi:pi /var/www/nextcloud
关闭防火墙!
临时关闭
setenforce 0
进入编辑
vi /etc/selinux/config
设置为禁用状态
SELINUX=disabled
关闭并取消开机自启
systemctl stop firewalld
systemctl disable firewalld
自行修改一下hosts文件。
访问网站:https://nextcloud.kioye.cn
初始化完成,查看nextcloud环境状态。
安装smbclient扩展模块
yum -y install libsmbclient libsmbclient-devel php-smbclient
pecl install smbclient
集成onlyoffice
onlyOffice服务使用docker安装。所以需要提前安装好docker环境。
docker环境安装: CentOS7下安装docker
nextcloud下的onlyoffice插件:ONLYOFFICE
onlyoffice的GitHub:onlyoffice docker
下载onlyffice插件
wget https://github.com/ONLYOFFICE/onlyoffice-nextcloud/releases/download/v3.0.2/onlyoffice.tar.gz
解压
tar zxvf onlyoffice.tar.gz
移动到apps下
mv onlyoffice /var/www/nextcloud/apps/
赋权
chown -R pi:pi /var/www/nextcloud/apps/onlyoffice
创建密钥
mkdir -p /home/pi/onlyoffice/certs
chown -R pi:pi /home/pi/onlyoffice
chmod 700 /home/pi/onlyoffice
chmod 600 /home/pi/onlyoffice/*
后台运行
#docker run -i -t -d -p 9300:80 onlyoffice/documentserver
docker run -i -t -d -p 9300:443 -v /home/pi/onlyoffice/:/var/www/onlyoffice/Data onlyoffice/documentserver
启动正常后,设置开机自启容器
docker update --restart=always xxx