因需重新搭建監控平臺(zabbix)以對公司服務器進行監控,故對Zabbix的編譯安裝過程進行整理。實驗在VPS上進行,操作系統選擇的是CentOS release 6.8 (Final)。因Zabbix的Web界面的後端是用PHP開發,故需額外構建PHP環境,此處選擇的是LEMP環境,相關軟件通過yum安裝。如果要使用LAMP環境,可參考本人Blog https://lempstacker.com/tw/Try-To-Compile-and-Install-Zabbix-3-0-1-From-Source-Code-in-Minimal-CentOS-7/進行安裝、配置。

Zabbix是一款企業級的開源分佈式監控產品,當前穩定版是3.2.1,於2016.09.30釋出,具體見link

重要:以下操作須在root用戶或sudo權限下操作,同時關閉SELinux

Preparation

以下是VPS服務器及LEMP相關軟件版本

item version
Distro CentOS release 6.8 (Final)
Kernel 2.6.32-642.4.2.el6.x86_64

Essencial Packages

以下是一些必要的軟件包,建議安裝

yum clean all
#更新系統但不更新內核
yum update -y --exclude=kernel*
yum install -y vim gcc gcc-c++ bzip2 openssl openssl-devel

#設置時區(Shanghai)
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

vim編輯器的參數配置可參考本人Blog VIM Editor Configuration

關閉SELinux

[[ -f '/etc/selinux/config' ]] && sed -i -r 's@SELINUX=enforcing@SELINUX=disabled@g;s@(SELINUXTYPE=targeted)@#\1@g' /etc/selinux/config

LEMP Environment

Zabbix對相關軟件的版本要求見 2 Requirements,以下為具體的版本

Software version
Nginx 1.10.2
MySQL 5.7.16
PHP 5.6

為節省時間,LEMP環境通過yum安裝。

Nginx 1.10.2

Nginx的默認Web Root路徑是/usr/share/nginx/html/

以下是安裝Nginx的操作命令

#添加Nginx官方Repo
#http://nginx.org/en/linux_packages.html
#https://www.nginx.com/resources/wiki/start/topics/tutorials/install/
tee /etc/yum.repos.d/nginx.repo <<-'EOF'
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
EOF

#安裝Nginx
yum clean all
yum install -y nginx
#啟動Nginx服務
service nginx start
#設置Nginx為開機啟動
chkconfig nginx on

#更改Web Root目錄的owner,group為nginx
chown -R nginx:nginx /usr/share/nginx/html/

Nginx Configuration

Nginx配置文件默認路徑/etc/nginx/,此處只設置PHP解析,詳細的配置可參考本人Blog LEMP Installation and Nginx Optimization

以下是操作命令

cp /etc/nginx/conf.d/default.conf{,bak}
vim /etc/nginx/conf.d/default.conf

#1. location中的index中添加index.php
location / {
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
}

#2. 為php文件設置fastcgi
location ~ \.php$ {
    try_files $uri = 404;
    root   /usr/share/nginx/html;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

#保存退出

#檢測配置文件是否有語法問題
nginx -t
#重新載入Nginx配置文件
nginx -s reload

以下是安裝完成後的測試

[root@Zabbix ~]# nginx -v
nginx version: nginx/1.10.2
[root@Zabbix ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@Zabbix ~]# nginx -s reload
[root@Zabbix ~]#

MySQL 5.7.16

MySQL 5.7MySQL 5.6相比,安裝方式有較大不同。差異較大的是MySQL 5.7使用了Password Validation Plugin,會對檢測用戶設置的密碼是否符合要求。同時root用戶的初始密碼在文件/var/log/mysqld.log中,首次登陸後必須更改用戶密碼才能進行CURD操作。否則會報如下錯誤 >ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement

以下是操作命令

#安裝MySQL官方Repo
rpm -ivh http://repo.mysql.com//mysql57-community-release-el6-9.noarch.rpm
#清空yum緩存
yum clean all
#安裝MySQL社區版,mysql-community-devel必須安裝,否則編譯Zabbix是會提示找不到數據庫
yum install -y mysql-community-server mysql-community-client mysql-community-devel
#啟動MySQL服務
service mysqld start
#設置MySQL服務為開機自動啟動
chkconfig mysqld on

#提取root用戶的臨時密碼(必須先啟動服務)
grep 'temporary password' /var/log/mysqld.log #initialRootPassword
#或
awk '$0~/temporary password/{print $NF}' /var/log/mysqld.log

含初始密碼的數據行格式如下 >2016-10-25T03:27:27.641009Z 1 [Note] A temporary password is generated for root@localhost: rAGMp>f)2dNJ

通過獲取到的初始密碼登入數據庫修改用戶密碼,Password Validation Plugin默認設置為MEDIUM,要求設置的用戶密碼必須如何以下要求: >passwords must contain at least 1 numeric character, 1 lowercase character, 1 uppercase character, and 1 special (nonalphanumeric) character

如果嚴格遵循密碼格式要求,可直接執行ALTER USER語句更改初始密碼。但如果不想設置過於複雜、難記的密碼,可通過如下方式進行設置 1. 通過SELECT PASSWORD()獲取需要設置的密碼的HASH值,然後在中使用mysql_native_password,具體示例見7.5.2 The Password Validation Plugin; 2. 更改MySQL全局環境變量validate_password_policyvalidate_password_length的變量值禁用Password Validation Plugin插件及密碼長度檢測;

以下採用第二種方式

bash> mysql -uroot -p
# 以新密碼 lemp123 為例
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=6;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'lemp123';
#恢復默認值
mysql> set global validate_password_policy=1;
mysql> set global validate_password_length=8;
mysql> flush privileges;
mysql> exit;

可通過創建~/.my.cnf創建實現免密碼登入數據庫

tee ~/.my.cnf <<-'EOF'
[client]
user=root
password=lemp123
EOF

#設置文件權限為400,只有owner擁有讀權限
chmod 400 ~/.my.cnf

至此MySQL安裝成功

[root@Zabbix ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

mysql> exit
Bye
[root@Zabbix ~]#

MySQL Configuration

MySQL的配置文件默認為/etc/my.cnf,此處只進行簡單配置,更改時區、設置字符集等。

cp -pv /etc/my.cnf{,.bak}
vim /etc/my.cnf

#在[mysqld]中添加如下參數
# skip_name_resolve=ON
character_set_server=utf8
collation-server=utf8_general_ci
default-time_zone = '+8:00'

#重其MySQL服務
service mysqld restart

如果要進行詳細的配置,可參考MYSQL AND MARIADB CONFIGURATION FILE TEMPLATE (MY.CNF/MY.INI)或通過Percona的配置文件生成工具在線生成PERCONA CONFIGURATION WIZARD FOR MYSQL

PHP 5.6

PHP選擇5.6版本,通過EPELREMI兩個yum源安裝,PHP通過php-fpm管理。

以下是操作命令

#安裝yum源
yum install -y epel-release
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

#啟用/etc/yum.repos.d/remi.repo中[remi-php56]部分中的enabled為1
# vim /etc/yum.repos.d/remi.repo
sed -i -r "s@enabled=1@enabled=0@g;/\[remi-php56\]/,/\[remi-test\]/ s@enabled=0@enabled=1@" /etc/yum.repos.d/remi.repo

#安裝運行Zabbix Web界面所需的PHP包
yum install -y --enablerepo=remi php php-fpm php-gd php-bcmath php-ctype php-libxml php-xmlreader php-xmlwriter php-session php-net-socket php-mbstring php-gettext php-ldap php-mysqlnd

#可選
# yum install -y --enablerepo=remi php-common php-mcrypt php-xml php-pecl-apc php-cli php-pear php-pdo php-ctype php-devel php-opcache

PHP Configuration

PHP配置文件默認路徑/etc/php.ini,php-fpm配置文件默認路徑/etc/php-fpm.d/www.conf

在Zabbix官方文檔 PHP configuration for Zabbix frontend中,建議的PHP設置是

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 always_populate_raw_post_data -1
# php_value date.timezone Europe/Riga
/etc/php.ini
cp -p /etc/php.ini{,.bak}
# vim /etc/php.ini

# max_execution_time = 300
sed -i -r "/^max_execution_time/ s@(max_execution_time = )[0-9]+@\1300@" /etc/php.ini
# memory_limit = 128M
sed -i -r "/^memory_limit/ s@(memory_limit = )[0-9]+(M)@\1128\2@" /etc/php.ini
# post_max_size = 16M
sed -i -r "/^post_max_size/ s@(post_max_size = )[0-9]+(M)@\116\2@" /etc/php.ini
# upload_max_filesize = 2M
sed -i -r "/^upload_max_filesize/ s@(upload_max_filesize = )[0-9]+(M)@\12\2@" /etc/php.ini
# max_input_time = 300
sed -i -r "/^max_input_time/ s@(max_input_time = )[0-9]+@\1300@" /etc/php.ini
# always_populate_raw_post_data = -1
sed -i -r "/^always_populate_raw_post_data/d; /^;always_populate_raw_post_data/ a\always_populate_raw_post_data = -1" /etc/php.ini
# date.timezone = Asia/Shanghai
sed -i -r "/^date.timezone =/d; /^;date.timezone =/ a\date.timezone = Asia/Shanghai" /etc/php.ini
# #關閉Nginx文件類型錯誤解析  cgi.fix_pathinfo=0
sed -i -r "/^cgi.fix_pathinfo/d; /^;cgi.fix_pathinfo=1/ a\cgi.fix_pathinfo=0" /etc/php.ini
;cgi.fix_pathinfo=1
# expose_php = Off
sed -i -r "/^expose_php/ s@(expose_php = )On@\1Off@" /etc/php.ini
/etc/php-fpm.d/www.conf
cp /etc/php-fpm.d/www.conf{,bak}
# vim /etc/php-fpm.d/www.conf

# listen = /var/run/php-fpm/php-fpm.sock
sed -i -r -e "/^listen = 127.0.0.1:9000/ s@(listen = 127.0.0.1:9000)@;\1@" -e "/^listen = \/var\/run\/php-fpm\/php-fpm.sock/d" -e "/^;listen = / a\listen = /var/run/php-fpm/php-fpm.sock" /etc/php-fpm.d/www.conf

#如果不指定為nginx,無法正常監聽php-fpm.sock
# listen.owner = nginx
sed -i -r "/^listen.owner =/d; /^;listen.owner = / a\listen.owner = nginx" /etc/php-fpm.d/www.conf
# listen.group = nginx
sed -i -r "/^listen.group =/d; /^;listen.group = / a\listen.group = nginx" /etc/php-fpm.d/www.conf
# listen.mode = 0660
sed -i -r "/^listen.mode =/d; /^;listen.mode = / a\listen.mode = 0660" /etc/php-fpm.d/www.conf
# user = nginx
sed -i -r -e "/^user = apache/ s@(user = apache)@;\1@" -e "/^user = nginx/d" -e "/^;user = / a\user = nginx" /etc/php-fpm.d/www.conf
# group = nginx
sed -i -r -e "/^group = apache/ s@(group = apache)@;\1@" -e "/^group = nginx/d" -e "/^;group = / a\group = nginx" /etc/php-fpm.d/www.conf

配置文件更改完成後,啟動/重啟php-fpm服務

# 重其php-fpm服務
service php-fpm restart
# 設置php-fpm為開機自動啟動
chkconfig php-fpm on

Zabbix 3.2

Download & Decompression

Zabbix的下載頁為 http://www.zabbix.com/download.php,往下滑動頁面到Zabbix Sources部分即可看到源碼包的下載列表。Zabbix 3.2.1的下載鏈接為

http://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.1/zabbix-3.2.1.tar.gz

將該源碼包下載保存到/usr/local/src目錄

# 安裝Zabbix需要的依賴包
yum -y install libxml2-devel libcurl-devel net-snmp-devel libssh2-devel curl curl-devel
curl -# -o /usr/local/src/zabbix.tar.gz http://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.1/zabbix-3.2.1.tar.gz
[[ -d '/tmp/zabbix' ]] && rm -rf /tmp/zabbix || mkdir -pv /tmp/zabbix
# 解壓縮到指定目錄 --strip-components http://www.cnblogs.com/bootoo/p/4678849.html
tar xf /usr/local/src/zabbix.tar.gz -C /tmp/zabbix --strip-components 1

Comiling & Installing

進入源碼包目錄後使用./configure進行參數設置,須注意: * 只安裝zabbix_server,則只指定--enable-server * 只安裝zabbix_agentd,則只指定--enable-agent * 同時安裝二者,則同時指定--enable-server--enable-agent

參數設置 * 二進制可執行文件路徑設置為/usr/local * 配置文件路徑設置為/etc/zabbix

以下是具體命令

cd /tmp/zabbix
# 注意--enable-server --enable-agent
./configure --prefix=/usr/local --sysconfdir=/etc/zabbix --enable-server --enable-agent --with-ssh2 --with-openssl --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
#使用-j參數,進行多線程編譯,加快編譯速度,數值根據自身情況設置
make -j 4 && make install

編譯安裝完成後可看到

[root@Zabbix zabbix]# ls -lh /usr/local/{bin,sbin}/zabbix_*
-rwxr-xr-x 1 root root 428K Oct 25 14:58 /usr/local/bin/zabbix_get
-rwxr-xr-x 1 root root 489K Oct 25 14:58 /usr/local/bin/zabbix_sender
-rwxr-xr-x 1 root root 1.2M Oct 25 14:58 /usr/local/sbin/zabbix_agentd
-rwxr-xr-x 1 root root 3.9M Oct 25 14:58 /usr/local/sbin/zabbix_server
[root@Zabbix zabbix]#

Create Zabbix User & Group

在系統中創建zabbix用戶及用戶組,並設置密碼為zabbix

#創建系統用戶組
groupadd -r zabbix
#創建系統用戶,執行shell為/bin/false,禁止使用其它服務
useradd -M -r -g zabbix -s /bin/false zabbix
#設置密碼為`zabbix`
passwd zabbix
或
echo 'zabbix' | passwd --stdin zabbix

以下是使用到的useradd的選項

option explanation
-M, –no-create-home do not create the user’s home directory
-r, –system create a system account
-g, –gid GROUP name or ID of the primary group of the new account
-s, –shell SHELL login shell of the new account

Create Database & Database User

在MySQL中創建名為zabbix的數據庫,並且授權只有名為zabbix的用戶在主機localhost上才能訪問。

執行mysql -uroot -pmysql(設置了文件~/.my.cnf)後執行如下操作

-- 創建名為zabbix的數據庫容器,強烈建議使用此名,否則需要更改很多配置文件的相關默認設置,導入數據庫時也會報錯
create database if not exists zabbix default character set=utf8 collate=utf8_general_ci;
set global validate_password_policy=0;
set global validate_password_length=6;
-- 創建數據庫登錄帳號zabbix@localhost,如果是遠程主機,可將`localhost`替換為具體的IP地址
create user zabbix@localhost identified by 'zabbix';
grant all on zabbix.* to zabbix@localhost;
set global validate_password_policy=1;
set global validate_password_length=8;
-- 刷新權限表
flush privileges;
-- 退出數據庫登錄
exit

Import Zabbix SQL

將Zabbix源碼包中的SQL文件導入到MySQL數據庫服務器中

cd /tmp/zabbix
# 進入數據庫文件所在路徑
cd database/mysql
# 導入數據庫
mysql -uzabbix -pzabbix -D zabbix < schema.sql
# 如果只是使用`Zabbix proxy`,只需導入schema.sql即可
mysql -uzabbix -pzabbix -D zabbix < images.sql
mysql -uzabbix -pzabbix -D zabbix < data.sql

導入的數據表如下

mysql> use zabbix
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| groups                     |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| httpstep                   |
| httpstepitem               |
| httptest                   |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| items                      |
| items_applications         |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_url         |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| task                       |
| task_close_problem         |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
+----------------------------+
127 rows in set (0.00 sec)

mysql>

Zabbix Configuration

Zabbix配置文件路徑為/etc/zabbix/ * /etc/zabbix/zabbix_agentd.conf * /etc/zabbix/zabbix_server.conf

備份配置文件

cp -p /etc/zabbix/zabbix_agentd.conf{,.bak}
cp -p /etc/zabbix/zabbix_server.conf{,.bak}
# 或
for i in /etc/zabbix/*.conf; do cp -p ${i}{,.bak}; done

注意:因編譯安裝後,Zabbix的日誌路徑在目錄/tmp下,建議更改,此處更改為/var/log/zabbix

# 創建目錄
mkdir -pv /var/log/zabbix
# 更改owner, group為zabbix
chown -R zabbix:zabbix /var/log/zabbix

/etc/zabbix/zabbix_server.conf

參考自官方文檔 Database configuration for Zabbix server

# LogFile=/var/log/zabbix/zabbix_server.log
sed -i -r -e "/^LogFile=\/tmp\/zabbix_server.log/ s@(LogFile=\/tmp\/zabbix_server.log)@#\1@" -e "/^LogFile=\/var\/log\/zabbix\/zabbix_server.log/d" -e "/^#LogFile=/ a\LogFile=/var/log/zabbix/zabbix_server.log" /etc/zabbix/zabbix_server.conf

# DBName=zabbix 默認是zabbix

# DBUser=zabbix 默認是zabbix

# DBPassword=zabbix 如果未設置密碼,可註釋此行
sed -i -r "/^DBPassword=/d; /^# DBPassword=/ a\DBPassword=zabbix" /etc/zabbix/zabbix_server.conf

# DBHost=localhost

#服務器IP,如果監聽本機無需更改,如果有固定IP可指定
# ListenIP=127.0.0.1

#如果在MySQL配置文件中更改了sock路徑或prot端口,則須指定具體路徑
# DBSocket=/tmp/mysql.sock 此處是/var/lib/mysql/mysql.sock
sed -i -r "/^DBSocket=/d; /^# DBSocket=/ a\DBSocket=\/var\/lib\/mysql\/mysql.sock" /etc/zabbix/zabbix_server.conf

# DBPort=3306 如果是默認3306端口則無需更改


# 獨立配置文件路徑(可選)
# 在Include=後
# Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf
# Include=/etc/zabbix/zabbix_server.conf.d/*.conf
sed -i -r -e "/^Include=\/etc\/zabbix\/zabbix/d" -e "/^# Include=$/ a\Include=/etc/zabbix/zabbix_server.conf.d/*.conf" /etc/zabbix/zabbix_server.conf

/etc/zabbix/zabbix_agentd.conf

#LogFile=/tmp/zabbix_agentd.log
# LogFile=/var/log/zabbix/zabbix_agentd.log
sed -i -r -e "/^LogFile=\/tmp\/zabbix_agentd.log/ s@(LogFile=\/tmp\/zabbix_agentd.log)@#\1@" -e "/^LogFile=\/var\/log\/zabbix\/zabbix_agentd.log/d" -e "/^#LogFile=/ a\LogFile=/var/log/zabbix/zabbix_agentd.log" /etc/zabbix/zabbix_agentd.conf

# 允許執行來自Zabbix Server的遠程命令
# EnableRemoteCommands=1
sed -i -r "/^EnableRemoteCommands=/d; /^# EnableRemoteCommands=/ a\EnableRemoteCommands=1" /etc/zabbix/zabbix_agentd.conf

# 以下參數如果在本地主機,無需更改,如果Server是單獨主機,須指定為具體的Server IP
# Server=127.0.0.1     Zabbix servers的ip 被動
sed -i -r "/^Server=/d; /^# Server=127.0.0.1$/ a\Server=127.0.0.1" /etc/zabbix/zabbix_agentd.conf

# 假若Zabbix servers的IP是192.168.88.88
# sed -i -r -e "/^Server=127.0.0.1$/ s@(Server=127.0.0.1)@# \1@" -e "/^Server=/d" -e "/^# Server=127.0.0.1$/ a\Server=192.168.88.88" /etc/zabbix/zabbix_agentd.conf

# ServerActive=127.0.0.1    Zabbix servers的ip 主動
sed -i -r "/^ServerActive=/d; /^# ServerActive=127.0.0.1$/ a\ServerActive=127.0.0.1" /etc/zabbix/zabbix_agentd.conf

# 假若Zabbix servers的IP是192.168.88.88
# sed -i -r -e "/^ServerActive=127.0.0.1$/ s@(ServerActive=127.0.0.1)@# \1@" -e "/^ServerActive=/d" -e "/^# ServerActive=127.0.0.1$/ a\ServerActive=127.0.0.1" /etc/zabbix/zabbix_agentd.conf

# sed -i -r -e "/^ServerActive=127.0.0.1$/ s@(ServerActive=127.0.0.1)@# \1@" -e "/^ServerActive=/d" -e "/^# ServerActive=127.0.0.1$/ a\ServerActive=192.168.88.88" /etc/zabbix/zabbix_agentd.conf

#必須與zabbix server上配置的Hostname相同
# Hostname=Zabbix server

# 獨立配置文件路徑(可選)
# 在Include=後添加
# Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf
sed -i -r -e "/^Include=\/etc\/zabbix\/zabbix/d" -e "/^# Include=$/ a\Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf" /etc/zabbix/zabbix_agentd.conf

注意: 參數Server必須設置,否則會報如下錯誤 >Starting Zabbix Agent: zabbix_agentd [22810]: ERROR: StartAgents is not 0, parameter Server must be defined

SysVinit

CentOS 6.x 使用SysVinit管理服務,CentOS 7.x 開始使用Systemd管理服務。可對服務進行啟動、關閉、狀態查詢,也可設置服務開機啟動。因此處是在CentOS 6.8上安裝,故只添加SysVinit支持。如果想在CentOS 7中設置Systemd支持,可參考本人Blog Try To Compile and Install Zabbix 3.0.1 From Source Code in Minimal CentOS 7

相關文件在源碼包的misc/init.d目錄中

cd /tmp/zabbix
cd misc/init.d/fedora/core5
# CentOS 與 Fedora同屬於RedHat系
cp -v zabbix_{server,agentd} /etc/init.d/

#賦予執行權限
chmod +x /etc/init.d/zabbix_{server,agentd}

#啟動服務
service zabbix_server start
service zabbix_agentd start

#設為開機啟動
chkconfig zabbix_server on
chkconfig zabbix_agentd on

#檢查
chkconfig --list

Web Interface Configuration

PHP文件在源碼包中的frontends/php目錄下,Nginx的默認Web Root路徑是/usr/share/nginx/html/,因已經在Nginx中設置了PHP解析,故只需將frontends/php/的文件複製到Nginx的Web Root目錄下即可。

此處將文件複製到目錄/usr/local/nginx/html/zabbix

cd /tmp/zabbix

# 創建名為zabbix的目錄
[[ ! -d /usr/local/nginx/html/zabbix ]] && (umask 027; mkdir -pv /usr/share/nginx/html/zabbix)

#更改owner, group為nginx
# chown -R nginx:nginx /usr/share/nginx/html/

# 遞歸複製文件到指定目錄中
cp -r frontends/php/* /usr/share/nginx/html/zabbix

# 更改owner, group為nginx
chown -R nginx:nginx /usr/share/nginx/html/zabbix

# (重要)更改owner, group為nginx
chown -R nginx:nginx /var/lib/php/session

注意: 如果不更改/var/lib/php/session的owner、group,在Zabbix Web界面中進行初始設置時無法點擊下一步(Next)。

操作完成後,在瀏覽器URL地址欄中輸入

http://localhost/zabbix

或指定IP(159.203.110.223)

http://159.203.110.223/zabbix

即可進入Zabbix的Installation界面,URL自動跳轉至

http://159.203.110.223/zabbix/setup.php

默認登錄用戶名是Admin,密碼是zabbix

Zabbix frontend is ready! The default user name is Admin, password zabbix. – Installing Zabbix web interface

Language Setting

Zabbix Web Interface默認是英文界面,版本3.2.1已經默認啟用 *簡體中文*,在Administration->Users中點擊需要設置語言的用戶名(位於alias列),找到Language點擊下拉框選擇Chinese(zh_CN)。但如果想使用 正體中文 或其它未列出的語言,則可在Zabbix的Web文件/include目錄下的文件locales.inc.php中進行設置

/**
 * Returns a list of all used locales.
 *
 * Each locale has the following properties:
 * - name       - the full name of the locale
 * - display    - whether to display the locale in the frontend
 *
 * @return array    an array of locales with locale codes as keys and arrays as values
 */
function getLocales() {
	return [
		'en_GB' => ['name' => _('English (en_GB)'),	'display' => true],
		'en_US' => ['name' => _('English (en_US)'),	'display' => true],
		'bg_BG' => ['name' => _('Bulgarian (bg_BG)'),	'display' => false],
		'zh_CN' => ['name' => _('Chinese (zh_CN)'),	'display' => true],
		'zh_TW' => ['name' => _('Chinese (zh_TW)'),	'display' => false],
		'cs_CZ' => ['name' => _('Czech (cs_CZ)'),	'display' => true],
		'nl_NL' => ['name' => _('Dutch (nl_NL)'),	'display' => false],
		'fi_FI' => ['name' => _('Finnish (fi_FI)'),	'display' => false],
		'fr_FR' => ['name' => _('French (fr_FR)'),	'display' => true],
		'ka_GE' => ['name' => _('Georgian (ka_GE)'),	'display' => false],
		'de_DE' => ['name' => _('German (de_DE)'),	'display' => false],
		'el_GR' => ['name' => _('Greek (el_GR)'),	'display' => false],
		'he_IL' => ['name' => _('Hebrew (he_IL)'),	'display' => false],
		'hu_HU' => ['name' => _('Hungarian (hu_HU)'),	'display' => false],
		'id_ID' => ['name' => _('Indonesian (id_ID)'),	'display' => false],
		'it_IT' => ['name' => _('Italian (it_IT)'),	'display' => true],
		'ko_KR' => ['name' => _('Korean (ko_KR)'),	'display' => true],
		'ja_JP' => ['name' => _('Japanese (ja_JP)'),	'display' => true],
		'lv_LV' => ['name' => _('Latvian (lv_LV)'),	'display' => false],
		'lt_LT' => ['name' => _('Lithuanian (lt_LT)'),	'display' => false],
		'fa_IR' => ['name' => _('Persian (fa_IR)'),	'display' => false],
		'pl_PL' => ['name' => _('Polish (pl_PL)'),	'display' => true],
		'pt_BR' => ['name' => _('Portuguese (pt_BR)'),	'display' => true],
		'pt_PT' => ['name' => _('Portuguese (pt_PT)'),	'display' => false],
		'ro_RO' => ['name' => _('Romanian (ro_RO)'),	'display' => false],
		'ru_RU' => ['name' => _('Russian (ru_RU)'),	'display' => true],
		'sk_SK' => ['name' => _('Slovak (sk_SK)'),	'display' => true],
		'es_ES' => ['name' => _('Spanish (es_ES)'),	'display' => false],
		'sv_SE' => ['name' => _('Swedish (sv_SE)'),	'display' => false],
		'tr_TR' => ['name' => _('Turkish (tr_TR)'),	'display' => false],
		'uk_UA' => ['name' => _('Ukrainian (uk_UA)'),	'display' => true],
		'vi_VN' => ['name' => _('Vietnamese (vi_VN)'),	'display' => false]
	];
}

zh_TW的display選項設置為true後,重新登錄系統即可進行語言設置。

Web Interface Snapshots

Installation

Enable Server

User Language Setting

Graphs

References

Change Logs

  • 2016.10.25 17:42 Tue Asia/Shanghai
    • 初稿完成

  • Note Time: 2016.10.25 17:42 Tue
  • Note Location: Asia/Shanghai
  • Writer: lempstacker