zabbix3.4版本最详细搭建
前言:zabbix是一款及时监控报警软件,能够对主机、网络状态实时监控。网上找的很多关于zabbix的搭建教程都或多或少有问题,于是乎自己写一篇算是复习了。
环境: 使用系统centos7、软件版本zabbix3.4、centos7可以参照我的博客[centos7模板机搭建]。(https://blog.csdn.net/qq_43316775/article/details/104791068)
1、修改hostname、hosts
[root@centos7 ~]# hostname zabbix
[root@centos7 ~]# vi /etc/hosts
[root@centos7 ~]# vi /etc/hostname
2、添加软件包镜像源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
yum clean all
yum makecache
vi /etc/yum.repos.d/zabbix.repo
[zabbix]
name=zabbix
baseurl=http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/
gpgcheck=0
enabled=1
yum -y install epel-release
3、安装软件
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
#安装可能会因为网速问题导致安装失败,因为下载源是在国外的网速非常慢,如果不行可以将几个rpm包下载到本地的然后上传进去通过yum localinstall zabbix*进行安装。
报错:
字面翻译就是deltarpm没有安装,接下来我们安装就是了
执行两条命令
yum provides '*/applydeltarpm' #查看依赖包的位置
yum -y install deltarpm #安装命令
rpm -qa|grep zabbix-* #查看已安装程序
4、安装配置数据库
yum -y install mariadb mariadb-server php php-mysql httpd net-tools
systemctl enable mariadb
systemctl start mariadb
# mysql -uroot -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
mysql>set password for root@localhost = password('ecpss@123'); #root密码设置
mysql> quit;
5、导入数据文件,需要输入密码zabbix
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
6、配置zabbix_server.conf
grep -Ev '^#|^$' /etc/zabbix/zabbix_server.conf #查看配置
cp -av /etc/zabbix/zabbix_server.conf{,.bak} #备份
cat >/etc/zabbix/zabbix_server.conf<<EOF
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
DBPort=3306
StartPollers=5
StartIPMIPollers=10
StartPollersUnreachable=10
StartTrappers=10
StartPingers=10
StartDiscoverers=10
VMwareFrequency=60
VMwareCacheSize=8M
SNMPTrapperFile=/var/log/snmptf/snmptf.log
ListenIP=$(hostname -i)
MaxHousekeeperDelete=500
CacheSize=256M
StartDBSyncers=40
HistoryCacheSize=128M
TrendCacheSize=128M
ValueCacheSize=128M
Timeout=30
TrapperTimeout=300
UnreachablePeriod=45
UnavailableDelay=60
UnreachableDelay=15
AlertScriptsPath=/etc/zabbix/alertscripts
ExternalScripts=/etc/zabbix/externalscripts
FpingLocation=/usr/sbin/fping
LogSlowQueries=10000
StartProxyPollers=50
ProxyConfigFrequency=3600
EOF
mkdir -pv /etc/zabbix/alertscripts
mkdir -pv /etc/zabbix/externalscripts
注意:在DBSocket=/var/lib/mysql/mysql.sock中,mysql由于安装方式不同所以安装目录也会有所不同,可以用一下命令找出安装目录,并修改在DBSocket这一行。
find / -name mysql.sock
7、配置zabbix_agentd.conf
[root@zabbix etc]# egrep -Ev '^#|^$' /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
EnableRemoteCommands=1
Server=192.168.1.56
Hostname=192.168.1.56
Include=/etc/zabbix/zabbix_agentd.d/
8、配置zabbix.conf.php
vi /etc/zabbix/web/zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = 'localhost'; #和创建数据库时候的主机一致
$DB['PORT'] = '3306';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'zabbix';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = '192.168.1.65'; # server_ip
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'zabbix'; # server_name
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
9、配置PHP参数文件
cp -av /etc/php.ini{,.bak}
sed -i 's/^\(max_execution_time\).*/\1 = 300/g' /etc/php.ini
sed -i 's/^\(max_input_time\).*/\1 = 300/g' /etc/php.ini
sed -i 's/^\(post_max_size\).*/\1 = 16M/g' /etc/php.ini
sed -i 's|\[Date\]|&\ndate.timezone = Asia/Shanghai|g' /etc/php.ini
sed -i 's|\[mbstring\]|&\nmbstring.func_overload = 1|g' /etc/php.ini
10、整合zabbix和httpd
cp -av /etc/httpd/conf.d/zabbix.conf{,.bak}
sed -i 's|# php_value date.timezone Europe/Riga|php_value date.timezone Asia/Shanghai|g' /etc/httpd/conf.d/zabbix.conf
systemctl restart httpd
11、启动zabbix-server zabbix-agent
systemctl enable zabbix-server
systemctl restart zabbix-server
systemctl enable zabbix-agent
systemctl restart zabbix-agent
systemctl start httpd
chkconfig zabbix-server on
chkconfig httpd on
chkconfig zabbix-agent on
12、配置http页面
在文件中添加一行ServerName 127.0.0.1:80
sed -i 's/#ServerName www.example.com:80/&\nServerName 127.0.0.1:80/g' /etc/httpd/conf/httpd.conf
13、进入web页面
http://ip/zabbix
账号默认Admin、密码zabbix