搭建两台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,外网)
[*]搭建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 ;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 -ybind bind-utils elif [ $ID = 'ubuntu' ];then color "不支持Ubuntu操作系统,退出!" 1 exit #apt update #apt install -ybind9 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
页:
[1]