centos7.2 安装 zabbix3.2.x
查看系统版本
cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
查看内核版本
uname -r
3.10.0-327.el7.x86_64
关闭selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0
关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
如果不关闭防火墙需要添加相应的端口,如添加80端口:
firewall-cmd --permanent --add-port={80/tcp,10051/tcp} 添加80端口和10051端口
firewall-cmd --reload 重载防火墙
到zabbix的官网下载相应的rpm包 官网地址如下:
https://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/
本次实验所需要的包如下:
zabbix-release-3.2-1.el7.noarch.rpm
zabbix-agent-3.2.4-1.el7.x86_64.rpm
zabbix-get-3.2.4-1.el7.x86_64.rpm
zabbix-sender-3.2.4-1.el7.x86_64.rpm
zabbix-proxy-mysql-3.2.4-1.el7.x86_64.rpm
zabbix-server-mysql-3.2.4-2.el7.x86_64.rpm
zabbix-web-3.2.4-1.el7.noarch.rpm
zabbix-web-mysql-3.2.4-1.el7.noarch.rpm
时间同步
yum -y install ntp
ntpdate 1.cn.pool.ntp.org
centos7自带了mariadb-libs 需要卸载他
rpm -qa | grep maraidb
rpm -e --nodeps mariadb-libs
yum -y localinstall *.rpm 安装所有的rpm包
rpm -qa | grep zabbix 查看已安装了那些包
安装LAMP环境 mariadb httpd php:
yum -y install mariadb mariadb-server httpd php
配置LAMP(这里是为了最后zabbix登录web页面不报错,更改时区,内存大小等):
sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/" /etc/php.ini
sed -i "s/max_execution_time = 30/max_execution_time = 300/" /etc/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 32M/" /etc/php.ini
sed -i "s/max_input_time = 60/max_input_time = 300/" /etc/php.ini
修改/etc/httpd/conf.d/zabbix.conf,把时区改为亚洲/上海
sed -i 's@# php_value date.timezone Europe/Riga@php_value date.timezone Asia/Shanghai@g' /etc/httpd/conf.d/zabbix.conf
启动数据库,登录数据库 设置数据库密码为123456 并刷新权限
systemctl start mariadb.service
mysql
set password = password ('123456');
flush privileges;
\q
在Linux命令行 创建zabbix数据库 并设置权限(这一步也可以在上一步登录mysql的时候操作):
mysql -uroot -p123456 -e "create database zabbix character set utf8 collate utf8_bin;"
mysql -uroot -p123456 -e "grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';"
mysql -uroot -p123456 -e "flush privileges;"
导入zabbix数据库
cd /usr/share/doc/zabbix-server-mysql-3.2.4/
zcat create.sql.gz | mysql -uzabbix -pzabbix zabbix
启动httpd和mysql,并设置开机启动
systemctl restart mariadb.service
systemctl restart httpd.service
systemctl enable mariadb.service
systemctl enable httpd.service
配置 zabbix_server:
配置zabix_server.conf zabbix_server.conf中 DBName=zabbix,DBUser=zabbix都是默认的不用更改 也可以vim /etc/zabbix/zabbix_server.conf进去更改 查看
sed -i 's@# DBPassword=@DBPassword=zabbix@g' /etc/zabbix/zabbix_server.conf
sed -i 's@# DBHost=localhost@DBHost=localhost@g' /etc/zabbix/zabbix_server.conf
启动zabbix_server并设置开机启动:
systemctl start zabbix-server
遇到问题如下:
Job for zabbix-server.service failed because the control process exited with error code. See "systemctl status zabbix-server.service" and "journalctl -xe" for details.
解决方法:
systemctl status zabbix-server.service
看到这么一句话
Process: 19635 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=1/FAILURE)
指定server的配置文件启动(因为我是rpm包安装的,所以启动方法如下):
/usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
看到问题如下:
zabbix_server [19699]: unknown parameter "DBPassowrd" in config file "/etc/zabbix/zabbix_server.conf", line 115
我们发现配置文件里面DBPassowrd 出错了 进去更改一下
如果不知道zabbix_server.conf配置文件在哪里,可以这样做:
find / -name 'zabbix_server.conf'
重启zabbix_server
systemctl restart zabbix-server.service
systemctl status zabbix-server.service
看到 Active: active (running) 说明启动成功
还可以查看一下端口
ss -antlup | egrep '10050|10051'
===========================================================================================
安装zabbix_agent(在新的Linux机器上安装zabbix_agent)
如果是zabbix_server端安装zabbix_agent那么就不需要再次关闭selinux 安装zabbix源 如果是另一台Linux上就需要关闭selinux 安装zabbix源
关闭selinux:
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0
关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
如果不关闭防火墙需要添加zabbix_agent的10050端口允许通过
firewall-cmd --permanent --add-port=10050/tcp
firewall-cmd --reload
安装zabbix软件源
https://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
官网其他rpm包地址(有需要可自行下载)
https://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/
安装zabbix-agent
yum -y install zabbix-sender zabbix-agent zabbix
查看已安装zabbix-agent版本
rpm -qa | grep zabbix-agent
zabbix-agent-3.2.4-1.el7.x86_64
配置zabbix-agent
修改zabbix-agentd.conf 让他指向zabbix_server端
sed -i "s/Server=127.0.0.1/Server=192.168.1.101/" /etc/zabbix/zabbix_agentd.conf
sed -i "s/ServerActive=127.0.0.1/ServerActive=192.168.1.101/" /etc/zabbix/zabbix_agentd.conf (主动模式)
sed -i "s/Hostname=Zabbix server/Hostname=192.168.1.105/" /etc/zabbix/zabbix_agentd.conf
也可以vim /etc/zabbix/zabbix_agentd.conf进去修改 ip地址根据自己环境更改一下
启动并设置开机自启
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service