春风十里不如你 —— Taozi - 实践 https://www.xiongan.host/index.php/tag/%E5%AE%9E%E8%B7%B5/ zh-CN Wed, 19 Oct 2022 08:13:00 +0800 Wed, 19 Oct 2022 08:13:00 +0800 【Packmaker】集群部署实践+测试 https://www.xiongan.host/index.php/archives/86/ https://www.xiongan.host/index.php/archives/86/ Wed, 19 Oct 2022 08:13:00 +0800 admin 主机名ip角色Node01192.168.123.23节点1Node02192.168.123.123节点2

首先安装pssh远程服务

yum install -y pssh

安装pssh

两台虚拟机都需要编辑hosts文件

分别写入node01、node02的ip 和主机名

生成免密登录,就可以无需密码直接登陆node01和node02

ssh-keygen -t rsa

ssh-copy-id -i /root/.ssh/id_rsa.pub root@node02-tz

生成上传ssl密钥

Node02端也需要进行相同操作

之后安装pacemaker服务并设置开机自启

pssh -h host-list.txt -i 'yum install pacemaker pcs -y'

pssh -h host-list.txt -i 'systemctl enable --now pcsd'

安装pacemaker

c9f038aa01c6440942e0a9679fe1735.png

配置 Pacemaker Cluster:

设置cluster的账号密码

pssh -h host-list.txt -i 'echo 123456 | passwd --stdin hacluster'

设置cluster

设置防火墙:

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

授权node节点用户

配置 Cluster(集群名称为:tz-cluster):

pcs cluster setup --name tz-cluster node01-tz node02-tz

添加集群

添加集群

启动 Cluster:

pcs cluster start –all

启动

使 Cluster 随机启动:

pcs cluster enable --all

自启cluster

验证集群状态:

pcs status cluster

验证状态

添加集群资源:

两台节点需要安装httpd服务,不需要启动

pssh -h host-list.txt -i 'yum install httpd -y'

httpd例子

两台服务器都需要编辑一个新的配置文件

vim /etc/httpd/conf.d/server_status.conf

ExtendedStatus 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

添加httpd资源

[root@node01-tz ~]# pcs constraint colocation add Web123-Cluster with VIP INFINITY

[root@node01-tz ~]# pcs constraint order VIP then Web123-Cluster <==设定启动顺讯:先启动 VIP 在启动 WEB123-Cluster

设置vip资源

pcs constraint <==显示资源情况

资源情况

客户端测试:

测试

停止 ndoe1 节点的 httpd 资源,客户端再测试:

pcs cluster stop node01-tz

测试

就自动切换到了node02上

使用 WEB GUI 管理 PaceMaker

firewall-cmd --add-port=2224/tcp --permanent

firewall-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/

]]>
0 https://www.xiongan.host/index.php/archives/86/#comments https://www.xiongan.host/index.php/feed/tag/%E5%AE%9E%E8%B7%B5/
【Ha-proxy】负载均衡配置实践记录 https://www.xiongan.host/index.php/archives/55/ https://www.xiongan.host/index.php/archives/55/ Sat, 15 Oct 2022 12:18:00 +0800 admin ha-proxy概述

ha-proxy是一款高性能的负载均衡软件。因为其专注于负载均衡这一些事情,因此与nginx比起来在负载均衡这件事情上做的更好,更专业。

准备

主机部署

Proxy端需要安装openssl openssl-lib haproxy

Web01和02 只需要安装httpd即可

Proxy端:

先备份配置文件
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
然后进行设置新的配置
vim /etc/haproxy/haproxy.cfg

global <== 全局配置

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

defaults

mode http <==定义运行模式为 http--Layer7 工作模式 
log global 
option httplog <==获取 http 的 request 日志 
timeout connect 10s <==后台服务超时时间 
timeout client 30s <==客户端超时时间 
timeout server 30s <==Server 超时时间

frontend http-in <==定义前台服务名称为 http-in

bind *:80 <==定义 http-in 所监听的端口 
default_backend backend_servers <==定义后台服务名称 
option forwardfor <==发送 X-Forwarded-For 头部信息

backend backend_servers <==定义后台服务名称为 backend_server

balance 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.conf
vim /etc/httpd/conf/httpd.conf //* 修改 196 行,如下面内容

LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

保存后退出

测试:

访问haproxy端的地址

测试01
测试02

关闭web01的httpd,就只显示web02的信息了

测试03

再次打开web02的httpd就可以两端都可以访问到

Haproxy端设置ssl

cd /etc/pki/tls/certs

openssl req -x509 -nodes -newkey rsa:2048 -keyout \ /etc/pki/tls/certs/haproxy.pem -out /etc/pki/tls/certs/haproxy.pem \ -days 365
运行后如下图:
生成ssl

修改haproxy的配置文件

vim /etc/haproxy/haproxy.cfg

配置ssl
配置ssl

//* 设置 SSL 最大连接数

//* 设置 SSL 加密信息

//* 定义 SSL 监听的端口及秘钥所在路径及文件名

保存后重启haproxy

在放行443端口

firewall-cmd --add-port=443/tcp

之后测试打开ssl地址

测试04
测试05

]]>
0 https://www.xiongan.host/index.php/archives/55/#comments https://www.xiongan.host/index.php/feed/tag/%E5%AE%9E%E8%B7%B5/