Haproxy开源负载均衡部署

第一步环境准备:

systemctl stop firewalld 

setenforce 0 

systemctl disable firewalld.service   #设置开机不启动防火墙

sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux   #设置开机不启动防火墙

iptables -F

centos7服务器    haproxy      192.168.1.107

centos7服务器    nginx(1)              192.168.1.109

centos7服务器    nginx  (2)          192.168.1.110

centos7服务器    nfs+rps         192.168.1.108

第二步:部署haproxy服务器

yum install haproxy -y  #yum安装haproxy


vim   /etc/haproxy/haproxy.cfg        #替换haproxy的配置文件82行为nginx1的ip
vim  /etc/haproxy/haproxy.cfg        #替换haproxy的配置文件83行为nginx2的ip
vim    /etc/haproxy/haproxy.cfg                     #将haproxy的默认5000端口改为80端口

在/etc/haproxy/haproxy.cfg 配置文件中添加以下内容
listen admin_stats         #设置haproxy的web管理用户
stats enable                 #开启haproxy程序web服务
bind *:8080                    #haproxy管理页面端口为8080
mode http                     #以下为haproxy系统配置
option httplog         #开启 HTTP 日志记录功能,记录 HTTP 请求和响应的详细信息。
log global                #开启全局日志记录功能,记录 HAProxy 的运行状态和事件。
maxconn 10         #设置每个后端服务器的最大连接数为 10。
stats refresh 30s         #设置统计页面的刷新时间为 30 秒。
stats uri /admin                #设置统计页面的 URL 为 /admin。
stats realm haproxy        #设置统计页面的认证域为 haproxy。
stats auth admin:admin        #设置统计页面的认证用户名和密码为 admin 和 admin。
stats hide-version                 #隐藏 HAProxy 的版本信息,增强安全性。
stats admin if TRUE              #以上为haproxy系统配置

systemctl start haproxy.service                                     #开启haproxy程序


第三步配置nfs+rpc

 yum install nfs-utils rpcbind -y  #yum安装nfs和rpc服务
mkdir -p /app/file               #创建nfc共享文件目录
chown -R nfsnobody.nfsnobody   /app/file/  #赋予共享目录nfs权限
vim /etc/exports   在配置文件中写入共享目录及参数  /app/file    *(rw,sync) #允许所有IP访问nfs共享目录并有可读写权限
exportfs –rv                               #载入配置
systemctl enable nfs                        #开机自启动nfs
systemctl enable rpcbind                    #开机自启动rps
systemctl start nfs                         #启动nfs程序
systemctl start rpcbind                     #启动rps程序
touch /app/file/index.html                  #在共享目录下创建网页文件
echo "<h1>999vip</h1>" >> /app/file/index.html #在网页文件中写入要显示的数据

部署完成

第四步部署nginx(1)  #ningx(2)的部署和nginx(1)相同  同步一样操作

 yum -y install  gcc gcc-c++ autoconf automake libtool make openssl openssl-devel pcre pcre-devel     #安装nginx所需环境
cd  /usr/local/src/                                                                              #切换到安装目录
wget  http://nginx.org/download/nginx-1.8.1.tar.gz                                               #下载nginx到当前目录
tar -zxvf nginx-1.8.1.tar.gz                                                                     #解压nginx安装包
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                                                                             #编译安装
cd  /usr/local/nginx                                                                             #进入nginx安装目录

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

yum install nfs-utils rpcbind  -y                                                                #安装nfs和rpc服务
systemctl enable nfs                                                                             #开机自启动nfs服务
systemctl enable rpcbind                                                                         #开机自启动rps服务
systemctl start nfs                                                                              #启动nfs服务
systemctl start rpcbind                                                                          #启动rpc服务


mount -t nfs 192.168.1.108:/app/file /usr/local/nginx/html/                                                 #挂载nfs上的目录到nginx的html目录下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值