操作步骤

  • 1、lnmp实现mysql数据库迁移
    • 2、lnmp实现PHP的拆分
      • 3、搭建NFS共享服务器
        • 4、搭建第二台web服务器
          • 5、搭建nginx代理和负载均衡
            • 6.配置4层负载均衡,发布内部服务器的ssh和mysql
            • 7.高可用-增加容错性(HA:High availability)
            • 8.nginx_ssl模块

1、lnmp实现mysql数据库迁移

为了实现mysql独立运行,可以进行拆分lnmp的操作
(1)重新开启一台虚拟机,安装mysql并修改mysql密码

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# hostname mysql
[root@localhost ~]#bash
[root@mysql ~]# rpm -ivh http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-release-el7-5.noarch.rpm
[root@mysql ~]# yum -y install mysql-community-server
[root@mysql ~]# systemctl start mysqld
[root@mysql ~]# systemctl enable mysqld
[root@mysql ~]# mysql_secure_installation

(2)在原来的lnmp服务器上的数据库文件导出

数据库备份
[root@nginx ~]# mysqldump -uroot -p --all-databases > `date +%F%H`-mysql-all.sql
Enter password:
[root@nginx ~]# ls
2020-06-2013-mysql.all.sql

(3)在新开启的mysql服务器上导入数据库文件

先把lnmp上产生的mysql文件传送到新开启的mysql服务器上
[root@nginx ~]# scp -r /root/2020-06-2013-mysql.all.sql root@192.168.229.140:/root进行数据的导入
[root@mysql ~]# mysql -uroot -p < 2020-06-2013-mysql.all.sql
Enter password:
[root@mysql ~]# systemctl restart mysqld

(4)在新mysql服务器上创建同名管理用户和密码

[root@mysql ~]# mysql -uroot -pasd123      #登录
mysql> grant all on blog.* to zj@'192.168.229.%' identified by 'asd123';
mysql> grant all on zh.* to li@'192.168.229.%' identified by 'asd123';
[root@mysql ~]# systemctl restart mysqld

(5)在原服务器上修改blog、zh的配置文件,重新指定数据库服务器IP
先查看blog的配置位置

[root@nginx ~]# cd /wordpress/
[root@nginx wordpress]# grep -r asd123
wp-config.php:define('DB_PASSWORD', 'asd123');
[root@nginx wordpress]# vim wp-config.php
主要把MySQL主机IP改为新的服务器IP
/** WordPress数据库的名称 */
define('DB_NAME', 'blog');/** MySQL数据库用户名 */
define('DB_USER', 'zj');/** MySQL数据库密码 */
define('DB_PASSWORD', 'asd123');/** MySQL主机 */
define('DB_HOST', '192.168.229.140');

先查看zh的配置文件位置

[root@nginx wordpress]# cd /zh
[root@nginx zh]# grep -r asd123
system/config/database.php:  'password' => 'asd123',
[root@nginx zh]# vim system/config/database.php'host' => '192.168.229.140',  #改为新MySQL主机IP'username' => 'li',  #MySQL数据库用户名'password' => 'asd123',  #MySQL数据库密码'dbname' => 'zh',  #zh数据库的名称

然后可以进行访问测试,在原服务器上查看访问日志成功迁移数据库。

[root@nginx zh]# tail /var/log/nginx/access.log

2、lnmp实现PHP的拆分

(1)再重新启动一台虚拟机,安装php

[root@localhost ~]#  systemctl stop firewalld
[root@localhost ~]#  setenforce 0
[root@localhost ~]#  hostname php
[root@localhost ~]# bash
[root@php ~]# yum -y install epel-release
[root@php ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

然后安装PHP

[root@php ~]# yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache

(2)修改nginx原服务器上的配置文件,重新指向新的php服务器(zh步骤相同)

[root@nginx ~]# vim /etc/nginx/conf.d/blog.conf
修改IP地址指向为新的PHP服务器IP地址
server {listen 80;server_name blog.benet.com;root /wordpress;index index.php index.html;location ~ \.php$ {root /wordpress;fastcgi_pass 192.168.229.141:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
[root@nginx ~]# vim /etc/nginx/conf.d/zh.conf
修改IP地址指向为新的PHP服务器IP地址
server {listen 80;server_name zh.benet.com;root /zh;index index.php index.html;location ~ \.php$ {root /zh;fastcgi_pass 192.168.229.141:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
[root@nginx ~]# systemctl restart nginx

(3)修改新的php服务器的配置文件

[root@nginx ~]# vim /etc/php-fpm.d/www.conf
定位并修改为:
listen = 192.168.229.141:9000  #新的PHP服务器IP
listen.allowed_clients = 192.168.229.142,192.168.229.134 #允许访问的web服务器
[root@nginx ~]# systemctl restart php-fpm

(4)从nginx服务器复制wordpress和zh的安装目录到新的php服务器

[root@nginx ~]# scp -rp /wordpress root@192.168.229.141:/
[root@nginx ~]# scp -rp /zh root@192.168.229.141:/

(5)客户端验证访问
客户端需要修改/etc/hosts文件进行域名解析

http://blog.benet.com
http://zh.benet.com

3、搭建NFS共享服务器

搭建nfs共享服务器,为了把网站静态元素通过挂载方式放在nfs上。
(1)重新开启一台虚拟机,安装nfs-utils、rpcbind

[root@node01 ~]# hostname nfs
[root@node01 ~]# bash
[root@nfs ~]# systemctl stop firewalld
[root@nfs ~]# setenforce 0
[root@nfs ~]# yum -y install nfs-utils rpcbind

(2)创建挂载点

[root@nfs ~]# mkdir -p /nfs/{blog,zh}

(3)发布共享目录

[root@nfs ~]# vim /etc/exports
添加:
/nfs/blog       192.168.229.0/24(rw,sync,no_root_squash)
/nfs/zh         192.168.229.0/24(rw,sync,no_root_squash)

(4)重启nfs服务

[root@nfs ~]# systemctl restart rpcbind
[root@nfs ~]# systemctl restart nfs

(5)在nginx服务器上查看nfs共享目录

[root@nginx ~]# showmount -e 192.168.229.139
Export list for 192.168.229.139:
/nfs/zh   192.168.229.0/24
/nfs/blog 192.168.229.0/24

(6)在nginx服务器上下载nfs工具并把wordpress的内容目录挂载到nfs

[root@nginx ~]# yum -y install nfs-utils rpcbind
[root@nginx ~]# cd /wordpress/
[root@nginx wordpress]# cp -rp wp-content/ wp-content.bak
[root@nginx wordpress]# mount -t nfs 192.168.229.139:/nfs/blog wp-content
[root@nginx wordpress]# cp -rp wp-content.bak/*  wp-content/
[root@nginx wordpress]# df -Th
文件系统                  类型      容量  已用  可用 已用% 挂载点
devtmpfs                  devtmpfs  470M     0  470M    0% /dev
tmpfs                     tmpfs     487M     0  487M    0% /dev/shm
tmpfs                     tmpfs     487M  8.1M  479M    2% /run
tmpfs                     tmpfs     487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   xfs        17G  5.2G   12G   31% /
/dev/sda1                 xfs      1014M  185M  830M   19% /boot
tmpfs                     tmpfs      98M     0   98M    0% /run/user/0
192.168.229.139:/nfs/blog nfs4       17G  1.7G   16G   10% /wordpress/wp-content

(7)设置永久挂载

[root@nginx ~]# vim /etc/fstab
添加:
192.168.229.139:/nfs/blog /wordpress/wp-content nfs defaults 0 0

4、搭建第二台web服务器

(1)重新开启一台虚拟机,安装nginx

[root@localhost ~]# hostname web2
[root@localhost ~]# bash
[root@web2 ~]# systemctl stop firewalld
[root@web2 ~]# setenforce 0
[root@web2 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@web2 ~]# yum -y install nginx

(2)把web1上的nginx的配置复制到web2

[root@nginx ~]# scp -rp /etc/nginx/*  root@192.168.229.143:/etc/nginx

(3)把web1上网页源码复制到web2

[root@nginx ~]# scp -rp /wordpress root@192.168.229.143:/
[root@nginx ~]# scp -rp /zh root@192.168.229.143:/

(4)启动服务

[root@web2 ~]# systemctl start nginx
[root@web2 ~]# systemctl enable nginx
5、搭建nginx代理和负载均衡

(1)重新开启一台虚拟机,安装nginx
代理和负载均衡的区别
代理负责把连接请求直接转发到后台某个web节点。
负载均衡负责把请求使用某种调度算法分散发布给后台所有web节点。
nginx代理

[root@localhost ~]# hostname lb
[root@localhost ~]# bash
[root@lb ~]# systemctl stop firewalld
[root@lb ~]# setenforce 0
[root@lb ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@lb ~]# yum -y install nginx
[root@lb ~]# systemctl start nginx
[root@lb ~]# systemctl enable nginx

(2)代理优化配置
1.第一种方法配置

[root@lb ~]# cd /etc/nginx/conf.d
[root@lb conf.d]# mv default.conf default.conf.bak
[root@lb ~]# vim /etc/nginx/conf.d/lb.conf
server {listen 80;server_name blog.benet.com;location / {proxy_pass     http://192.168.229.134;proxy_set_header Host $http_host;  #转发请求时,包含头部“HOST”信息proxy_set_header X-Real-IP $remote_addr;  #和下行一起,共同实现追踪客户端原ipproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_connect_timeout 30;  #代理和后端服务器连接超时时间proxy_send_timeout 60;  #后端服务器传回代理的超时时间proxy_read_timeout 60;  #代理等待后端服务器的响应时间proxy_buffering on;  #启用缓存,后端返回内容先缓存,再给客户端,收到多少转多少proxy_buffer_size 32k;  #代理缓存用户头信息的缓存区大小proxy_buffers 4 128k;  #缓存区的设置}
}
server {listen 80;server_name zh.benet.com;location / {proxy_pass      http://192.168.229.134;proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_connect_timeout 30;proxy_send_timeout 60;proxy_read_timeout 60;proxy_buffering on;proxy_buffer_size 32k;proxy_buffers 4 128k;}
}
[root@lb conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb conf.d]# systemctl restart nginx

2.第二种配置方法(推荐使用,服务器数量较多时,配置方便)

[root@lb nginx]# pwd
/etc/nginx
[root@lb nginx]# vim nginx_params
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;
[root@lb nginx]# vim conf.d/lb.conf
server {listen 80;server_name blog.benet.com;location / {proxy_pass      http://192.168.229.134;include         nginx_params;   #添加}
}
server {listen 80;server_name zh.benet.com;location / {proxy_pass      http://192.168.229.134;include         nginx_params;   #添加}
[root@lb conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb ~]# systemctl restart nginx

(3)客户端修改hosts文件指向lb1,测试访问

[root@client ~]# vim /etc/hosts

nginx负载均衡(Load Balance),简写LB
面对高并发web请求,使用各种调度算法(rr:轮询,wrr:加权轮询,lc最小连接数,wlc:加权最小连接数,ip_hash),分散转发到后台web群集节点,提高数据吞吐量,高容灾。
常见的LB:

软件:lvs  nginx   haproxy
硬件:F5
云LB:阿里云SLB    腾讯云CLB   青云QLB   ucloud ULB

四层负载:ip地址 tcp/udp 端口号
七层负载:HTTP https ftp SMTP
(1)修改lb1的配置文件,添加负载均衡功能

[root@lb ~]# vim /etc/nginx/conf.d/lb.conf
修改为:
upstream webcluster {server 192.168.229.144:80;server 192.168.229.143:80;
}server {listen 80;server_name blog.benet.com;location / {proxy_pass http://webcluster;include nginx_params;}
}
server {listen 80;server_name zh.benet.com;location / {proxy_pass http://webcluster;include nginx_params;}
}
[root@lb ~]# systemctl restart nginx

(2)客户端访问验证,浏览器如果判断不出来,就看web节点上的日志。
(3)nginx负载均衡后端状态
例子:

[root@lb ~]# vim /etc/nginx/conf.d/lb1.conf
修改为:upstream属于http字段
upstream web_cluster {server 192.168.229.143:80 max_fails=2 fails_timeout=10s max_conns=1;  server 192.168.229.144:80 down;  #一般用于停机维护
}

注意:参数不写会有默认值;
参数解释

down             当前节点服务器不参与负载均衡backup        备份服务器max_fails      允许请求失败的次数fails_timeout  经过max_fails失败后,服务的暂停时间max_conns       同一ip最大连接数
6.配置4层负载均衡,发布内部服务器的ssh和mysql

利用跳板机进行其他服务器的管理,达到免密登录的效果

[root@lb ~]# ssh-keygen
[root@lb ~]# ssh-copy-id 需要管理的IP
[root@lb ~]# ssh 需要管理的IP

4层负载均衡:端口映射

[root@lb ~]# vim /etc/nginx/nginx.conf
不属于http字段,所以插入数据到http字段上方:
stream {upstream sshweb1 {server 192.168.229.139:22;    #管理服务器的群集}upstream mysql {server 192.168.229.140:3306;    #管理数据库的群集}server {listen 5555;        #效果:远程登录只能通过5555端口连接proxy_pass sshweb1;proxy_connect_timeout 30;proxy_timeout 60;}server {listen 7777;       #效果:远程登录只能通过7777端口连接proxy_pass mysql;proxy_connect_timeout 30;proxy_timeout 60;}
}
[root@lb ~]# systemctl restart nginx

然后访问跳板机IP去登录到web服务器节点

[root@lb ~]# ssh root@192.168.229.145 -p 5555
connection established.
7.高可用-增加容错性(HA:High availability)

协议

VRRP(虚拟路由冗余协议) 公有协议  224.0.0.18
HSRP(热备份路由协议)   私有协议,Cisco公司

1.高可用软件
keepalived:使用vrrp实现多台主机高可用群集

2.高可用角色
master 主服务器
backup 备服务器

实施步骤
目的:实现两台负载均衡器的高可用
环境:两台负载均衡器
最小化安装需要安装psmisc

[root@localhost ~]# yum -y install psmisc

lb1:192.168.1.117
lb2:192.168.1.118
搭建另一台负载均衡器lb2
把第一台的yum源nginx文件传过来,配置文件/etc/nginx/*也传过来。两台配置一样。
(1)安装keepalived(两台都装)

[root@lb1 ~]# yum -y install keepalived
[root@lb2 ~]# yum -y install keepalived

(2)配置keepalived
主服务器:lb1

[root@lb1 ~]# vim /etc/keepalived/keepalived.conf
修改为:
global_defs {router_id lb1   #主服务器名
}vrrp_instance VI_1 {state MASTER   #主服务器interface ens33  #网卡名称virtual_router_id 51priority 100  #优先级0-255advert_int 1  #心跳线秒数authentication {   #认证标准auth_type PASSauth_pass 1111}virtual_ipaddress {    #虚拟IP地址,相当于一个飘移地址,必须是同网段。192.168.1.254}
}
[root@lb1 ~]# systemctl restart keepalived

备服务器:lb2
3倍心跳时间收不到master的通知包,backup就会变成master。

[root@lb2 ~]# vim /etc/keepalived/keepalived.conf
修改为:
global_defs {router_id lb2           #路由id号,和主服务器必须不同
}vrrp_instance VI_1 {state BACKUP         #状态:BACKUP备   MASTER主interface ens33virtual_router_id 51priority 99               #优先级:备比主要小advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.1.254      #虚拟路由ip,公共ip,必须和自己的网段相同。}
}
[root@lb2 ~]# systemctl restart keepalived

(3)查看虚拟ip(漂移ip地址)

[root@lb1 ~]# ip addr show dev ens33

(4)客户端修改hosts文件,访问验证(访问成功,关闭主服务器,再访问)

[root@client ~]# vim /etc/hosts
修改为:
192.168.1.254  blog.benet.com
192.168.1.254  zh.benet.com

3.高可用裂脑
高可用节点之间互相失去联系,自认为自己是主服务器,就会出现多主现象,即裂脑现象。
裂脑出现的原因:

(1)心跳线松动或网卡故障(2)服务器硬件故障,崩溃(3)节点服务器开启防火墙,却没有做vrrp例外(4)nginx服务死掉,不会出现裂脑现象,但整个集群都无法正常运作

(1)检测裂脑脚本(在备用服务器运行)

[root@lb2 ~]# vim split_brain.sh
#!/bin/bash
while true
do
ping -c 2 -W 3 192.168.1.117(主服务器IP) &> /dev/null
if [ $? -eq 0 -a `ip add | grep 192.168.1.254(飘移地址)|wc -l` -eq 1 ]thenecho "split brain....."
elseecho "HA is ok"
fi
sleep 5
done
[root@lb2 ~]# chmod +x split_brain.sh
[root@lb2 ~]# bash split_brain.sh

lb1和lb2开启防火墙验证:

[root@lb1 ~]# systemctl start firewalld
[root@lb2 ~]# systemctl start firewalld

出现裂脑现象,解决因为防火墙出现的裂脑现象:

[root@lb1 ~]# firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0  --destination 224.0.0.18 --protocol vrrp -j ACCEPT
[root@lb1 ~]# firewall-cmd --reload
[root@lb2 ~]# firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0  --destination 224.0.0.18 --protocol vrrp -j ACCEPT
[root@lb2 ~]# firewall-cmd --reload

脚本显示裂脑现象成功消除。
(2)解决nginx故障造成群集无法工作
编辑nginx监控脚本

[root@lb1 ~]# mkdir /sh
[root@lb1 ~]# vim /sh/check_nginx_proxy.sh
#!/bin/bash
killall -0 nginx
if  [ $? -ne 0 ];thensystemctl stop keepalived
fi
[root@lb1 ~]# chmod +x /sh/check_nginx_proxy.sh

添加脚本追踪模块到keepalived配置文件

[root@lb1 ~]# vim /etc/keepalived/keepalived.conf
global_defs {router_id lb1
}
vrrp_script check_nginx_proxy {script "/sh/check_nginx_proxy.sh"interval 2weight 5}
vrrp_instance VI_1 {state MASTERinterface ens33virtual_router_id 51priority 100advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.1.254}track_script {check_nginx_proxy}
}
[root@lb1 ~]# systemctl restart keepalived
8.nginx_ssl模块

SSL:安全套接字层,由Netscape公司于1994年创建,它旨在通过Web创建安全的Internet通信。
它是一种标准协议,用于加密浏览器和服务器之间的通信。它允许通过Internet安全轻松地传输账号密码、银行卡、手机号等私密信息。
SSL常见应用
https:启用ssl加密的安全HTTP传输协议 443端口
ipsec vpn
PKI:公钥基础设施,主要功能是绑定证书持有者的身份和相关的密钥对(通过为公钥及相关的用户身份信息签发数字证书),为用户提供方便的证书申请、证书作废、证书获取、证书状态查询的途径,并利用数字证书及相关的各种服务(证书发布,黑名单发布,时间戳服务等),实现通信中各实体的私钥(身份认证、完整性、抗抵赖性)和保密性(公钥)。
标准:x.509
CA:证书颁发机构
RA:证书注册机构
证书的内容

申请者的公钥
申请者的身份标识
证书有效期
颁发者的标识
颁发者的签名

HTTPS证书的选择

专业版OV型  不显示企业名
高级版EV型  显示企业名

HTTPS证书购买选择

单域名:仅能绑定一个域名
多域名:能绑定五个域名
通配符域名:不限个数

HTTPS注意事项

https仅支持二级域名
https不支持续费,证书到期重新申请替换
https显示绿色,说明整个网站都是https的
https显示黄色,网站代码中包含https不安全链接
https显示红色,证书不认或过期

企业内部实现https案例

生成key密钥
生成证书签名请求文件(csr文件)
生成证书签名文件(ca文件)

例子:在web1上操作
1.查看是否安装openssl和版本

[root@web1-152 ~]# rpm -q openssl
[root@web1-152 ~]# yum -y install openssl

2.查看nginx是否安装ssl模块

[root@web1-152 ~]# nginx -V
显示结果包含: --with-http_ssl_module

3.创建ssl密钥目录,并进入目录

[root@web1-152 ~]# mkdir -p /etc/nginx/ssh_key
[root@web1-152 ssh_key]# cd /etc/nginx/ssh_key

4.本机当CA:证书颁发机构,创建私钥

[root@web1-152 ssh_key]# openssl genrsa -idea -out server.key 2048

5.生成证书,去掉私钥的密码

[root@web1-152 ssh_key]# openssl req -days 3650 -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt

6.配置https网站

[root@web1-152 ssh_key]# vim /etc/nginx/conf.d/https.conf
server {listen 443 ssl;server_name https.benet.com;ssl_certificate ssh_key/server.crt;ssl_certificate_key ssh_key/server.key;location / {root /httpsweb;index index.html;}
}
[root@web1-152 ssh_key]# mkdir /httpsweb
[root@web1-152 ssh_key]# echo "<h1>https.benet.com</h1>" > /httpsweb/index.html
[root@web1-152 ssh_key]# systemctl restart nginx

7.客户机修改hosts文件,使用https://https.benet.com访问测试。

[root@web1-152 ~]# vim /etc/hosts
192.168.229.152 https.benet.com

8.rewrite地址重写(http重定向到https)

[root@web1-152 ~]# vim /etc/nginx/conf.d/https.conf
server {listen 443 ssl;server_name https.benet.com;ssl_certificate ssh_key/server.crt;ssl_certificate_key ssh_key/server.key;location / {root /httpsweb;index index.html;}
}
server {listen 80;server_name https.benet.com;rewrite .* https://https.benet.com;rewrite .* https://$host$request_uri redirect;rewrite .* https://$server_name$request_uri redirect;rewrite .* https://$server_name$1 redirect;
}

9.配置负载均衡https

[root@lb1 ~]# vim /etc/nginx/conf.d/lb_https.conf
upstream webhttps {server 192.168.229.152:443;server 192.168.229.155:443;
}server {listen 443 ssl;server_name https.benet.com;ssl_certificate ssh_key/server.crt;ssl_certificate_key ssh_key/server.key;location / {proxy_pass https://webhttps;include nginx_params;}
}
server {listen 80;server_name https.benet.com;return 302 https://$server_name$1;
}

10.模拟案例:配置https的blog、zh(web2和web1配置相同)
(1)配置web1的blog

[root@web1-152 ~]# vim /etc/nginx/conf.d/blog.conf
server {listen 443 ssl;server_name blog.benet.com;ssl_certificate ssh_key/server.crt;ssl_certificate_key ssh_key/server.key;root /wordpress;index index.php index.html;location ~ \.php$ {root /wordpress;fastcgi_pass 192.168.229.157:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
server {listen 80;server_name blog.benet.com;rewrite .* https://blog.benet.com;rewrite .* https://$host$request_uri redirect;rewrite .* https://$server_name$request_uri redirect;rewrite .* https://$server_name$1 redirect;
}

(2)配置web1的zh

[root@web1-152 ~]# vim /etc/nginx/conf.d/zh.conf
server {listen 443 ssl;server_name zh.benet.com;ssl_certificate ssh_key/server.crt;ssl_certificate_key ssh_key/server.key;root /zh;index index.php index.html;location ~ \.php$ {root /zh;fastcgi_pass 192.168.229.157:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
server {listen 80;server_name zh.benet.com;rewrite .* https://zh.benet.com;rewrite .* https://$host$request_uri redirect;rewrite .* https://$server_name$request_uri redirect;rewrite .* https://$server_name$1 redirect;
}
[root@web1-152 ~]# nginx -t
[root@web1-152 ~]# systemctl restart nginx

直接把web1的配置传到web2上

[root@web1-152 ~]# scp -rp /etc/nginx/ssh_key root@192.168.229.155:/etc/nginx
[root@web1-152 ~]# scp -rp /etc/nginx/conf.d/blog.conf root@192.168.229.155:/etc/nginx/conf.d/
[root@web1-152 ~]# scp -rp /etc/nginx/conf.d/zh.conf root@192.168.229.155:/etc/nginx/conf.d/

(3)配置负载均衡lb1,lb2配置一样
首先把证书传到lb1上

[root@web1-152 ~]# scp -rp /etc/nginx/ssh_key/ root@192.168.229.158:/etc/nginx/
[root@lb1 ~]# vim /etc/nginx/conf.d/lb.conf
upstream web_cluster {server 192.168.229.152:443;server 192.168.229.155:443;
}server {listen 443 ssl;server_name blog.benet.com;ssl_certificate ssl_key/server.crt;ssl_certificate_key ssl_key/server.key;location / {proxy_pass https://web_cluster;include nginx_params;}
}
server {listen 443 ssl;server_name zh.benet.com;ssl_certificate ssl_key/server.crt;ssl_certificate_key ssl_key/server.key;location / {proxy_pass https://web_cluster;include nginx_params;}
}
server {listen 80;server_name blog.benet.com;return 302 https://$server_name$1;
}
server {listen 80;server_name zh.benet.com;return 302 https://$server_name$1;
}
[root@lb1 ~]# nginx -t
[root@lb1 ~]# systemctl restart nginx

关于lb2的配置,直接把lb1的配置传过去即可。

[root@lb1 ~]# scp -rp /etc/nginx/ssh_key/ root@192.168.229.158:/etc/nginx/
[root@lb1 ~]# scp -rp /etc/nginx/conf.d/lb.conf root@192.168.229.159:/etc/nginx/conf.d/

lnmp分离网站基础架构相关推荐

  1. 企业实战案例-- LNMP基础架构的原理及部署以及wordpress论坛的安装

    企业实战案例-- LNMP基础架构的原理及部署以及wordpress论坛的安装 LNMP架构原理 一.源码安装mysql 二.源码安装php 三.源码安装nginx 四.安装wordpress论坛 L ...

  2. 部署LNMP动态网站及网站架构变迁

    1:网站架构演变 学习从单机架构到集群架构的演变之路: 单机版LNMP 独立数据库服务器 Web服务器集群与Session保持 动静分离.数据库集群 各种缓存服务器 业务模型 单机版LNMP 单机版网 ...

  3. 11.LNMP基础架构

    [toc] LNMP基础架构 12.1 LNMP架构介绍 架构原理: LAMP=linux+apache+mysql+php LNMP=linux+nginx+mysql+php 1.初识LNMP 当 ...

  4. 大型商业网站的基础架构解析

    今天在西部在线群里碰到一个玩笑争论,就是人工进行大数据量更新的问题.刚好也在考虑高并发量大型商业网站的技术和运营架构,暂且将一些思路写下来,提醒自己,顺便抛砖引玉了.有些数据,为了更形象的说明问题,在 ...

  5. 小白入门:大型网站技术架构负载均衡技术介绍及学习资源推荐

    十年间,负载均衡的前沿技术层出不穷,令用户眼花缭乱.经常在技术网站.文档中出现的"四层负载均衡"."七层负载均衡"字眼有什么含义?有什么区别?对客户网络有哪些不 ...

  6. 《大型网站技术架构:核心原理及案例分析》阅读笔记01

    第一篇:概述   1.大型网站架构演化 从上世纪90年代初,Web标准和Web服务出现来计算,互联网发展了仅仅20年,但是,它的发展速度却是惊人的,世界被互联网改变着.随着互联网的发展,越来越多的问题 ...

  7. 阿里P9架构师讲解从单机至亿级流量大型网站系统架构的演进过程

    阶段一.单机构建网站 网站的初期,我们经常会在单机上跑我们所有的程序和软件.此时我们使用一个容器,如tomcat.jetty.jboos,然后直接使用JSP/servlet技术,或者使用一些开源的框架 ...

  8. 大型网站技术架构:摘要与读书笔记

    花了几个晚上看完了<大型网站技术架构>(https://book.douban.com/subject/25723064/)这本书,个人感觉这本书的广度还行,深度还有些欠缺(毕竟只有200 ...

  9. 高并发高负载的大型网站系统架构

    2019独角兽企业重金招聘Python工程师标准>>> 一个小型的网站,比如个人网站,可以使用最简单的html静态页面就实现了,配合一些图片达到美化效果,所有的页面均存放在一个目录下 ...

最新文章

  1. gitter 卸载_最佳Gitter频道:VR和AR
  2. Java基础学习总结(31)——Java思维导图
  3. php配置默认index.php,Apache的vhost中配置默认访问入口index-test.php的方法(Yii)
  4. 机器学习算法基础——k近邻算法
  5. Idea Debug调试介绍
  6. IPropertySet接口
  7. 1017 The Best Peak Shape (35 分)(最佳峰形)(思路+详解+翻译+题意分析)Come brather!!!!!!!!!
  8. 运行时的Java 8参数名称
  9. 数字时钟html5 js,html5 canvas js(数字时钟)实例代码
  10. PHP中两种包含文件方式、三种注释风格、四种标记风格
  11. MATLAB 三路频分复用通信系统
  12. leetcode-231-Power of Two
  13. Macbook Pro休眠唤醒后后台运行程序被关闭的解决方法
  14. Hadoop在业界的使用情况
  15. 30个值得推荐的数据可视化工具--转
  16. 解决IE浏览器jQuery执行ajax不响应问题
  17. 中性粒细胞的免疫应用最新研究进展
  18. matlab qpsk调试 rls均衡,通信系统仿真速成第2天:QPSK调制与解调(实验)
  19. 课下作业(选做)第八周
  20. 魅族手机安装Google Play

热门文章

  1. docker(七)容器与外部通信
  2. apache服务器安装以及使用passenger插件部署rails应用,基于ubuntu 12.04 LTS
  3. 阿里云服务器上搭建宝塔
  4. PaddleHub一键识别动物 : resnet50_vd_animals
  5. ffmpeg js转换音频_linux下使用ffmpeg将amr转成mp3
  6. c++用贪心算法解决汽车加油问题
  7. 加油站问题的题解与分析——循环队列+合并
  8. JS面试题汇总(八)
  9. 天黑请闭眼,我这次还能抽到杀手吗
  10. web前端数据表格有合并项的一种简单实现方法