试验环境:腾讯云主机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:勾选