实验目的:模拟生产环境clb 云平台负载均衡 后端web服务器,nfs共享存储,若没有clb,也可以keeplived-nginx vip方式完成搭建
这个实验省略了redis mysql 等真实生产环境。同理可以使用云平台mysql,redis产品即可,或者自建高可用中间件集群
集群角色 | 系统配置 |
---|---|
192.168.26.130 (clb)nginx代替 | centos7.6 2c2g |
192.168.26.130 web服务器-nfs服务端 | centos7.6 2c1g |
192.168.26.130 web服务器-nfs客户端 | centos7.6 2c1g |
首相我们安装nginx 3个环境执行
省略环境配置
主机名修改以及hostname修改
yum -y install nginx
两台web服务器上操作
web服务器搭建nfs共享存储
web1nfs-服务端
yum install nfs-utils rpcbind -y
mkdir /data ##创建共享目录
vim /etc/exports ##配置nfs server端
/data 192.168.26.120(rw,no_root_squash)
##nfs配置规则可以百度 建议生产中指定ip段
##设置开机自启
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
exportfs -r 重读配置文件
web2-nfs-客户端操作
yum install -y nfs-utils
showmount -e 192.168.26.100 ##执行查看nfs服务端得共享情况 ip记得替换
输出结果正常
Export list for 192.168.26.100:
/data 192.168.26.120
创建本地共享文件夹
mkdir /data
mount -t nfs 192.168.26.100:/data/ /data/ ##挂载共享目录文件夹
开启开机自动挂载
vim /etc/fstab
...
##加入此行
192.168.26.100:/data /data nfs defaults 0 0
df -h ##查看是否挂载成功
两台web服务器同时操作
修改nginx.conf主页目录为nfs路径
...
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /data; ##主页路径修改成nfs目录
index index.html index.htm;
}
设置一个主页
echo haitao01! > /data/index/html
启动nginx
nginx -t ##检测conf是否正确
nginx -s reload ##重读配置文件
验证
[root@web2_nfs2 conf]# curl 192.168.26.100
haitao01!
测试nfs效果
任何一台web服务器修改主页index.html看是否生效
echo haitao > /data/index.html
验证
[root@web2_nfs2 conf]# curl 192.168.26.120
haitao
[root@web2_nfs2 conf]# curl 192.168.26.100
haitao
web服务器配置完成
下面开出配置clb负载均衡器
这里我就用另外一台nginx来代替
vim nginx.conf
需要修改得部分配置
...
http {
include mime.types;
default_type application/octet-stream;
upstream test-web { ##配置负载均衡
server 192.168.26.100:80;
server 192.168.26.120:80;
}
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://test-web; ##和上面得负载均衡关联
root html;
index index.html index.htm;
}
...
验证
[root@slb_nginx nginx]# curl 192.168.26.130
haitao01!
[root@slb_nginx nginx]# curl 192.168.26.130
haitao01!