不积跬步,无以至千里;不积小流,无以成江海。

zabbix和grafana安装配置

zabbix安装

版本:5.0 LTS

系统:centos 7

数据库:mysql

web server:nginx

1、下载zabbix rpm安装包

# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# yum clean all

2、安装zabbix客户端

# yum install zabbix-server-mysql zabbix-agent -y

3、安装zabbix前端

# yum install centos-release-scl -y

4、修改/etc/yum.repos.d/zabbix.repo

vim /etc/yum.repos.d/zabbix.repo

[zabbix-frontend]下的enable=0改为enable=1

[zabbix-frontend]...enabled=1...

5、安装Zabbix前端软件包。

# yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl -y

6、初始化数据库

# mysql -uroot -ppassword
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;

7、导入zabbix数据到mysql

# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

8、为Zabbix服务器配置数据库

编辑文件 /etc/zabbix/zabbix_server.conf

DBPassword=password
DBHost=127.0.0.1
DBPort=3306
StatsAllowedIP=127.0.0.1

9、为Zabbix前端配置PHP

编辑文件 /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf, 取消注释,并修改端口,并改server_name:本机ip

# listen 80;
# server_name example.com;

10、编辑文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf, add nginx to listen.acl_users directive.

listen.acl_users = apache,nginx

11、然后取消注释,为自己设置正确的时区。

; php_value[date.timezone] = Asia/Shanghai

12、启动zabbix服务和客户端,并且设置为开机自启

# systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
# systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm

13、浏览器登录

Connect to your newly installed Zabbix frontend: http://server_ip_or_name

14、更改zabbix客户端为root用户启动

编辑客户端配置文件/etc/zabbix/zabbix_agentd.conf

Server=127.0.0.1
ServerActive=127.0.0.1
AllowRoot=1			#为了让root启动zabbix客户端。以便于系统命令能正确执行

15、编辑文件 /lib/systemd/system/zabbix-agent.service

User=root
Group=root
  1. 重启加载所有unit单元

    systemctl daemon-reload

  2. 重启zabbix服务

    systemctl restart zabbix-agent.service

16、客户端监控脚本位置

/etc/zabbix/zabbix_agentd.d

新建什么名字都可以,但是要加.conf后缀

文件内容,如:

UserParameter=loginuser,/usr/bin/who | /usr/bin/wc -l			#语法:UserParameter=key,命令
zabbix_agentd -p  #打印出所有zabbix的key值

zabbix客户端安装

清华源地址:https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-agent-5.0.0-1.el7.x86_64.rpm

解压安装

rpm -ivh zabbix-agent-5.0.0-1.el7.x86_64.rpm

更改配置文件

Server=服务器地址
HostName=自己起

grafana安装

清华源地址:(https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/el7/grafana-5.4.2-1.x86_64.rpm)

1、下载

wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/el7/grafana-5.4.2-1.x86_64.rpm

2、安装

yum localinstall grafana-5.4.2-1.x86_64.rpm

3、启动服务并设置开机自启

systemctl start grafana-server
systemctl enable grafana-server

4、grafana默认端口为:3000

5、登录

ip:3000

6、初始用户名密码

admin
admin

7、添加zabbix插件

插件下载地址

https://files.cnblogs.com/files/blogs/678357/alexanderzobnin-grafana-zabbix-v3.4.0-0-g14a7fd4.zip

把插件传到 /var/lib/grafana/plugins/ 目录下

8、启动zabbix插件

设置>plugins>zabbix>enable

9、zabbix关联数据库

设置>Data Sources>

Name:Zabbix
HTTP
URL:http://ip/api_jsonrpc.php
Access:Server(Default)

Zabbix API details
Username:Admin
Password:admin


Save & Test

posted @ 2021-11-19 16:31  |是吴啊|  阅读(379)  评论(0编辑  收藏  举报