一、安裝Zabbix 3.0前說明
Zabbix伺服器運作的環境為Linux(UNIX)+PHP+Web Service+DataBase,這裡的Web Service 可以為Nginx為例,而DataBase 可以為MySQL為例,下面以CentOS6.4_X64 為例介紹如何安裝Zabbix 3.0。
系統環境
CentOS 6.5
PHP 7.0
Nginx 1.10.0
MySQL 5.5
Zabbix 3.0
首先要關閉防火牆和SELINUX
$ service iptbales stop
$ setenforce 0
1
2
$serviceiptbalesstop
$setenforce0
順便把EPEL源添加進來
# CentOS 6 / RHEL 6
$ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# CentOS 7 / RHEL 7
$ rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
1
2
3
4
5
# CentOS 6 / RHEL 6
$rpm-ivhhttp://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# CentOS 7 / RHEL 7
$rpm-ivhhttp://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
二、安裝配置PHP
安裝Zabbix 3.0需要PHP版本大于5.4,這裡我直接使用PHP 7.0即可。但是這裡我們需要使用到REMI源,Remi repository是包含最新版本PHP和MySQL包的Linux源,由Remi提供維護。有個這個源之後,使用YUM安裝或更新PHP、MySQL較新版本了。
安裝最新的Remi源自動安裝檔案
# CentOS 6 / RHEL 6
$ yum install http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# CentOS 7 / RHEL 7
$ yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
1
2
3
4
5
# CentOS 6 / RHEL 6
$yuminstallhttp://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# CentOS 7 / RHEL 7
$yuminstallhttp://rpms.famillecollet.com/enterprise/remi-release-7.rpm
安裝PHP相關元件
$ yum --enablerepo=remi,remi-php70 install php php-fpm php-common php-devel php-mysqlnd php-mbstring php-mcrypt \
php-mysql php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-bcmath php-opcache
1
2
$yum--enablerepo=remi,remi-php70installphpphp-fpmphp-commonphp-develphp-mysqlndphp-mbstringphp-mcrypt\
php-mysqlphp-gdphp-xmlphp-mbstringphp-ldapphp-pearphp-xmlrpcphp-bcmathphp-opcache
檢視PHP版本
$ php -v
PHP 7.0.9 (cli) (built: Jul 20 2016 18:08:08) ( NTS )
1
2
$php-v
PHP7.0.9(cli)(built:Jul20201618:08:08)(NTS)
啟動PHP-FPM
$ service php-fpm start
1
$servicephp-fpmstart
三、安裝配置MySQL
1)安裝MySQL 5.6
首先從MySQL官方網站下載下傳YUM源,位址:http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
這裡我選擇MySQL 5.6的源進行安裝MySQL 5.6,手動添加一個YUM源。
$ cat /etc/yum.repos.d/mysql.repo
1
$cat /etc/yum.repos.d/mysql.repo
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=0
1
2
3
4
5
6
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL5.6CommunityServer
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=0
安裝啟動配置MySQL
$ yum install mysql-community-server mysql-community-devel mysql-community-client mysql-community-common
$ service mysqld start
$ mysql_secure_installation
1
2
3
$yuminstallmysql-community-servermysql-community-develmysql-community-clientmysql-community-common
$servicemysqldstart
$mysql_secure_installation
當然你也可以使用REMI安裝MySQL(版本可能比較低)
$ yum --enablerepo=remi install mysql-server mysql-client mysql-common mysql-connector-odbc mysql-devel mysql
$ service mysqld start
$ mysql_secure_installation
1
2
3
$yum--enablerepo=remiinstallmysql-servermysql-clientmysql-commonmysql-connector-odbcmysql-develmysql
$servicemysqldstart
$mysql_secure_installation
2)配置MySQL
mysql> create database zabbix charset utf8;
mysql> grant all on zabbix.* to [email protected]'%' identified by 'zabbix';
mysql> grant all on zabbix.* to [email protected]'localhost' identified by 'zabbix';
mysql> flush privileges;
1
2
3
4
mysql>createdatabasezabbixcharsetutf8;
mysql>grantallonzabbix.*[email protected]'%'identifiedby'zabbix';
mysql>grantallonzabbix.*[email protected]'localhost'identifiedby'zabbix';
mysql>flushprivileges;
四、安裝配置Nginx
說明一下,Nginx在系統YUM源中沒有提供,就算使用EPEL源版本也是非常低,是以這裡直接使用Nginx官方源。
$ cat /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
1
2
3
4
5
6
$cat/etc/yum.repos.d/nginx.repo
[nginx]
name=nginxrepo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
直接進行YUM安裝Nginx即可
$ yum install nginx
$ service nginx start
$ nginx -v
nginx version: nginx/1.10.1
1
2
3
4
$yuminstallnginx
$servicenginxstart
$nginx-v
nginxversion:nginx/1.10.1
五、安裝配置Zabbix
1)先安裝Zabbix需要的插件
$ yum install libdbi-dbd-mysql net-snmp-devel curl-devel net-snmp libcurl-devel libxml2-devel
1
$yuminstalllibdbi-dbd-mysqlnet-snmp-develcurl-develnet-snmplibcurl-devellibxml2-devel
2)安裝Zabbix就需要導入Zabbix官方的源了,官方版本比較新,其餘的系統自帶源或EPEL源的Zabbix都很舊,選項源時找好對應的系統版本号以及架構平台。
$ rpm -Uvh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
1
$rpm-Uvhhttp://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
3)有了源之後使用YUM安裝即可(yum install zabbix-server),但這裡我使用源碼安裝Zabbix 3.0。先把編譯庫安裝一下。
$ yum groupinstall "Development tools" "Compatibility libraries"
1
$yumgroupinstall"Development tools""Compatibility libraries"
4)接下來添加使用者後就進行編譯安裝了,Zabbix安裝包自行官網下載下傳即可。
$ groupadd zabbix
$ useradd -g zabbix zabbix
$ tar xf zabbix-3.0.4.tar.gz
$ cd zabbix-3.0.4
$ ./configure --prefix=/usr/local/zabbix-server --enable-server --with-mysql --with-net-snmp --with-libcurl --with-libxml2
$ make && make install
1
2
3
4
5
6
$groupaddzabbix
$useradd-gzabbixzabbix
$tarxfzabbix-3.0.4.tar.gz
$cdzabbix-3.0.4
$./configure--prefix=/usr/local/zabbix-server--enable-server--with-mysql--with-net-snmp--with-libcurl--with-libxml2
$make&&makeinstall
5)安裝完後就進行資料庫檔案導入操作
$ cd /root/zabbix-3.0.4/database/mysql
1
$cd/root/zabbix-3.0.4/database/mysql
$ mysql -uzabbix -p zabbix < schema.sql
$ mysql -uzabbix -p zabbix < images.sql
$ mysql -uzabbix -p zabbix < data.sql
1
2
3
$mysql-uzabbix-pzabbix
$mysql-uzabbix-pzabbix
$mysql-uzabbix-pzabbix
6)編輯配置檔案
$ vim /usr/local/zabbix-server/etc/zabbix_server.conf
ListenPort=10051
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
ListenIP=0.0.0.0
1
2
3
4
5
6
7
$vim/usr/local/zabbix-server/etc/zabbix_server.conf
ListenPort=10051
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
ListenIP=0.0.0.0
7)啟動Zabbix
/usr/local/zabbix-server/sbin/zabbix_server -c /usr/local/zabbix-server/etc/zabbix_server.conf
1
/usr/local/zabbix-server/sbin/zabbix_server-c/usr/local/zabbix-server/etc/zabbix_server.conf
8)檢視監聽端口
$ netstat -nplt | grep zabbix_server
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 13677/zabbix_server
1
2
$netstat-nplt|grepzabbix_server
tcp 0 00.0.0.0:10051 0.0.0.0:* LISTEN 13677/zabbix_server
9)拷貝zabbix應用到Nginx根目錄
$ rm -fr /usr/share/nginx/html/*
$ cd /root/zabbix-3.0.4/frontends/php/
$ cp -a . /usr/share/nginx/html/
$ chown -R nginx.nginx /usr/share/nginx/html/*
1
2
3
4
$rm-fr/usr/share/nginx/html/*
$cd/root/zabbix-3.0.4/frontends/php/
$cp-a./usr/share/nginx/html/
$chown-Rnginx.nginx/usr/share/nginx/html/*
10)配置PHP
$ cat /etc/php.ini
date.timezone = Asia/Shanghai
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
1
2
3
4
5
$cat/etc/php.ini
date.timezone=Asia/Shanghai
post_max_size=16M
max_execution_time=300
max_input_time=300
這幾個值必須要改,不然zabbix檢測時過不去,就會報這樣的錯誤:Minimum required limit on input parse time for PHP scripts is 300 (configuration option “max_input_time”)。
11)配置Nginx
$ cat /etc/nginx/conf.d/default.conf
1
$cat/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log error;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
server{
listen80;
server_namelocalhost;
#charset koi8-r;
access_log/var/log/nginx/access.logmain;
error_log/var/log/nginx/error.logerror;
location/{
root/usr/share/nginx/html;
indexindex.htmlindex.htmindex.php;
}
# redirect server error pages to the static page /50x.html
error_page500502503504/50x.html;
location=/50x.html{
root/usr/share/nginx/html;
}
location~\.php${
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
$ service nginx restart
1
$servicenginxrestart
好,當這些都安裝配置完了并且都成功啟動了後就可以用浏覽器通路本機IP,并按照提示安裝Zabbix即可。
打開浏覽器後會看到如下界面,首先會檢查Zabbix需要的環境,如果都是OK狀态,那麼就沒有什麼問題了,可以繼續下一步。如果檢查沒有通過就要看看缺少什麼,然後安裝即可。

檢查都通過後,就進入到下面這個界面,選擇資料庫及相關配置資訊,其中有資料庫位址、端口、使用者名及密碼。
在操作連接配接資料庫時可能會出現
The frontend does not match Zabbix database. Current database version (mandatory/optional): 2050061/2050061. Required mandatory version: 3000000. Contact your system administrator.
遇到這種問題需要删除一下建立的zabbix庫,然後在從新導入zabbix庫檔案。
資料庫資訊都填寫正确之後,就會進入到下一步,如下圖:
這裡出現權限報錯,将配置檔案下載下傳下來儲存到/usr/share/nginx/html/conf/zabbix.conf.php檔案中。如果手動寫入配置檔案之後如果還報錯,可以忽略,将浏覽器關閉并重新打開連接配接即可。登入賬号Admin,登入密碼zabbix。
手動寫入配置
$ cat /usr/share/nginx/html/conf/zabbix.conf.php
1
$cat/usr/share/nginx/html/conf/zabbix.conf.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 = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = '';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 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='localhost';
$ZBX_SERVER_PORT='10051';
$ZBX_SERVER_NAME='';
$IMAGE_FORMAT_DEFAULT=IMAGE_FORMAT_PNG;
?>
完成上面操作就安裝完了,下面就進入到了Zabbix 3.0主界面。
進來之後的第一件事就是看看是否支援中文以及可以調整主題。
我這裡是編譯安裝的,看了一下支援中文顯示。如果你的系統預設不支援的話,就需要開啟中文支援了。
六、開啟Zabbix對中文支援
如果你安裝的zabbix預設把對中文的支援給關閉了,我們需要修改zabbix的php源檔案. 修改站點根目錄下include/locales.inc.php檔案。
$ cat /usr/share/nginx/html/include/locales.inc.php
function getLocales() {
return array(
'en_GB' => array('name' => _('English (en_GB)'), 'display' => true),
'en_US' => array('name' => _('English (en_US)'), 'display' => true),
'bg_BG' => array('name' => _('Bulgarian (bg_BG)'), 'display' => true),
'zh_CN' => array('name' => _('Chinese (zh_CN)'), 'display' => true),
//原本這裡為false,請改為true
...........代碼省略掉........
1
2
3
4
5
6
7
8
9
$cat/usr/share/nginx/html/include/locales.inc.php
functiongetLocales(){
returnarray(
'en_GB'=>array('name'=>_('English (en_GB)'),'display'=>true),
'en_US'=>array('name'=>_('English (en_US)'),'display'=>true),
'bg_BG'=>array('name'=>_('Bulgarian (bg_BG)'),'display'=>true),
'zh_CN'=>array('name'=>_('Chinese (zh_CN)'),'display'=>true),
//原本這裡為false,請改為true
...........代碼省略掉........
七、安裝zabbix_agentd
上面以及提供了zabbix 3.0的YUM源,我們這裡可以用來直接安裝3.0的zabbix_agentd。
$ yum install zabbix-agent
$ service zabbix-agent start
1
2
$yuminstallzabbix-agent
$servicezabbix-agentstart
安裝并啟動完後,就可以去zabbix web頁面開啟本機監控了。
如果是監控其他主機,一般在agent安裝完後需要簡單調整一下幾個配置項在zabbix-agent的主配置檔案中。
$ cat /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
1
2
3
4
$cat/etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbixserver
其中Server和ServerActive都指定zabbix伺服器的IP位址,不同的是,前者是被動後者是主動。也就是說Server這個配置是用來允許127.0.0.1這個ip來我這取資料。而serverActive的127.0.0.1的意思是用戶端主動送出資料給他。
八、Zabbix Proxy安裝介紹
zabbix server與proxy需要資料庫,agent不需要。尤其要注意的是proxy隻需要導入一個sql檔案,而server一共要導入3個sql檔案。proxy隻需要導入一個表結構即可其餘的操作跟安裝server端一樣。
如果您覺得本站對你有幫助,那麼可以支付寶掃碼捐助以幫助本站更好地發展,在此謝過。