試驗環境:騰訊雲主機1C2G
試驗日期:20200508php
第一章 配置ZABBIX服務端
[root@VM_0_3_centos install_zabbix]# yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
[root@VM_0_3_centos install_zabbix]# vi /etc/httpd/conf/httpd.conf
ServerName VM_0_3_centos //修改成主機名
DirectoryIndex index.html index.php //修改
:wqhtml
[root@VM_0_3_centos install_zabbix]# vi /etc/php.ini
date.timezone = PRC //修改成中國時區
:wqmysql
[root@VM_0_3_centos install_zabbix]# systemctl stop firewalld.service
[root@VM_0_3_centos install_zabbix]# setenforce 0
[root@VM_0_3_centos install_zabbix]# systemctl start httpd.service //啓動httpd服務
[root@VM_0_3_centos install_zabbix]# systemctl start mariadb.service //啓動mariadb服務git
[root@VM_0_3_centos install_zabbix]# netstat -anpt|grep 80
tcp6 0 0 :::80 :::* LISTEN 6436/httpd
[root@VM_0_3_centos install_zabbix]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
……忽略N行
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.github
Thanks for using MariaDB!
[root@VM_0_3_centos install_zabbix]# vi /var/www/html/index.php
[root@VM_0_3_centos install_zabbix]# vi /var/www/html/index.php
[root@VM_0_3_centos install_zabbix]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, 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 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
Byeweb
[root@VM_0_3_centos install_zabbix]# vi /var/www/html/index.php
<?phpsql
$link=mysql_connect('172.17.x.x','zabbix','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>數據庫
訪問http:// 172.17.x.x/json
[root@VM_0_3_centos ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.4BUdMY: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-4.0-1.el7 ################################# [100%]
[root@VM_0_3_centos ~]# centos
[root@VM_0_3_centos install_zabbix]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Complete!
[root@VM_0_3_centos ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u zabbix -p -h 172.17.x.x zabbix
Enter password:
用戶是zabbix登錄密碼admin123
[root@VM_0_3_centos ~]#
vi /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBName=zabbix
DBUser=zabbix
DBPassword=admin123
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
vi /etc/httpd/conf.d/zabbix.conf //修改時區
php_value date.timezone Asia/Shanghai
[root@VM_0_3_centos install_zabbix]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@VM_0_3_centos install_zabbix]# systemctl start zabbix-server
[root@VM_0_3_centos install_zabbix]# netstat -anpt | grep zabbix
[root@VM_0_3_centos install_zabbix]# systemctl restart httpd.service
[root@VM_0_3_centos install_zabbix]#
設置中文環境:Administrator-Users-點擊用戶Admin-語言中設置:
第二章 配置ZABBIX代理端
(即被控服務器,如服務器要被本身監控也需安裝)
wget http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.3-1.el7.x86_64.rpm
yum -y install zabbix-agent
vi /etc/zabbix/zabbix_agentd.conf //配置zabbix agent,修改成以下代碼行
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=172.17.x.x
ServerActive=172.17.x.x
Hostname=VM_0_3_centos
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#關閉防火牆
[root@VM_0_3_centos ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@VM_0_3_centos ~]# setenforce 0
setenforce: SELinux is disabled
#啓動、中止、檢查 zabbix_ agentd
systemctl start zabbix-agent.service
systemctl stop zabbix-agent.service
systemctl status zabbix-agent.service
常使用的文件(配置、進程、pid、日誌)如路徑以下
/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.d
/var/run/zabbix/zabbix_agentd.pid
/var/log/zabbix/zabbix_agentd.log
設置開機自啓動
systemctl enable zabbix-agent.service
增長被控主機
配置-主機-建立主機:
常見操做
#查看日誌
tail -100 /var/log/zabbix/zabbix_server.log
tail -100 /var/log/zabbix/zabbixagentd.log
#httpd服務
systemctl start httpd.service
systemctl restart httpd.service
#啓動mariadb服務(MariaDB數據庫管理系統是MySQL的一個分支)
systemctl stop mariadb.service
systemctl start mariadb.service
#zabbix服務
systemctl stop zabbix-server
systemctl start zabbix-server
#啓動、中止、檢查 zabbix agentd
systemctl start zabbix-agent.service
systemctl stop zabbix-agent.service
systemctl status zabbix-agent.service
第三章 Grafana安裝
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-6.3.6-1.x86_64.rpm
yum install initscripts fontconfig
rpm -Uvh grafana-6.3.6-1.x86_64.rpm
注:此前誤裝過老版本(grafana-4.3.1-1.x86_64.rpm),故截圖有removing操做
Grafana配置文件
systemd服務和daemon服務在後臺運行時,都使用文件/etc/sysconfig/grafana-server來設置環境變量,可經過修改garfana-server文件來設置日誌目錄等其餘變量。
#默認日誌文件:/var/log/grafana
#數據庫設置
#缺省配置指定一sqlite3數據庫位於/var/lib/grafana/grafana.db。請在升級前備份這個數據庫。還能夠使用MySQL或Postgres Grafana數據庫。
訪問測試ip:3000
缺省用戶/密碼 admin/admin(注意正式使用務必改密碼強度)
第四章 Grafana Zabbix插件安裝
使用grafana-cli工具安裝
獲取可用插件列表
#grafana-cli plugins list-remote
安裝zabbix插件
#grafana-cli plugins install
alexanderzobnin-zabbix-app
安裝插件完成以後重啓garfana服務
#service grafana-server restart
#使用grafana-zabbix-app源,其中包含最新版本的插件
cd /var/lib/grafana/plugins/
#克隆grafana-zabbix-app插件項目
git clone https://github.com/alexanderzobnin/grafana-zabbix-app
#注:若是沒有git,請先安裝git
yum –y install git
#插件安裝完成重啓garfana服務
service grafana-server restart
#注:經過這種方式,能夠很容器升級插件
cd /var/lib/grafana/plugins/grafana-zabbix-app
git pull
service grafana-server restart
修改圖形爲餅狀,須要下載另外一個grafana-piechart-panel
https://grafana.com/plugins/grafana-piechart-panel
grafana-cli plugins install grafana-piechart-panel
安裝其餘圖形插件
grafana-cli plugins install grafana-clock-panel
#鐘錶形展現
grafana-cli plugins install briangann-gauge-panel
#字符型展現
grafana-cli plugins install natel-discrete-panel
#服務器狀態
grafana-cli plugins install vonage-status-panel
3)訪問grafana,http://localhost:3000,默認用戶名和密碼:admin/admin
第五章 Grafana配置Zabbix數據源
激活zabbix插件
add data source
Name:自定義一個名稱
URL:http://172.17.x.x/zabbix/api_jsonrpc.php #zabbixAPI接口地址
Access: 默認Server(Default)
Username:填寫你zabbix的用戶名(Admin)
Password: 填寫你zabbix的密碼
Trends:勾選
New dashboard
Add query
注:
一、 選定Query、Group(zabbix上配置的)、Host(zabbix上配置的);
二、 Application和item能夠自動帶出;
常見錯誤排查(可選)
1、版本過舊
處置方法:從新安裝對應版本的grafana
[root@VM_0_3_centos ~]# rpm -qa | grep grafana
grafana-4.3.1-1.x86_64
2、依賴包問題
問題現象:
[root@VM_0_3_centos ~]# rpm -Uvh grafana-6.3.6-1.x86_64.rpm
warning: grafana-6.3.6-1.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 24098cb6: NOKEY
error: Failed dependencies:
urw-fonts is needed by grafana-6.3.6-1.x86_64
處置方法:
yum install -y urw-fonts
3、連接ZABBIX異常
處置方法:覈對以下參數
URL:http://172.17.x.x/zabbix/api_jsonrpc.php #zabbixAPI接口地址Access: 默認Server(Default)Username:填寫zabbix的用戶名Password: 填寫zabbix的密碼Trends:勾選