CentOS7下部署Zabbix4.0
本文参考官方文档完成
https://www.zabbix.com/cn/download?zabbix=4.0&os_distribution=centos&os_version=7&db=mysql&ws=apache
环境说明
- 1、Zabbix-Server
CentOS7.9 VMware虚拟机一台 192.168.31.232
- 2、Zabbix-Agent
CentOS7.9 VMware虚拟机一台 192.168.31.127
一、Zabbix Server端部署
1、yum源+EPEL源配置
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
关闭SELINUX等操作 记得校准系统时间
yum install ntpdate -y ntpdate ntp.aliyun.com
2、yum方式安装Zabbix Server及Zabbix-agent
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent
3、安装MariaDB数据库并导入zabbix初始化数据库
yum install mariadb-server systemctl start mariadb.service mysql_secure_installation
创建zabbix数据库
mysql -uroot -p create database zabbix character set utf8 collate utf8_bin; create user zabbix@localhost identified by 'zabbix@2021'; grant all privileges on zabbix.* to zabbix@localhost; quit;
导入zabbix初始化数据库
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
4、修改配置文件中数据库密码
vim /etc/zabbix/zabbix_server.conf 修改DBPassword=zabbix@2021 并启动 systemctl restart zabbix-server zabbix-agent httpd
5、配置文件中时区修改
vi /etc/httpd/conf.d/zabbix.conf php_value date.timezone Asia/Shanghai
6、php.ini配置优化
vim /etc/php.ini date.timezone = Asia/Shanghai max_execution_time = 300 memory_limit = 128M post_max_size = 16M upload_max_filesize = 2M max_input_time = 300 max_input_vars = 10000 always_populate_raw_post_data = -1
7、启动zabbix-server相关服务并设置为开机自启动
systemctl enable httpd systemctl enable zabbix-server systemctl enable zabbix-agent systemctl enable mariadb firewall-cmd --permanent --zone=public --add-port=80/tcp firewall-cmd --permanent --zone=public --add-port=10051/tcp firewall-cmd --reload
二、Zabbix-Server Web上完成初始化向导
http://192.168.31.127/zabbix/setup.php
修改界面语言为中文
三、Zabbix Agent安装与配置
1、yum源配置
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/Cen
2、安装zabbix-agent
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm yum install zabbix-agent
3、修改配置文件
修改配置文件中Server和ServerActive地址
sed -i "s/Hostname=Zabbix server/Hostname=centos.walkingcloud.cn/g" /etc/zabbix/zabbix_agentd.conf sed -i "s/ServerActive=127.0.0.1/ServerActive=192.168.31.232/g" /etc/zabbix/zabbix_agentd.conf sed -i "s/Server=127.0.0.1/Server=192.168.31.232/g" /etc/zabbix/zabbix_agentd.conf cat /etc/zabbix/zabbix_agentd.conf | grep Server= cat /etc/zabbix/zabbix_agentd.conf | grep ServerActive= cat /etc/zabbix/zabbix_agentd.conf | grep Hostname=
4、启动zabbix-agent相关服务并设置为开机自启动
zabbix-agent需要在防火墙中放通10050端口
firewall-cmd --permanent --zone=public --add-port=10050/tcp firewall-cmd --reload systemctl enable zabbix-agent systemctl start zabbix-agent systemctl status zabbix-agent tail -f /var/log/zabbix/zabbix_agentd.log
四、创建主机组,并添加主机
Tips:解决乱码问题
解决方法:安装字体并替换现有字体
yum install wqy-microhei-fonts -y cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/zabbix/assets/fonts/graphfont.ttf
五、触发器告警测试
可以看到可用容量低于80%时告警产生,in方向流量超过70Mbps时同样
总结:本文只是zabbix初始安装部署入门篇,zabbix强大的监控功能后续有空再继续探索