搭建两台web服务器基于HAProxy实现负载均衡
|
环境:
- DNS服务器:192.168.10.200 仅主机模式
- internet服务器:192.168.10.123 仅主机模式
- web1:10.0.0.100 (安装apache2)NAT模式
- web2:10.0.0.18 (安装httpd) NAT模式
- HAProxy服务器:10.0.0.8(配备两块网卡,eth0NAT模式,属于内网;eth1 仅主机模式192.168.10.129,外网)
[code][root@dns ~]$ cat install_dns.sh #!/bin/bash##***********************************************************#Author: yanli#Date: 2022-10-25#FileName: install_dns.sh#Description: #***********************************************************DOMAIN=yanlinux.orgHOST=wwwHOST_IP=192.168.10.129CPUS=`lscpu |awk '/^CPU\(s\)/{print $2}'`. /etc/os-releasecolor () { RES_COL=60 MOVE_TO_COL="echo -en \\033[${RES_COL}G" SETCOLOR_SUCCESS="echo -en \\033[1;32m" SETCOLOR_FAILURE="echo -en \\033[1;31m" SETCOLOR_WARNING="echo -en \\033[1;33m" SETCOLOR_NORMAL="echo -en \E[0m" echo -n "$1" && $MOVE_TO_COL echo -n "[" if [ $2 = "success" -o $2 = "0" ] ;then ${SETCOLOR_SUCCESS} echo -n $" OK " elif [ $2 = "failure" -o $2 = "1" ] ;then ${SETCOLOR_FAILURE} echo -n $"FAILED" else ${SETCOLOR_WARNING} echo -n $"WARNING" fi ${SETCOLOR_NORMAL} echo -n "]" echo }install_dns () { if [ $ID = 'centos' -o $ID = 'rocky' ];then yum install -y bind bind-utils elif [ $ID = 'ubuntu' ];then color "不支持Ubuntu操作系统,退出!" 1 exit #apt update #apt install -y bind9 bind9-utils else color "不支持此操作系统,退出!" 1 exit fi }config_dns () { sed -i -e '/listen-on/s/127.0.0.1/localhost/' -e '/allow-query/s/localhost/any/' /etc/named.conf cat >> /etc/named.rfc1912.zones /dev/null [ -d /var/lib/haproxy/ ] || mkdir -p /var/lib/haproxy &> /dev/null #准备配置文件 cat > /etc/haproxy/haproxy.cfg |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|
|
|
发表于 2023-3-3 00:38:58
举报
回复
分享
|
|
|
|