(最全的)zabbix監控搭建(親測)
1.系統環境配置
1.1 關閉防火牆
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
1.2 關閉SeLinux
vi /etc/selinux/config
#SELINUX=enforcing 去掉#並修改為 SELINUX=disabled
#SELINUXTYPE=targeted 去掉#
:wq! #儲存退出
(或者 sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config)
setenforce 0 #使配置立即生效
2.安裝LAMP環境
2.1 安裝apache
yum install httpd –y
systemctl start httpd #啟動apache
systemctl enable httpd #設定apache開機啟動
在客戶端瀏覽器中開啟伺服器IP地址,會出現網站畫面,說明apache安裝成功
2.2.1 安裝資料庫MariaDB
yum install mariadb-bench mariadb-devel mariadb-libs mariadb-server
sudo yum search mariadb
systemctl start mariadb #啟動MariaDB
systemctl enable mariadb #設定開機啟動
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷貝配置檔案(注意:如果/etc目錄下面預設有一個my.cnf,直接覆蓋即可)
2.2.2 設定資料庫密碼
mysql_secure_installation 預設密碼為空,根據提示輸入Y設定新密碼
之後根據提示都選擇Y,也可以根據自己需要設定。最後出現:Thanks for using MariaDB!,密碼設定完成。
systemctl restart mariadb #重啟MariaDB
登入資料庫mysql -uroot -p,出現MariaDB [(none)]>明安裝成功。
2.3 安裝PHP
yum install php –y
安裝元件支援
yum install php-mysql php-gd libjpeg* php-ldap php-odbcphp-pear php-xml php-xmlrpc php-mbstr。ing php-bcmath php-mhash –y
systemctl restart mariadb #重啟MariaDB
rm -f /etc/httpd/conf.d/welcome.conf/var/www/error/noindex.html #刪除apache預設測試頁
systemctl restart httpd #重啟apache
設定PHP時區
vi /etc/php.ini #編輯
date.timezone = PRC #把前面的分號去掉,改為date.timezone= PRC
測試cd /var/www/html
vi index.php
輸入如下內容
:wq儲存退出
許可權設定:chown apache.apache -R /var/www/html
systemctl restart mariadb #重啟MariaDB
systemctl restart httpd #重啟apache
客戶端瀏覽器輸入ip地址
yum install zabbix-server-mysql zabbix-web-mysql
3.2 建立zabbix資料庫
mysql -uroot -p
MariaDB [(none)]> create database zabbix character set utf8;
zabbix資料庫可以和zabbix伺服器分離,採用用專門的mysql伺服器儲存資料,此時要給zabbix資料庫受相應的許可權。
注:ip為zabbix伺服器的IP地址。
MariaDB [(none)]> grant all privileges on zabbix.* to [email protected](伺服器地址) identified by ‘hfjy’;
匯入資料庫
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uroot -p zabbix
配置zabbix_server.conf
vi
vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=root
DBPassword=123123
systemctl start zabbix-server #啟動zabbix-server
systemctl enable zabbix-server #設定zabbix-server開機啟動
3.3 配置PHP
vi /etc/httpd/conf.d/zabbix.conf
更改時區設定
php_value date.timezone Asia/Shanghai
(或sed -i.ori ‘18a php_value date.timezone Asia/Shanghai‘ /etc/httpd/conf.d/zabbix.conf)
重啟資料庫,httpd和zabbix-server
[[email protected] conf.d]# systemctl restart mariadb
[[email protected] conf.d]# systemctl restart httpd
[[email protected] conf.d]# systemctl restart zabbix-server
3.4. web配置
客戶端瀏覽器輸入http://<server_ip_or_name>/zabbix
點選Next step根據提示完成配置
登陸賬號密碼 Admin/zabbix
至此zabbix安裝完成。