zabbix是一個基于WEB界面的提供分布式系統(tǒng)監(jiān)視以及網(wǎng)絡(luò)監(jiān)視功能的企業(yè)級的開源解決方案。zabbix能監(jiān)視各種網(wǎng)絡(luò)參數(shù),保證服務(wù)器系統(tǒng)的安全運營;并提供靈活的通知機制以讓系統(tǒng)管理員快速定位/解決存在的各種問題。
下面是Centos7上yum安裝zabbix的步驟。
本文檔在同一臺機器上安裝了zabbix-server 和zabbix-agent 自己監(jiān)控自己。
一、lamp環(huán)境搭建
1、安裝依賴包
#yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel libpng-devel libjpeg-devel freetype freetype-devel
2.yum安裝apache
yum install httpd -y
systemctl start httpd
systemctl enable httpd
firewall設(shè)置允許遠程登錄
firewall-cmd --permanent --add-service=http
systemctl restart firewalld
3、安裝mariadb
# yum -y install mariadb mariadb-server mariadb-devel
#yum install mysql-community-server
#service mysqld start
systemctl start mariadb
systemctl enable mariadb
默認情況下,root密碼為空。為防止未授權(quán)的訪問,我們設(shè)置root密碼
mysql_secure_installation
4、安裝php
yum install php php-mysql php-gd php-pear -y
測試PHP:
在Apache文檔根目錄創(chuàng)建“testphp.php”
vi/var/www/html/testphp.php
編輯內(nèi)容如下
phpinfo();?>
重啟 httpd 服務(wù)
systemctl restart httpd
也可以使用如下命令安裝所有php modules,重啟httpd服務(wù),查看http://server-ip-address/testphp.php,可以看到所有安裝的modules
yum install php* -y
5、Install phpMyAdmin (可選)
phpMyAdmin
是一個以PHP為基礎(chǔ),以Web-Base方式架構(gòu)在網(wǎng)站主機上的MySQL的數(shù)據(jù)庫管理工具,讓管理者可用Web接口管理MySQL數(shù)據(jù)庫。由于phpMyAdmin跟其他PHP程式一樣在網(wǎng)頁服務(wù)器上執(zhí)行,您可以在任何地方使用這些程式產(chǎn)生的HTML頁面,也就是于遠端管理MySQL數(shù)據(jù)庫,方便的建立、修改、刪除數(shù)據(jù)庫及資料表。也可借由phpMyAdmin建立常用的php語法,方便編寫網(wǎng)頁時所需要的sql語法正確性。
添加 EPEL repository?? 參照(Install EPEL Repository on RHEL/CentOS/Scientific Linux 7)
yum install epel-release
安裝 phpMyAdmin:
yum install phpmyadmin -y
配置phpMyAdmin
默認,phpMyAdmin只能由本機訪問。為了能夠遠程訪問,編輯phpmyadmin.conf file
vi/etc/httpd/conf.d/phpMyAdmin.conf
查找/<Directory>,注釋掉或刪除如下內(nèi)容
<Directory /usr/share/phpMyAdmin/>
?? AddDefaultCharset UTF-8
??? <IfModule mod_authz_core.c>
???? # Apache 2.4
???? <RequireAny>
?????? Require ip 127.0.0.1
?????? Require ip ::1
???? </RequireAny>
?? </IfModule>
?? <IfModule !mod_authz_core.c>
???? # Apache 2.2
???? Order Deny,Allow
???? Deny from All
???? Allow from 127.0.0.1
???? Allow from ::1
?? </IfModule>
</Directory>
?<Directory /usr/share/phpMyAdmin/setup/>
?? <IfModule mod_authz_core.c>
???? # Apache 2.4
???? <RequireAny>
?????? Require ip 127.0.0.1
?????? Require ip ::1
???? </RequireAny>
?? </IfModule>
?? <IfModule !mod_authz_core.c>
???? # Apache 2.2
???? Order Deny,Allow
???? Deny from All
???? Allow from 127.0.0.1
???? Allow from ::1
?? </IfModule>
</Directory>
添加
<Directory /usr/share/phpMyAdmin/>
??????? Options none
??????? AllowOverride Limit
??????? Require all granted
</Directory>
編輯“config.inc.php”改變phpMyAdmin的authentication,修改“cookie” 為 “http”
vi/etc/phpMyAdmin/config.inc.php
Change‘cookie’to‘http’.
重啟the Apache service:
systemctl restart httpd
訪問 phpmyadmin 的控制臺http://server-ip-address/phpmyadmin/
輸入MySQL username and password,將重定向到PhpMyAdmin main web interface.
現(xiàn)在你可以通過phpMyAdmin web interface 管理你的MariaDB數(shù)據(jù)庫了。
至此LAMP環(huán)境搭建完畢
二、yum安裝zabbix
Zabbix在CentOS基本源里不可獲得,因此必須配置EPEL 和Zabbix 官方repository
安裝EPEL repository
yum install epel-release
配置ZabbixZone package repository and GPG key
rpm --import http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX
rpm -Uv http://repo.zabbix.com/zabbix/2.4/rhel/7/x86_64/zabbix-release-2.4-1.el7.noarch.rpm
安裝Zabbix server and agent(agent是可選的)
安裝Zabbix server and agent:(配置自己監(jiān)控自己,所以安裝了zabbix-agent)
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway
編輯 file /etc/httpd/conf.d/zabbix:
vi/etc/httpd/conf.d/zabbix.conf
更新時區(qū):
php_value date.timezone Asia/Shanghai
重啟httpd
systemctl restart httpd
創(chuàng)建MySQL 數(shù)據(jù)庫和用戶
登錄MariaDB:
mysql –u root –p
創(chuàng)建一個數(shù)據(jù)庫‘zabbix’和數(shù)據(jù)庫用戶‘zabbix’
MariaDB[(none)]>create database zabbix character set utf8;
MariaDB [(none)]>grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';
MariaDB [(none)]>flush privileges;
數(shù)據(jù)庫導入zabbix template
使用數(shù)據(jù)庫用戶zabbix登錄數(shù)據(jù)庫
mysql –uzabbix –p
切換到zabbix數(shù)據(jù)庫
use zabbix
導入模板數(shù)據(jù)
MariaDB[zabbix]>source /usr/share/doc/zabbix-server-mysql-2.4.8/create/schema.sql
MariaDB [zabbix]>source /usr/share/doc/zabbix-server-mysql-2.4.8/create/images.sql
MariaDB [zabbix]>source /usr/share/doc/zabbix-server-mysql-2.4.8/create/data.sql
配置Zabbix server
編輯文件/etc/zabbix/zabbix_server.conf,
vi/etc/zabbix/zabbix_server.conf
配置下面的三個參數(shù)
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
vi/etc/zabbix/zabbix_agentd.conf
配置zabbix server 的ip
## Line 85 - Specify Zabbix server ##
Server=127.0.0.1
## Line 126 - Specify Zabbix server ##
ServerActive=127.0.0.1
## Line 137 - Specify Zabbix server Hostname or IP address ##
Hostname=127.0.0.1
修改PHP 設(shè)置
修改php.ini為zabbix 建議的設(shè)置
編輯文件 php.ini,
vi/etc/php.ini
設(shè)置下面的參數(shù).
max_execution_time = 600
max_input_time = 600
memory_limit = 256
post_max_size = 32M
upload_max_filesize = 16M
date.timezone = Asia/Shanghai
修改Firewall 和SELinux 設(shè)置
開放zabbix端口10050 and 10051.
firewall-cmd --permanent --add-port=10050/tcp
firewall-cmd --permanent --add-port=10051/tcp
重啟firewall
systemctl restart firewalld
如果使用 SELinux, 運行以下命令使 Apache 可以和 Zabbix通信
setsebool -P httpd_can_connect_zabbix=1
允許Zabbix web console 對特定IP段可用 (可選)
編輯文件 /etc/httpd/conf.d/zabbix.conf,
vi/etc/httpd/conf.d/zabbix.conf
添加允許訪問 zabbix web interface的ip段. 如果設(shè)置 ‘Allow from All’, 這可以允許全部可以訪問
# Zabbix monitoring system php web frontend
Alias /zabbix /usr/share/zabbix<Directory "/usr/share/zabbix">? ? Options FollowSymLinks
? ? AllowOverride None
? ? Require all granted
? ? <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 date.timezone Asia/Shanghai
? ? </IfModule></Directory><Directory "/usr/share/zabbix/conf">? ? Require all denied</Directory><Directory "/usr/share/zabbix/include">? ? Require all denied</Directory>
啟動zabbix-server 和zabbix-agent。重啟httpd,,并設(shè)置zabbix-server和zabbix-agent開機自動啟動
systemctl start zabbix-server
systemctl start zabbix-agent
systemctl restart httpd
systemctl restart mariadb
systemctl enable zabbix-server
systemctl enable zabbix-agent? ---- (可選)
三、通過控制臺配置Zabbix
瀏覽器訪問http://ip-address/zabbix
檢查包的完整性和參數(shù)配置
數(shù)據(jù)zabbix數(shù)據(jù)庫名、數(shù)據(jù)庫用戶和密碼,并測試
輸入Server name(可選)
預安裝summary
點擊完成,完成安裝
安裝完成后,重定向到zabbix控制臺登錄頁面. 輸入用戶名和密碼,默認的用戶名和密碼為admin/zabbix.
管理儀表盤頁面如下
四、解決zabbix中文亂碼、漢化
1、在windows中找一個自己喜歡的字體或者去網(wǎng)上下載一個字體
2、將字體上傳至/var/www/html/zabbix/fonts目錄下
3、修改zabbix頁面管理的中文字體設(shè)置
vim?/var/www/html/zabbix/include/defines.inc.php????????#修改以下兩行
define('ZBX_FONT_NAME',?'simfang');
define('ZBX_GRAPH_FONT_NAME',??'simfang');
4、登陸頁面設(shè)置相應用戶的默認語言Administrator—->Users(此處要保證顯示的是用戶,否則顯示的都是用戶組)
5、點擊用戶名進入用戶信息編輯,默認語言選擇簡體中文,然后點擊save保存
6、刷新頁面