centos 7 部署haproxy+nginx+nfs服务

本次实验要求:

操作系统 主机名 IP地址
centos 7 haproxy 192.168.50.251
centos 7 nginx 1 192.168.50.241
centos 7 nginx 2 192.168.50.140
centos 7 nfs 192.168.50.182

 四台centos 7必须关闭防火墙:

systemctl stop firewalld                   #关闭防火墙

setenforce 0                               #零时关闭防火墙

1.安装nginx服务器

 1.部署nginx 1环境  

yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel           #安装工具和库

wget -c https:"//nginx.org/download/nginx-1.18.0.tar.gz"                              #下载1.18.0.tar.gz的包

tar -zxvf nginx-1.18.0.tar.gz                                                        #解压1.18.0.tar.gz的包

cd nginx-1.18.0
                                                                           #进入nginx目
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-http_gzip_static_module --with-pcre                          #编译与安装nginx

make install

cd /usr/local/nginx/sbin /nginx                                                        #进入到安装nginx目录下面的sbin

./nginx                          	                                                  #启动

2.部署nginx 2环境

yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel           #安装工具和库

wget -c https:"//nginx.org/download/nginx-1.18.0.tar.gz"                              #下载1.18.0.tar.gz的包

tar -zxvf nginx-1.18.0.tar.gz                                                        #解压1.18.0.tar.gz的包

cd nginx-1.18.0
                                                                           #进入nginx目
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-http_gzip_static_module --with-pcre                          #编译与安装nginx

make install

cd /usr/local/nginx/sbin /nginx                                                        #进入到安装nginx目录下面的sbin

./nginx                          	                                                  #.启动

浏览器测试nginx1结果

 浏览器测试nginx2结果

 2.部署haproxy服务

1.编译安装haproxy

yum -y install pcre-devel bzip2-devel           #安装

rz 上传haproxy-1.5.19.tar.gz                    #上传haproxy-1.5.19.tar.gz

tar zxf haproxy-1.5.19.tar.gz -C /usr/src/      #解压haproxy-1.5.19.tar.gz

cd /usr/src/haproxy-1.5.19/                     #进入cd /usr/src/haproxy-1.5.19/

make TARGET=linux26 && make install             #安装make install

2.部署haproxy和haproxy监控界面配置文件

mkdir /etc/haproxy                                #创建配置文件

cd /usr/src/haproxy-1.5.19/                       #进入cd /usr/src/haproxy-1.5.19/

cd /etc/haproxy/                                  #进入cd /etc/haproxy/目录
vim haproxy.cfg                                   #进入haproxy.cfg编辑

haproxy.cfg配置文件内容如下:


global
        log /dev/log    local0 info
        log /dev/log    local0 notice
        #log loghost    local0 info
        maxconn 4096
        #chroot /usr/share/haproxy
        uid 99
        gid 99
        daemon
        #debug
        #quiet
 
defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000
listen  webserver 0.0.0.0:80
        option httpchk GET /index.html
        balance roundrobin
        server  inst1   192.168.50.241:80 check inter 2000 fall 3
        server  inst2   192.168.50.140:80 check inter 2000 fall 3

isten admin_stats
        stats   enable
        bind    *:8080    #监听的ip端口号
        mode    http    #开关
        option  httplog
        log     global
        maxconn 10
        stats   refresh 30s   #统计页面自动刷新时间
        stats   uri /admin    #访问的uri ip:8080/admin
        stats   realm haproxy
        stats   auth admin:admin  #认证用户名和密码
        stats   hide-version   #隐藏HAProxy的版本号
        stats   admin if TRUE   #管理界面,如果认证成功了,可通过webui管理节点
重起haproxy:service haproxy restart

3.创建启动脚本

cd /usr/src/haproxy-1.5.19/                 #进入cd /usr/src/haproxy-1.5.19/

cp examples/haproxy.init /etc/init.d/haproxy

ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy

chmod +x /etc/init.d/haproxy

/etc/init.d/haproxy start                    #启动haproxy
Starting haproxy (via systemctl):                          [  OK  ]   #启动成功
 

浏览器测试:19.2168.50.251  多点两下会切换到nginx222

 

监控界面测试: 192.168.50.251:8080/admin      用户名:admin     密码:admin

3.部署nfs服务器 

1.服务器端配置

1.服务器配置

yum -y install rpcbind nfs-utils                     #安装

ss -tnulp | grep 111                                 #查看rpc服务是否自动启动

vim /etc/exports                                     #进入编辑内容
/data    192.168.50.0/24(rw,async)
  
systemctl start nfs                                  #启动nfs

systemctl start rpcbind                              #启动rpcbind

showmount -e localhost                               #查看IP
Export list for localhost:
/dijia/html 192.168.50.0/24

chmod 755 -R /dijia/html                             #给加入权限

mkdir -p /dijia/html                                 #创建/dijia/htmlmu和文件

cd /dijia/html                                       #切换到/dijia/html

touch index.html                                     #创建文件index.html
vim index.html                                       #进入编辑内容
kekeaiaimeiyounaodai

2.客户端配置    我是直接用了一台nginx来当客户端是不会有影响的

showmount -e 192.168.50.182                      #查看IP

mkdir /mnt/html                                  #创建目录/mnt/html  这是要挂载的目录 

mount -t nfs 192.168.50.182:/dijia/html /mnt/html  #挂载到/mnt/html目录

cd /usr/local/nginx                              #进入cd /usr/local/nginx

ll                                               #查看

cd conf                                          #进入cd conf

ll                                               #查看

vim nginx.conf           #找到nginx.conf文件进行编辑  需要需改两处
root   /html;            #修改成:root  /mnt/html;
root   /html;            #修改成:root  /mnt/html;

/usr/local/nginx/sbin/nginx -s reload         #重启配置文件
      

浏览器测试:192.168.50.251  多刷新几下

本次实验就验证成功了 

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇

)">
下一篇>>