基于centos7安装Zabbix4.0
准备工作
# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
# 清空防火墙规则
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
# selinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
安装
1、在清华源找到wget对应的链接,https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/
wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
2、将wget到的文件通过rpm安装
rpm -ivh zabbix-release-4.0-2.el7.noarch.rpm
3、查看安装包依赖
rpm -ql zabbix-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
/etc/yum.repos.d/zabbix.repo
/usr/share/doc/zabbix-release
/usr/share/doc/zabbix-release/GPL
4、修改/etc/yum.repos.d/zabbix.repo
#更换zabbix源成国内源
sed -i 's/http\:\/\/repo.zabbix.com/https\:\/\/mirrors.tuna.tsinghua.edu.cn\/zabbix/g' /etc/yum.repos.d/zabbix.repo
# 关闭gpg检测
sed -i 's/gpgcheck=1/gpgcheck=0/g' /etc/yum.repos.d/zabbix.repo
5、安装zabbix-server端和zabbix-web端
# 根据centos版本更换yum源,防止出错更换的时候最好备份下。
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
# 安装zabbix客户端和web端
yum install zabbix-server-mysql zabbix-web-mysql -y
6、安装数据库,以mariadb为例
# 安装
yum install mariadb-server.x86_64 -y
# 启动服务、开机自启动
systemctl start mariadb.service && systemctl enable mariadb.service
# 初始化数据库
mysql_secure_installation
# 设置root密码
Set root password? [Y/n] n
# 移除匿名用户
Remove anonymous users? [Y/n] y
# 远程登录root
Disallow root login remotely? [Y/n] y
# 删除测试数据库并访问
Remove test database and access to it? [Y/n] y
# 重新加载privilege tables
Reload privilege tables now? [Y/n] y
# 进入客户端
mysql
MariaDB [(none)]>create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]>grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
# 导出zabbix表结构和初始数据
# 查询到create.sql
rpm -ql zabbix-server-mysql | grep mysql
/usr/share/doc/zabbix-server-mysql/create.sql.gz
# 导入
zcat /usr/share/doc/zabbix-server-mysql-4.0.28/create.sql.gz | mysql -uzabbix -p123456 zabbix
# 如果报错ERROR 1118 (42000) at line 1278: Row size too large (> 8126)
# 需要修改配置文件把严格模式失效,然后restart服务,drop zabbix数据库,重新创建,然后再导入
vi /etc/my.cnf.d/server.cnf
[mysqld]
innodb_strict_mode = 0
# 检查
mysql -uroot zabbix -e "show tables"
7、修改zabbix-server配置数据库连接
#修改配置项
vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
8、启动服务zabbix-server服务
# 启动服务、开机自启动
systemctl start zabbix-server.service && systemctl enable zabbix-server
systemctl start httpd && systemctl enable httpd
# 如果报错,查看日志
cat /var/log/zabbix/zabbix_server.log
9、ip/zabbix就可以访问web端了。但是需要设置下时区,很容易理解,zabbix告警出来的信息肯定要跟本地时间一致。
方法一
# 把zabbix.conf文件的timezone注释取消掉,改成设置的时区。
vi /etc/httpd/conf.d/zabbix.conf
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_popular_row_post_data -1
php_value date.timezone Asia/Shanghai
</IfModule>
# 重启httpd服务
systemctl restart httpd
方法二
vi /etc/php-fpm.d/zabbix.conf
# 增加
php_value[date.timezone] = Asia/Shanghai
# 重启php-fpm.service服务
systemctl restart php-fpm.service
方法三
vi /ect/php.ini
# ;date.timezone =
date.timezone = Asia/Shanghai
# 重启php-fpm.service服务
systemctl restart php-fpm.service
10、完成安装
登录用户的话,是读取导入的users表
mysql -uroot -p -e "select alias,passwd from zabbix.users\G"
alias: Admin
passwd: 5fce1b3e34b520afeffb37ce08c7cd66
密码都是md5加密后的,默认密码:Admin zabbix