春风十里不如你 —— Taozi - 实践 https://www.xiongan.host/index.php/tag/%E5%AE%9E%E8%B7%B5/ 【Packmaker】集群部署实践+测试 https://www.xiongan.host/index.php/archives/86/ 2022-10-19T08:13:00+08:00 主机名ip角色Node01192.168.123.23节点1Node02192.168.123.123节点2首先安装pssh远程服务yum install -y pssh两台虚拟机都需要编辑hosts文件分别写入node01、node02的ip 和主机名生成免密登录,就可以无需密码直接登陆node01和node02ssh-keygen -t rsassh-copy-id -i /root/.ssh/id_rsa.pub root@node02-tzNode02端也需要进行相同操作之后安装pacemaker服务并设置开机自启pssh -h host-list.txt -i 'yum install pacemaker pcs -y'pssh -h host-list.txt -i 'systemctl enable --now pcsd'配置 Pacemaker Cluster:设置cluster的账号密码pssh -h host-list.txt -i 'echo 123456 | passwd --stdin hacluster'设置防火墙:pssh -h host-list.txt -i 'firewall-cmd --add-service=high-availability --permanent'添加服务pssh -h host-list.txt -i 'firewall-cmd --reload'加载防火墙建立 Cluster 授权:pcs cluster auth node01-tz node02-tz配置 Cluster(集群名称为:tz-cluster):pcs cluster setup --name tz-cluster node01-tz node02-tz启动 Cluster:pcs cluster start –all使 Cluster 随机启动:pcs cluster enable --all验证集群状态:pcs status cluster添加集群资源:两台节点需要安装httpd服务,不需要启动pssh -h host-list.txt -i 'yum install httpd -y'两台服务器都需要编辑一个新的配置文件vim /etc/httpd/conf.d/server_status.confExtendedStatus On <Location /server-status> SetHandler server-status Require local </Location> 并写入一个测试页面到/var/www/html/index.html配置 Cluster 并设定 VIP:[root@node01-tz ~]# pcs property set stonith-enabled=false <==关闭 stonith 功能[root@node01-tz ~]# pcs property set no-quorum policy=ignore <==忽略仲裁[root@node01-tz ~]# pcs property set default-resource-stickiness="INFINITY" <==设置资源超 时时间[root@node01-tz ~]# pcs property list<==显示设定pcs resource create VIP ocf:heartbeat:IPaddr2 ip=192.168.123.111 cidr_netmask=24 op monitor interval=30s <==设定 VIP pcs status resources <==显示资源信息 添加 httpd 资源: pcs resource create Web123-Cluster ocf:heartbeat:apache configfile=/etc/httpd/conf/httpd.conf statusurl="http://127.0.0.1/server-status" op monitor interval=1min[root@node01-tz ~]# pcs constraint colocation add Web123-Cluster with VIP INFINITY[root@node01-tz ~]# pcs constraint order VIP then Web123-Cluster <==设定启动顺讯:先启动 VIP 在启动 WEB123-Clusterpcs constraint <==显示资源情况客户端测试:停止 ndoe1 节点的 httpd 资源,客户端再测试:pcs cluster stop node01-tz就自动切换到了node02上使用 WEB GUI 管理 PaceMakerfirewall-cmd --add-port=2224/tcp --permanentfirewall-cmd --reload访问https://192.168.123.111:2224注:①80端口占用查询:netstat -tlnp|grep 80杀死已经存在的80端口服务Kill -9 进程号firewall-cmd --zone=public--add-port=80/tcp --permanent ###添加80端口Firewall-cmd --reload ###重载防火墙②ssh密钥生成信息只能存在一个,需要手动添加到本机与对方的auth开头文件和konw文件中>>>>>/root/.ssh/ 【Ha-proxy】负载均衡配置实践记录 https://www.xiongan.host/index.php/archives/55/ 2022-10-15T12:18:00+08:00 ha-proxy概述ha-proxy是一款高性能的负载均衡软件。因为其专注于负载均衡这一些事情,因此与nginx比起来在负载均衡这件事情上做的更好,更专业。准备Proxy端需要安装openssl openssl-lib haproxyWeb01和02 只需要安装httpd即可Proxy端:先备份配置文件mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak然后进行设置新的配置vim /etc/haproxy/haproxy.cfgglobal <== 全局配置log 127.0.0.1 local2 info <==定义收集的日志信息及日志设备 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 256 <==最大连接数 user haproxy <==定义 haproxy 的属主 group haproxy <==定义 harpoxy 属组 daemon stats socket /var/lib/haproxy/stats defaultsmode http <==定义运行模式为 http--Layer7 工作模式 log global option httplog <==获取 http 的 request 日志 timeout connect 10s <==后台服务超时时间 timeout client 30s <==客户端超时时间 timeout server 30s <==Server 超时时间 frontend http-in <==定义前台服务名称为 http-inbind *:80 <==定义 http-in 所监听的端口 default_backend backend_servers <==定义后台服务名称 option forwardfor <==发送 X-Forwarded-For 头部信息 backend backend_servers <==定义后台服务名称为 backend_serverbalance roundrobin <==定义负载均衡算法为 roundrobin server web01.tao.com 192.168.1.24:80 check <==定义负载均衡算法为 roundrobin server web02.tao.com 192.168.23.25:80 check <==定义负载均衡算法为 roundrobin保存重启haproxy并且关闭selinux :setenforce 0查看服务端口的使用情况,并放行端口web01、web02端:修改httpd.confvim /etc/httpd/conf/httpd.conf //* 修改 196 行,如下面内容LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined保存后退出测试:访问haproxy端的地址关闭web01的httpd,就只显示web02的信息了再次打开web02的httpd就可以两端都可以访问到Haproxy端设置sslcd /etc/pki/tls/certsopenssl req -x509 -nodes -newkey rsa:2048 -keyout \ /etc/pki/tls/certs/haproxy.pem -out /etc/pki/tls/certs/haproxy.pem \ -days 365运行后如下图:修改haproxy的配置文件vim /etc/haproxy/haproxy.cfg//* 设置 SSL 最大连接数//* 设置 SSL 加密信息//* 定义 SSL 监听的端口及秘钥所在路径及文件名保存后重启haproxy在放行443端口firewall-cmd --add-port=443/tcp之后测试打开ssl地址