精简版的步骤:
1.添加源
yum –y install epel-release
vi /etc/yum.repos.d/zabbix.repo
[Zabbix]
name=Zabbix
baseurl=http://repo.zabbix.com/zabbix/2.4/rhel/7/x86_64/
gpgcheck=1
gpgkey=http://repo.zabbix.com/zabbix-official-repo.key
2.安装包
yum –y install zabbix-server-mysql zabbix-agent zabbix-web-mysql mysql mariadb-server httpd php
3.准备数据库
3.1启动数据库服务并在开机自动启动
systemctl start mariadb
systemctl enable mariadb
3.2 加固数据库
mysql_secure_installation
设置数据库root密码,其它选项全部默认选择是。
3.3 创建zabbix数据库,添加账号和权限
mysql –u root –p #root登录数据库
CREATE DATABASE zabbix; #创建zabbix专用库
GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY ‘zabbix’ #创建专用数据库管理员账号zabbix,密码也是zabbix,
同时给予zabbix账号zabbix库所有表所有权限。
FLUSH PRIVILEGES; #生效权限
exit;保存退出数据库
3.4 导入zabbix数据库配置表格
mysql -u root -p zabbix </usr/share/doc/zabbix-server-mysql-*/create/schema.sql
mysql -u root -p zabbix </usr/share/doc/zabbix-server-mysql-*/create/images.sql
mysql -u root -p zabbix </usr/share/doc/zabbix-server-mysql-*/create/data.sql
更多数据库优化项请移步 https://github.com/major/MySQLTuner-perl
4.配置网页服务器
优化PHP,最后一项时区一定要改
sed -i 's/^max_execution_time.*/max_execution_time=600/' /etc/php.ini
sed -i 's/^max_input_time.*/max_input_time=600/' /etc/php.ini
sed -i 's/^memory_limit.*/memory_limit=256M/' /etc/php.ini
sed -i 's/^post_max_size.*/post_max_size=32M/' /etc/php.ini
sed -i 's/^upload_max_filesize.*/upload_max_filesize=16M/' /etc/php.ini
sed -i "s/^\;date.timezone.*/date.timezone=\'Asia\/Shanghai\'/" /etc/php.ini
加固apache
vim /etc/httpd/conf.d/zabbix.conf
#
# Zabbix monitoring system php web frontend
#
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory "/usr/share/zabbix/conf">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/include">
Require all denied
</Directory>
打开防火墙规则,启动服务,检查登录情况
firewall-cmd --zone=public --add-service=http –permanent
systemctl start httpd
systemctl enable httpd
5.配置zabbix
配置zabbix
sed -i 's/^# DBPassword=.*/DBPassword=zabbix/' /etc/zabbix/zabbix_server.conf
参数优化
sed -i 's/^# CacheSize=.*/CacheSize=32M/' /etc/zabbix/zabbix_server.conf
sed -i 's/^# StartPingers=.*/StartPingers=5/' /etc/zabbix/zabbix_server.conf
配置selinux
setsebool -P httpd_can_connect_zabbix=true
启动服务
systemctl enable zabbix-server
systemctl start zabbix-server
#有个bug会导致启动失败,segfault at 18 ip 00007fbf1295dc00 sp 00007ffff5527ec8 error 4 in libpthread-2.17.so[7fbf12954000+16000]
可通过降级gnutls 至3.1.20或者yum –y update后重启服务
详细讨论请移步 https://support.zabbix.com/browse/ZBX-7790
网页登录 http://zabbix.it.lab/zabbix ,完成初始化配置
默认登录用户名admin,密码zabbix
6.添加监控主机
yum –y install epel-release
yum –y install zabbix22-agent
修改配置文件
sed -i 's/^Server=127.0.0.1/Server=zabbix.it.lab/g' /etc/zabbix/zabbix_agentd.conf
开启服务
systemctl enable zabbix-agent
systemctl start zabbix-agent
这儿遇到了个坑,server not running
停用selinux和防火墙没有解决,架梯子搜了圈基本都在说selinux。
静下以来仔细检查日志 /var/log/zabbix/zabbix_server.log
connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO)
mysql -u zabbix -p zabbix 登录却是成功的,那问题就在zabbix配置上无疑了。
grep DBPassword /etc/zabbix/zabbix_server.conf
# For SQLite3 path to database file must be provided. DBUser and DBPassword are ignored.
### Option: DBPassword
# DBPassword=
这里竟然没配上密码,也是蠢哭了。
学习Linux这段时间,对自己几乎成了一种修炼。静心,不急不燥,不追求完美的方案 认真对待每一条命令,每一个字母的大小写;先解决眼前的要求,不盲目跟着兴趣走。这些都会是受用终生的财富。