zabbix2 centos7建置筆記
1. LAMP
Linux,Apache,MariaDB,PHP
Linux
安裝centos7。
Apache
yum install httpd
跟著回答 “y” 後便會完成安裝, 然後輸入以下指令啟動及設定 Apache 開機自動執行:
systemctl start httpd
systemctl enable httpd
這時 Apache 已經啟動了, 可以在瀏覽器輸入伺服器的位置試試, 例如 http://localhost
MariaDB
執行以下指令安裝 MariaDB:
yum install mariadb-server mariadb
![](https://i.imgur.com/LM7jIy7.png
啟動及設定開機自動執行 MariaDB:
systemctl start mariadb
systemctl enable mariadb
執行以下指令設定 MariaDB 的 root 密碼, 預設是空密碼, 所以建議盡快修改:
設定 mysql
mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
是否更新root使用者密碼或者N
Set root password? [Y/n] y ## Enter Y and press Enter
New password: ## Enter new password
Re-enter new password: ## Enter password again
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
是否要刪除匿名使用者
Remove anonymous users? [Y/n] y ## Enter Y and press Enter
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
是否不允許遠端登入root
Disallow root login remotely? [Y/n] y ## Enter Y and press Enter
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
是否刪除測試資料庫
Remove test database and access to it? [Y/n] y ## Enter Y and press Enter
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
是否重新讀取權限
Reload privilege tables now? [Y/n] y ## Enter Y and press Enter
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
完成後可以用測試一下 MariaDB 是否已經啟動:
mysql -u root -p
image
PHP
yum install php php-mysql php-gd php-pear -y
Test PHP:
testphp.php
vi /var/www/html/testphp.php
加入以下幾行
<?php
phpinfo();
?>
重啟 httpd service:
systemctl restart httpd
2. zabbix
安裝zabbix 2.4
安裝EPEL repository
yum install epel-release
加入zabbix相關源
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
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway
更改zabbix server時區
編輯 /etc/httpd/conf.d/zabbix
:
vi /etc/httpd/conf.d/zabbix.conf
更改時區
php_value date.timezone Asia/Taipei
重啟服務
Restart the httpd
systemctl restart httpd
創建zabbix群組及使用者
在終端上輸入命令
groupadd zabbix
useradd zabbix -g zabbix
創建DB使用者及資料庫
登入 MariaDB
mysql -u root -p
建立zabbix資料庫及zabbix使用者
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.41-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix character set utf8;
Query OK, 1 row affected (0.05 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';
Query OK, 0 rows affected (0.21 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
導入zabbix模板資料庫
mysql -u root -p zabbix < /usr/share/doc/zabbix-server-mysql-2.4.8/create/schema.sql
mysql -u root -p zabbix < /usr/share/doc/zabbix-server-mysql-2.4.8/create/images.sql
mysql -u root -p zabbix < /usr/share/doc/zabbix-server-mysql-2.4.8/create/data.sql
設置zabbix與資料庫連接
編輯 /etc/zabbix/zabbix_server.conf
vi /etc/zabbix/zabbix_server.conf
確認剛剛設定好的資料庫名、使用者、密碼
- DBName
- DBUser
- DBPassword
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
StartPollers=20
StartIPMIPollers=0
StartPollersUnreachable=1
StartTrappers=5
StartPingers=1
StartDiscoverers=5
StartHTTPPollers=1
SNMPTrapperFile=/var/log/snmptt/snmptt.log
CacheSize=8M
StartDBSyncers=4
HistoryCacheSize=32M
TrendCacheSize=4M
ValueCacheSize=32M
Timeout=3
TrapperTimeout=300
UnreachablePeriod=45
UnavailableDelay=60
UnreachableDelay=15
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
編輯php設定檔,進行調優
vi /etc/php.ini
修改php.ini內的數值。
max_execution_time = 600
max_input_time = 600
memory_limit = 256M
post_max_size = 32M
upload_max_filesize = 16M
date.timezone = Asia/Taipei
讓防火牆開啟10050及10051
Adjust Firewall and SELinux settings
Adjust iptables to allow the zabbix ports 10050 and 10051.
firewall-cmd --permanent --add-port=10050/tcp
firewall-cmd --permanent --add-port=10051/tcp
重新啟動防火牆
systemctl restart firewalld
3. 啟動zabbix
用瀏覽器進入http://yourip/zabbix
,開始初步設定zabbix。
[图片上传失败...(image-10130a-1520237351475)]
檢查PHP服務
連線資料庫(輸入user跟passwd)
[图片上传失败...(image-207c3e-1520237351475)]
設定初始名稱
[图片上传失败...(image-2dfde0-1520237351475)]
再次確認所有狀態
設置完畢
[图片上传失败...(image-a844dc-1520237351475)]
成功!zabbix主頁
image常見問題
[問題] zabbix-server沒有啓動成功
image登入zabbix後會出現"Zabbix server is not running: the information displayed may not be current."
如何解決:
查看zabbix-server狀態
systemctl status zabbix-server
[图片上传失败...(image-489a50-1520237351475)]
看到zabbix-server並沒有啓動成功
啓動zabbix-server
systemctl start zabbix-server
啓動後 在看一次zabbix-server狀態
image看到綠色文字的地方已經顯示成功啓動
在刷新一次網頁
[图片上传失败...(image-10679a-1520237351475)]
這樣就沒有提示錯誤,這是比較簡單的除錯方法,如果還不能解決有可能是端口沒有開放導致,可以先netstat
查看端口。
查看zabbix_server端口
netstat -tulpn | grep zabbix_server
image
zabbix-agent Error
如果agent端出錯報紅,可以先參考上方zabbix-server解決方式進行排除。
[图片上传失败...(image-e89d7d-1520237351475)]
可查看zabbix_server及zabbix_agentd的日誌
/var/log/zabbix/zabbix_server.log(是否有啟動錯誤)
/var/log/zabbix/zabbix_agentd.log(是否正常連線)
如假設都資料庫及zabbix_server皆已正常,建議查看Zabbix_server.conf的配置
檔案參考連結(Zabbix_server.conf) 帶新增
[問題] 選單中沒有繁體中文
[图片上传失败...(image-aa5e59-1520237351475)]
修改zabbix源文件
vim /usr/share/zabbix/include/locales.inc.php
找出'zh_TW'
大概在56行的位置將display改成true,如下圖。
'zh_TW' => array('name' => _('Chinese (zh_TW)'), 'display' => true),
image
修改後就可以設定繁體中文了
image
[問題] 圖形 中文亂碼
image修改zabbix 介面無法顯示中文字體的錯誤
如何解決:
下載微軟雅黑字型檔
wget https://github.com/StellarCN/scp_zh/raw/master/fonts/SimHei.ttf
chmod 755 SimHei.ttf
sudo mv SimHei.ttf /usr/share/zabbix/fonts/SIMHEI.ttf
修改配置文件
sudo vim /usr/share/zabbix/include/defines.inc.php
搜尋兩個名稱並修改對應字型
ZBX_GRAPH_FONT_NAME
define('ZBX_GRAPH_FONT_NAME', 'graphfont');
改爲
define('ZBX_GRAPH_FONT_NAME', 'SIMHEI');
ZBX_FONT_NAME
define('ZBX_FONT_NAME', 'graphfont');
改爲
define('ZBX_FONT_NAME', 'SIMHEI');
或也可以直接將原字型graphfont取代成SIMHEI
# 在VIM內輸入
:1,$s/graphfont/SIMHEI/g
在刷新一次圖形頁面
image