部署期中架构-可道云
可道云压缩包
🤪1.部署db01节点(mariadb+redis)
①部署数据库(db01)
1.安装数据库服务
yum -y install mariadb mariadb-server
2.重启服务,服务添加下次开机自启
systemctl start mariadb
systemctl enable mariadb
3.查看selinxu 和防火墙是否关闭
getenforce
systemctl status firewalld
4.mysql 登入数据库,创建我们部署可道云需要的库
mysql #mariadb5.5版本默认数据库root用户没有密码,可以直接登陆
create database kodbox;
show databases; #查看数据库
5.创建远程连接用户
grant all privileges on *.* to 'all'@'%' identified by 'boy123.com';
英语翻译: grant v.授予给与
privileges n.特权
6.刷新权限
flush privileges;
②部署redis(db01)
1.安装redis服务
yum -y install redis
2.更改redis配置文件,因为redis默认监听在127.0.0.1本地,只允许本地访问,所以为了提供访问我们修改redis服务监听到自己的内网网卡上(172.16.1.51)
sed -i '/^bind/c bind 127.0.0.1 172.16.1.51' /etc/redis.conf
3.重启服务,服务添加下次开机自启
systemctl start redis
systemctl enable redis
4.查看修改之后的监听端口
netstat -lntup
🤪2.部署web01节点(nginx+php+redis)
0.先配置好nginx yum仓库(nginx官方)
cat > /etc/yum.repos.d/nginx.repo <<EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
1.安装nginx服务,(web01, web02 ,lb01,lb02 同时安装)
yum -y install nginx
2.安装php(web01 web02 同时安装)
2.1 解压我们上传的php解压包
unzip php.zip
2.2 yum本地安装关于php名称的rpm包
yum -y localinstall php/*.rpm
3.统一用户权限
创建用户
groupadd -g666 www
useradd -u666 -g666 www
更改php,nginx配置文件权限
sed -i '/^user/c user www;' /etc/nginx/nginx.conf
sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf
sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf
4.配置php应用服务器的session信息存储至Redis中,有两个文件控制session信息写在哪里。一个是/etc/php.ini 一个是/etc/php-fpm.d/www.conf
4.1 修改/etc/php.ini(Session)
[root@web01 ~]# vim /etc/php.ini
session.save_handler = redis
session.save_path = "tcp://172.16.1.51:6379?weight=1&timeout=2.5"
4.2 修改/etc/php-fpm.d/www.conf(这个文件的末行)
#注释如下两行,使用;
[root@web01 ~]# vim /etc/php-fpm.d/www.conf
;php_value[session.save_handler] = files
;php_value[session.save_path] = /var/lib/php/session
5.重启服务,将服务加入下次开机自启
systemctl start nginx php-fpm
systemctl enable nginx php-fpm
systemctl restart nginx php-fpm
6.配置站点nginx配置文件(可道云)
6.1 将默认站点打包
gzip /etc/nginx/conf.d/default.conf
6.2 配置站点配置文件
vim /etc/nginx/conf.d/kdy.etiantian.org.conf
server {
listen 80;
server_name kdy.etiantian.org;
root /code/kodbox;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000; # 将请求转给9000端口的应用程序处理
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 告诉php我们需要被解析的文件在哪个目录,是哪个文件
#fastcgi_param HTTPS on;(这个在lb配置好https再开启)
include fastcgi_params;
}
}
6.3 检查语句重启服务
nginx -t
systemctl reload nginx
7.创建站点目录,上传可道云代码,并对站点目录授权
7.1创建站点目录
mkdir -p /code/kodbox
cd /code/kodbox
7.2上传代码解压
uzip kodbox.1.13.zip
7.3对站点目录授权
chown -R www.www /code/kodbox
8.配置本地DNS劫持
9.通过谷歌浏览器用域名访问,配置数据库和redis的初始化
🤪3.部署web02,添加一个新的web节点
1.创建用户和组:
[root@web02 ~]# groupadd -g666 www
[root@web02 ~]# useradd -u666 -g666 www
2.推送nginx ,php配置文件(保证用户权限统一)
Nginx配置文件:
[root@web02 ~]# gzip /etc/nginx/conf.d/default.conf
[root@web02 ~]# scp 172.16.1.7:/etc/nginx/nginx.conf /etc/nginx/nginx.conf
[root@web02 ~]# scp 172.16.1.7:/etc/nginx/conf.d/* /etc/nginx/conf.d/
PHP配置文件:
[root@web02 ~]# scp 172.16.1.7:/etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf
[root@web02 ~]# scp 172.16.1.7:/etc/php.ini /etc/php.ini
3.推送对应的代码,给站点目录授权,用户统一
[root@web02 ~]# scp -r 172.16.1.7:/code/ /
[root@web02 ~]# chown -R www.www /code/kodbox
4.配置php应用服务器的session信息存储至Redis中,有两个文件控制session信息写在哪里。一个是/etc/php.ini 一个是/etc/php-fpm.d/www.conf
(我们已经推送过来,所以不需要再去修改,放在这里就是看一下)
4.1 修改/etc/php.ini(Session)
[root@web02 ~]# vim /etc/php.ini
session.save_handler = redis
session.save_path = "tcp://172.16.1.51:6379?weight=1&timeout=2.5"
4.2 修改/etc/php-fpm.d/www.conf(这个文件的末行)
#注释如下两行,使用;
[root@web02 ~]# vim /etc/php-fpm.d/www.conf
;php_value[session.save_handler] = files
;php_value[session.save_path] = /var/lib/php/session
5.检查语法,启动服务
[root@web02 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web02 ~]# php-fpm -t
[28-Oct-2020 19:54:37] NOTICE: configuration file /etc/php-fpm.conf test is successful
启动服务:
[root@web02 ~]# systemctl enable nginx php-fpm
[root@web02 ~]# systemctl start nginx php-fpm
**5.配置本地dns 10.0.0.8 浏览器访问查看 **
通过 访问日志(var/log/nginx/access.log)
tail -f /var/log/nginx/access.log
🤪4.配置负载均衡lb01(nginx七层负载均衡+https)
①部署https(lb01)
前端负载走https,后端应用走http协议,php应用会不支持,所以需要开启一个参数,让其支持。
注意:一定是在应用服务器上配置的
web节点开启https参数!!!!
fastcgi_param HTTPS on;
0.准备存储证书的目录位置
[root@b01 ~]# mkdir -p /etc/nginx/ssl_key
[root@lb01 ~]# cd /etc/nginx/ssl_key
1.申请证书:
[root@lb01 ssl_key]# openssl genrsa -idea -out server.key 2048
[root@lb01 ssl_key]# openssl req -days 36500 -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
②部署nginx负载均衡
0.设置nginx的代理参数
[root@lb01 ~]#vim /etc/nginx/proxy_params
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_connect_timeout 60s; # nginx连接后端的超时时间 TCP
proxy_read_timeout 60s; # 响应头部超时时间
proxy_send_timeout 60s; # 响应数据主体的超时时间
proxy_buffering on; # 开启缓冲区
proxy_buffer_size 8k; # 缓冲区Header大小
proxy_buffers 4 64k; # 缓冲区数量 * 大小 = 最大接收
1.配置站点配置文件
打包默认配置文件
gzip /etc/nginx/conf.d/default.conf
vim /etc/nginx/conf.d/proxy_kdy.etiantian.org.conf
upstream kdy {
server 172.16.1.7:80;
server 172.16.1.8:80;
}
server {
listen 443 ssl;
server_name kdy.etiantian.org;
ssl_certificate ssl_key/server.crt;
ssl_certificate_key ssl_key/server.key;
location / {
proxy_pass http://kdy;
include proxy_params;
}
}
server {
listen 80;
server_name kdy.etiantian.org;
return 302 https://$http_host$request_uri;
#rewrite ^(.*)$ https://$http_host$1;
}
2.检查语句 重启服务,把服务加入开启自启
nginx -t
systemctl restart nginx
systemctl enable nginx
3.更改配置 dns本地劫持解析 10.0.0.5 kdy.etiantian.org
3.1 https
4.测试
>/var/log/nginx/access.log #web01 web02的访问日志清空
🤪5.配置keepalived (lb01 ,lb02)
0.安装keepalived服务(lb01,lb02)
yum -y install keepalived
① 我们先配置lb01
1.配置keepalived配置文件
[root@lb01 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
router_id lb01
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 50
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.3
}
}
2.重启服务,加入下次开机自启
[root@lb01 ~]# systemctl start keepalived.service
[root@lb01 ~]# systemctl enable keepalived
② 再配置lb02
1.lb02备节点的环境要完全一致.
1.1 下载Nginx
[root@lb02 ~]# scp 172.16.1.5:/etc/yum.repos.d/nginx.repo /etc/yum.repos.d/
[root@lb02 ~]# yum install nginx -y
1.2 拷贝配置
[root@lb02 ~]# scp -rp 172.16.1.5:/etc/nginx/conf.d/* /etc/nginx/conf.d/
[root@lb02 ~]# scp -rp 172.16.1.5:/etc/nginx/ssl_key /etc/nginx/
[root@lb02 ~]# scp -rp 172.16.1.5:/etc/nginx/proxy_params /etc/nginx/
2.配置keepalived配置文件
[root@lb02 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
router_id lb02
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.3
}
}
3.重启服务,加入下次开机自启
[root@lb01 ~]# systemctl start keepalived.service
[root@lb01 ~]# systemctl enable keepalived
🤪6.配置nfs共享存储
1.安装nfs服务(web01 web02 nfs同时安装)
yum -y install nfs-utils
2.web找到挂载点
chown -R www.www /code/kodbox/static
3.配置nfs共享目录
[root@nfs ~]# cat /etc/exports
/data/kdy 172.16.1.0/24(rw,async,all_squash,anonuid=666,anongid=666)
4.创建共享目录,和统一用户www,并对共享目录授权
[root@nfs ~]# groupadd -g666 www
[root@nfs ~]# useradd -u666 -g666 www
[root@nfs ~]# mkdir -p /data/kdy
[root@nfs ~]# chown -R www.www /data/kdy
5.重启nfs服务,将服务加入开机自启
systemctl restart nfs
systemctl enable nfs
6.web节点查看共享目录
showmount -e 172.16.1.31
7.两台web节点挂载nfs共享的目录
mount -t nfs 172.16.1.31:/data/kdy /code/kodbox/static
8.写入到fstab
vim /etc/fstab
172.16.1.31:/data/kdy /code/kodbox/static/images/common nfs defaults 0 0