原貼地址http://jensd.be/393/linux/install-zabbix-on-centos-7-or-rhel-7php
精簡版的步驟:mysql
1. 添加源linux
yum –y install epel-releasegit
vi /etc/yum.repos.d/zabbix.repogithub
[Zabbix]web
name=Zabbixsql
baseurl=http://repo.zabbix.com/zabbix/2.4/rhel/7/x86_64/數據庫
gpgcheck=1apache
gpgkey=http://repo.zabbix.com/zabbix-official-repo.keyvim
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/p_w_picpaths.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這段時間,對本身幾乎成了一種修煉。靜心,不急不燥,不追求完美的方案 認真對待每一條命令,每個字母的大小寫;先解決眼前的要求,不盲目跟着興趣走。這些都會是受用終生的財富。
不功利,日常心,慢下來,也許就有了起色。
加油,努力。