Centos7部署zabbix

不多介绍,直接上干货

 1.yum源换成阿里源

 可以参考这篇文章

(2条消息) centos7阿里云换源_怡雪~的博客-CSDN博客

2.配置基础环境
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vi /etc/selinux/config
修改为SELINUX=disabled
3.配置yum仓库

[root@localhost ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
获取https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.iQp5pl: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:zabbix-release-4.0-1.el7         ################################# [100%]

[root@localhost ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
4.安装zabbix-server服务端,以及数据库

#zabbix-server-mysql 以mysql作为存储开发的zabbix-server服务端程序
#zabbix-web-mysql php核心程序,zabbix-UI页面,也是以mysql为存储版本
#zabbix-agent 采集客户端数据的核心程序,自己监控自己
#mariadb-server 安装mysql服务端程序
[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb-server
5.启动mariadb,并设置开机自启
[root@localhost ~]# systemctl start mariadb && systemctl enable mariadb
6.设置mariadb数据库,创建zabbix库,存储监控数据,且创建账号
[root@localhost ~]# mysqladmin password 123456
[root@localhost ~]# mysql -uroot -p123456 -e "create database zabbix character set utf8 collate utf8_bin;"
[root@localhost ~]# mysql -uroot -p123456 -e "grant all privileges on zabbix.* to zabbix@localhost identified by '123456';"
#查看数据库
[root@localhost ~]# mysql -uroot -p123456 -e "show databases;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| zabbix             |
+--------------------+
7.导入zabbix服务端的数据库内容 
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.47/create.sql.gz |mysql -uroot -p123456 zabbix
[root@localhost ~]# mysql -uroot -p123456 -e "show tables from zabbix;"
+----------------------------+
| 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                |
| dashboard                  |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_preproc               |
| items                      |
| items_applications         |
| maintenance_tag            |
| 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_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_remote_command        |
| task_remote_command_result |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+
8.修改zabbix-server服务端配置文件,指明信息,便于agent去连接
利用grep筛选出有效内容
[root@localhost ~]# grep "^[a-Z]" /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
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
#将上面的内容写入到zabbix_server.conf配置文件中
[root@localhost ~]# cat >/etc/zabbix/zabbix_server.conf << 'EOF'
> LogFile=/var/log/zabbix/zabbix_server.log
> LogFileSize=0
> PidFile=/var/run/zabbix/zabbix_server.pid
> SocketDir=/var/run/zabbix
> DBName=zabbix
> DBUser=zabbix
> SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
> Timeout=4
> AlertScriptsPath=/usr/lib/zabbix/alertscripts
> ExternalScripts=/usr/lib/zabbix/externalscripts
> LogSlowQueries=3000
> EOF
#再次编辑文件,添加几行内容
末尾添加俩行
[root@localhost ~]# vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBPassword=123456
9.启动zabbix-server
[root@localhost ~]# systemctl start zabbix-server && 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@localhost ~]# yum -y install net-tools
[root@localhost ~]# netstat -tunlp|grep zabbix
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      2719/zabbix_server  
tcp6       0      0 :::10051                :::*                    LISTEN      2719/zabbix_server 
10.修改apache的配置文件,并启动80端口的apache服务
[root@localhost ~]# vi /etc/httpd/conf.d/zabbix.conf
#文件中的20行
# php_value date.timezone Europe/Riga
修改为
php_value date.timezone Asia/Shanghai
[root@localhost ~]# systemctl start httpd
11.访问zabbix页面

使用ip+/zabbix进行访问

 

 

 

 

 

 12.设置中文

点击Update,即可设置为中文 

13.解决乱码

点击查询cpu使用的统计信息,发现左下角不是文字,而是小格格,因为字体不匹配,造成的乱码

 下载文泉仪微黑字体,修改zabbix的字体支持

[root@localhost ~]# yum install wqy-microhei-fonts -y

拷贝字体给zabbix用,覆盖图形字体

[root@localhost ~]# cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/zabbix/assets/fonts/graphfont.ttf 
cp:是否覆盖"/usr/share/zabbix/assets/fonts/graphfont.ttf"? y

刷新zabbix网页,发现字体已经正常显示 

此时打开zabbix首页,发现显示Zabbix agent on Zabbix server is unreachable for 5 minutes(Zabbix服务器上的Zabbix代理在5分钟内无法访问)

 

 因为我们现在只安装了zabbix-server,还没有安装zabbix-agent来采集数据

14.安装zabbix-agent,并修改配置文件

 

[root@localhost ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.47-1.el7.x86_64.rpm
获取https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.47-1.el7.x86_64.rpm
准备中...                          ################################# [100%]
	软件包 zabbix-agent-4.0.47-1.el7.x86_64 已经安装

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
98行
Server=127.0.0.1
地址修改为zabbix-serverip地址,我这里是192.168.200.4
Server=192.168.200.4

139行
ServerActive=127.0.0.1
地址修改为zabbix-serverip地址,我这里是192.168.200.4
ServerActive=192.168.200.4
保存退出

 启动zabbix-agent,设置为开机自启,查看状态

[root@localhost ~]# systemctl start zabbix-agent
[root@localhost ~]# systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@localhost ~]# systemctl status zabbix-agent
● zabbix-agent.service - Zabbix Agent
   Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2023-06-27 21:01:07 CST; 12s ago
 Main PID: 15083 (zabbix_agentd)
   CGroup: /system.slice/zabbix-agent.service
           ├─15083 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
           ├─15084 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
           ├─15085 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
           ├─15086 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
           ├─15087 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
           └─15088 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]

6月 27 21:01:07 localhost.localdomain systemd[1]: Starting Zabbix Agent...
6月 27 21:01:07 localhost.localdomain systemd[1]: Started Zabbix Agent.
15.服务器上配置好了,最后去zabbix界面上配置

 

 

 

 

 

 变绿显示成功,查询cpu的统计信息,成功读取数据 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值