前言
这是之前做学校实验时我写的zabbix部署脚本
网络拓扑
网络拓扑很简单,同一局域网的两台机器,一个是zabbix服务端,一个是被监控端
IP地址 |
描述 |
192.168.200.222 |
zabbix服务端 |
192.168.200.111 |
部署着其他应用的被监控端 |
部署脚本
服务端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| #!/bin/bash
MARIADB_ROOT_PASSWD=123456
ZABBIX_PASSWORD=basi-a@123
function LAMP_install(){ yum -y install httpd \ mariadb-server mariadb \ php }
function mariadb_run(){ systemctl enable mariadb && systemctl start mariadb mysqladmin password ${MARIADB_ROOT_PASSWD} }
function zabbix_run(){ systemctl start zabbix-server zabbix-agent httpd systemctl enable zabbix-server zabbix-agent httpd }
function zabbix_install(){ rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm yum clean all yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent mysql -uroot -p${MARIADB_ROOT_PASSWD} -e "create database zabbix character set utf8 collate utf8_bin;" mysql -uroot -p${MARIADB_ROOT_PASSWD} -e "create user zabbix@localhost identified by '${ZABBIX_PASSWORD}';" mysql -uroot -p${MARIADB_ROOT_PASSWD} -e "grant all privileges on zabbix.* to zabbix@localhost;" zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p${ZABBIX_PASSWORD} zabbix sed -i "/^# DBPassword=/a\DBPassword=${ZABBIX_PASSWORD}" /etc/zabbix/zabbix_server.conf sed -i "s\# php_value date.timezone Europe/Riga\php_value date.timezone Asia/Shanghai\g" /etc/httpd/conf.d/zabbix.conf }
function main(){ systemctl disable firewalld >/dev/null 2>&1 systemctl stop firewalld >/dev/null 2>1& setenforcing 0 >/dev/null 2>&1 LAMP_install mariadb_run zabbix_install zabbix_run echo "visit zabbix with http://server's_IP/zabbix" echo "default username: Admin" echo "default password: zabbix" } main
|
之后就访问 http://服务端IP/zabbix 安装zabbix
然后就可以设置被控端监控项
被监控端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #!/bin/bash
ZABBIX_SERVER=192.168.200.222 CLIENT_HOSTNAME=192.168.200.111
function zabbix_client_install(){ rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm yum clean all yum -y install zabbix-agent sed -i "s\Server=127.0.0.1\Server=${ZABBIX_SERVER}\g" /etc/zabbix/zabbix_agentd.conf sed -i "s\ServerActive=127.0.0.1\ServerActive=${ZABBIX_SERVER}\g" /etc/zabbix/zabbix_agentd.conf sed -i "s\Hostname=Zabbix server\Hostname=${CLIENT_HOSTNAME}\g" /etc/zabbix/zabbix_agentd.conf }
function zabbix_client_run(){ systemctl enable zabbix-agent && systemctl start zabbix-agent }
function main(){ zabbix_client_install zabbix_client_run echo "zabbix client is OK, you can add it on zabbix server" } main
|
被控端, 安装好zabbix-agent, zabbix-server就能进行监控了