欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

zabbix 系统搭建(LAMP环境)+keepalived LVS配置

程序员文章站 2022-07-12 17:08:48
...

zabbix 系统搭建(LAMP环境)

先搭建好LAMP环境 (介绍)

安装zabbix监控主机 (设置监控主机ip为192.168.200.130)
wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm (下载rpm包,是zabbix的yum源)

rpm -ivh zabbix-release-3.2-1.e17.noarh.rpm (这里就是安装yum源)

yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql

mysql搭建zabbix使用的库
步骤

● vim /etc/my.cnf //需要增加配置
character_set_server = utf8
● 重启mysqld服务后。进入mysql命令行,创建zabbix库
● creat database zabbix character set utf8;
● 再创建用户
● grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'aming-zabbix'
给库zabbix有所有权限
● 导入数据
● cd /usr/share/doc/zabbix-server-mysql-3.2.7
● gzip -d creat.sql.gz
● mysql -uroot -pXXX zabbix < creat.sql
● systemctl start httpd; systemctl enable httpd
● vim /etc/zabbix/zabbix_server.conf //修改或增加
DBHost=127.0.0.1 //在DBName=zabbix上面增加(这个要与mysql创建库的一样@XXXXX,来源ip)
DBUser=zabbix
DBPassword=aming-zabbix //在DBuser下面增加
● systemctl start zabbix-server
● systemctl enable zabbix-server
● netstat -lntp | grep zabbix //查看监听端口 10051
● 浏览器访问 http://ip.zabbix/ web界面下配置zabbix(如:http://192.168.200.130.zabbix)
● 用户名Admin 密码 zabbix
● 进入后台第一件事情就是该密码

如果时区错误,设置时区 vim /etc/php.ini
date.timezone = Asia/Shanghai
保存退出,再重启httpd(Apache)

Seal-server客户端安装
● wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
● rpm -ivh zabbix-release-3.2-1.e17.noarh.rpm (这里就是安装yum源)
● yum install -y zabbix-agent
● vim /etc/zabbix/zabbix_agentd.conf //修改如下配置
Server=127.0.0.1 Server=192.168.200.130 //定义服务器端的ip (被动模式)
ServerActive=127.0.0.1 ServerActive=192.168.200.130 //定义服务器端的ip (主动模式)
Hostname=Zabbix server Hostname=Group02_118~122 //这是自定义的主机名,一会还需要在web界面下设置同样的主机名
● systemctl start zabbix-agent //启动zabbix-agent
● systemctl enable zabbix-agent //设置zabbix-agent开机启动

浏览器访问 http://ip.zabbix/ web界面下配置zabbix监控 客户端

配置分发器keepalived LVS配置

分发器主机SR:192.168.200.116 的设置

  1. master主机192.168.200.116,安装keepalived ,
    Yum install –y keepalived
    (关闭防火墙+selinux清空iptables规则:
    ● systemctl stop firewalld; systemctl disable firewalld(必须关闭firwalld ,清空iptables的规则,关闭selinux)
    ● systemctl start iptables-services; iptables -F ;service iptables save
    ● 命令getenforce 查询selinux状态Enforcing 开启 /Disabled 关闭,临时关闭命令 setenforce 0
    永久关闭 vim /etc/selinux/config 编辑SELINUX=disabled 重启也生效关闭selinux
    #检查网关 route -n

  2. vim /etc/keepalived/keepalived.conf 编辑配置,内容
    .
vrrp_instance VI_1 {
    #备用服务器上为 BACKUP
    state MASTER
    #绑定vip的网卡为ens33,你的网卡和阿铭的可能不一样,这里需要你改一下
    interface ens160
    virtual_router_id 51
    #备用服务器上为90
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass aminglinux
    }
    virtual_ipaddress {
        192.168.200.117
    }
}
virtual_server 192.168.200.117 80 {
    #(每隔10秒查询realserver状态)
    delay_loop 10
    #(lvs 算法)
    lb_algo wlc
    #(DR模式)
    lb_kind DR
    #(同一IP的连接60秒内被分配到同一台realserver)
    persistence_timeout 60
    #(用TCP协议检查realserver状态)
    protocol TCP
    real_server 192.168.200.118 80 {
        #(权重)
        weight 100
        TCP_CHECK {
        #(10秒无响应超时)
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.200.119 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
real_server 192.168.200.120 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
real_server 192.168.200.121 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
real_server 192.168.200.122 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }

}

保存退出

  1. systemctl start keepalived 启动keepalived
    ps aux|grep keepalived 查看keepalived是否启动
    ip add 查看虚拟VIP 192.168.200.177 是否生效

  2. 查看设置虚拟IP,ipvsadm –ln ;
    如果有其他规则ip 要先停止keepalived :systemctl stop keepalived
    ipvsadm –C 清空虚拟ip,再启动 systemctl start keepalived

分发器备机SR:192.168.200.125 的设置

  1. backup主机192.168.200.125,安装keepalived ,(资讯铭哥vip不可以是本机IP,117更换125)
    Yum install –y keepalived
    (关闭防火墙+selinux清空iptables规则:
    ● ystemctl stop firewalld; systemctl disable firewalld(必须关闭firwalld ,清空iptables的规则,关闭selinux)
    ● systemctl start iptables-services; iptables -F ;service iptables save
    ● 命令getenforce 查询selinux状态Enforcing 开启 /Disabled 关闭,临时关闭命令 setenforce 0
    永久关闭 vim /etc/selinux/config 编辑SELINUX=disabled 重启也生效关闭selinux
    #检查网关 route -n

  2. vim /etc/keepalived/keepalived.conf 编辑配置,内容
    .
vrrp_instance VI_1 {
    #备用服务器上为 BACKUP
    state BACKUP
    #绑定vip的网卡为ens33,你的网卡和阿铭的可能不一样,这里需要你改一下
    interface ens160
    virtual_router_id 51
    #备用服务器上为90
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass aminglinux
    }
    virtual_ipaddress {
        192.168.200.117
    }
}
virtual_server 192.168.200.117 80 {
    #(每隔10秒查询realserver状态)
    delay_loop 10
    #(lvs 算法)
    lb_algo wlc
    #(DR模式)
    lb_kind DR
    #(同一IP的连接60秒内被分配到同一台realserver)
    persistence_timeout 60
    #(用TCP协议检查realserver状态)
    protocol TCP
    real_server 192.168.200.118 80 {
        #(权重)
        weight 100
        TCP_CHECK {
        #(10秒无响应超时)
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.200.119 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
real_server 192.168.200.120 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
real_server 192.168.200.121 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
real_server 192.168.200.122 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }

}

保存退出

  1. systemctl start keepalived 启动keepalived
    ps aux|grep keepalived 查看keepalived是否启动
    ip add 查看虚拟VIP 192.168.200.177 是否生效

所有服务端:real-server 118~122操作
所有real-server 118~122都要执行
编写脚本vim /usr/local/sbin/lvs_dr.sh //内容如下

#!/bin/bash
vip=192.168.200.117
#把vip绑定在lo上,是为了实现rs直接把结果返回给客户端
ifdown lo
ifup lo
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip lo:0
#以下操作为更改arp内核参数,目的是为了让rs顺利发送mac地址给客户端
#参考文档 http://www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

保存退出后
执行lvs_dr.sh 脚本,

转载于:https://blog.51cto.com/8229148/2055553