centos 7部署Haproxy+Nginx+NFS

 

目录

1.1部署前准备:

1.2nginx安装

 1.3编译安装haproxy

 1.4安装NFS

 实验结束


1.1部署前准备:

实验要求:

使用四台centos7虚拟机

haproxy:192.168.83.128

nginx(1):192.168.83.137

nginx(2):192.168.83.138

nfs:192.168.83.139

 关闭防火墙

systemctl stop firewalld.service             //临时关闭
systemctl disable firewalld.service          //永久关闭

关闭selinux

临时关闭:setenforce 0

永久关闭(需要重启才生效):vi /etc/selinux/config                              进入目录

                  SELINUX=disabled                                修改配置文件

 nginx压缩包:提取码:owx9

haproxy压缩包:提取码:021h

1.2nginx安装

yum -y install  gcc gcc-c++ autoconf automake libtool make openssl openssl-devel pcre pcre-devel   依赖包安装

cd  /usr/local/src/     切换安装路径

上传安装包到此目录下

 tar -zxvf nginx-1.8.1.tar.gz   解压安装包



cd  nginx-1.8.1         打开解压出来的目录


./configure 
--prefix=/usr/local/nginx 
--with-http_ssl_module 
--with-http_flv_module 
--with-http_stub_status_module 
--with-http_gzip_static_module 
--with-pcre                     编译命令

make && make install  安装

测试
/usr/local/nginx/sbin/nginx -t

启动服务
/usr/local/nginx/sbin/nginx

重新载入配置文件
/usr/local/nginx/sbin/nginx  -s reload

重启服务
/usr/local/nginx/sbin/nginx  -s reopen

停止服务
/usr/local/nginx/sbin/nginx  -s stop

测试nginx

 按照nginx1安装nginx2

测试nginx2

 1.3编译安装haproxy

上传安装包到/etc/src目录下

tar zxf haproxy-1.5.19.tar.gz  解压安装包

cd /usr/src/haproxy-1.5.19/    进入解压后的目录

make TARGET=linux26 && make install      编译安装

建立haproxy配置文件

cd ~
mkdir /etc/haproxy   返回家目录创建配置文件目录

cd /usr/src/haproxy-1.5.19/

cp examples/haproxy.cfg /etc/haproxy/    将haproxy.cfg文件复制到配置文件目录

Haproxy配置项介绍

 根据实验要求,haproxy.cfg配置文件修改如下(注意节点IP要改为nginx服务器的

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.83.137:80 check inter 2000 fall 3
        server  inst2   192.168.83.138:80 check inter 2000 fall 3

创建自启动脚本

[root@localhost ~]# cd /usr/src/haproxy-1.5.19/
[root@localhost haproxy-1.5.19]# cp examples/haproxy.init /etc/init.d/haproxy
[root@localhost haproxy-1.5.19]# ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
[root@localhost haproxy-1.5.19]# chmod +x /etc/init.d/haproxy 
[root@localhost haproxy-1.5.19]# chkconfig --add /etc/init.d/haproxy 
[root@localhost haproxy-1.5.19]# /etc/init.d/haproxy start
Starting haproxy (via systemctl):                          [  OK  ]
[root@localhost ~]# systemctl stop firewalld

测试:

使用浏览器输入haproxy服务器的IP,显示出nginx1的页面,刷新几次显示出nginx2的页面就成功了。

 

 

开启haproxy监控页面

编辑haproxy.cfg,加入如下参数

 listen 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

浏览器访问http://ip:8080/admin

用户名:admin       密码:admin

 1.4安装NFS

yum -y install nfs-utils           yum安装

ss -tnulp | grep 111      查看rpc服务是否自动启动,如果没有启动,就systemctl start rpcbind 启动rpc服务。

rpm -qa nfs-utils            查看是否安装成功

vim /etc/exports
/data    192.168.1.0/24(rw,async)       编辑/etc/exports,添加此内容

systemctl start nfs          启动nfs服务

rpcinfo -p 192.168.83.139     查看

使用    ss -tnulp | grep 111命令

 使用rpcinfo -p 192.168.83.139查看,如图所示

 使用showmount -e localhost    如下

 创建/data目录添加文件,更改权限(很重要!!!!!

mkdir /data 
touch /data/index.html                      创建目录data和index.html文件

echo "hello nfs" >> /data/index.html        输入“hello nfs”内容到文件中

chown -R nfsnobody.nfsnobody /data          给/data目录权限

两台nginx服务器安装nfs

yum -y install nfs-utils

检测rpc是否启动

使用showmount -e 192.168.83.139查看

挂载至本地/mnt目录

mount -t nfs 192.168.83.139:/data /mnt 

 

 修改两台nginx服务器的配置文件,将访问页面路径修改为挂载路径,如下图

vim /usr/local/nginx/conf/nginx.conf

 

 修改完成,重新载入配置文件

/usr/local/nginx/sbin/nginx  -s reload

 

 在nfs服务器中执行,让nfs,rpcbind开机自动启

systemctl enable nfs-server.server

systemctl enable rpcbind

测试,输入haproxy服务器IP显示如下图,多刷新几次不变就是成功了。

 

 实验结束

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

)">
< <上一篇
https://forum.starrocks.com/t/topic/552下面我们以从StarRocks)">
下一篇>>