【Zabbix】Linux监控软件安装与配置(三)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

一、安装扩展源

[root@www ~]# rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/i386/epel-release-6-8.noarch.rpm

二、安装LAMP环境

[root@www ~]# yum -y install httpd mysql mysql-libs php php-mysql mysql-server php-bcmath php-gd php-mbstring

三、安装zabbix服务(zabbix2.0版本)

[root@www ~]# yum -y install zabbix20 zabbix20-agent zabbix20-server  zabbix20-server-mysql zabbix20-web zabbix20-web-mysql net-snmp-devel

四、启动服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@www ~] # service mysqld start
[root@www ~] # service httpd start
[root@www ~] # service zabbix-server start
Starting Zabbix server:                                    [  OK  ]
[root@www ~] # service zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]
 
[root@www ~] # netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID /Program  name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1281 /sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1015 /master         
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      4796 /zabbix_agentd  
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      4594 /mysqld         
tcp        0      0 :::80                       :::*                        LISTEN      2712 /httpd          
tcp        0      0 :::22                       :::*                        LISTEN      1281 /sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1015 /master         
tcp        0      0 :::10050                    :::*                        LISTEN      4796 /zabbix_agentd

五、配置mysql

1、增加或修改以下配置

1
2
3
4
5
6
[root@www ~] # vim /etc/my.cnf
[mysqld]
character_set_server = utf8
 
[mysql]
default-character- set  = utf8
1
2
3
[root@www ~] # service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

2、创建zabbix数据库

1
[root@www ~] # mysql -uroot -p -e "create database zabbix"

3、创建授权zabbix数据库用户

1
[root@www ~] # mysql -uroot -p -e "grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';"

4、导入zabbix数据库

1
2
[root@www ~] # ls /usr/share/zabbix-mysql/
data.sql  images.sql  schema.sql  upgrades
1
2
3
[root@www ~] # mysql -uroot -p --default-character-set=utf8 zabbix < /usr/share/zabbix-mysql/schema.sql 
[root@www ~] # mysql -uroot -p --default-character-set=utf8 zabbix < /usr/share/zabbix-mysql/images.sql 
[root@www ~] # mysql -uroot -p --default-character-set=utf8 zabbix < /usr/share/zabbix-mysql/data.sql

六、安装zabbix网页端

http://192.168.1.21/zabbix

wKioL1aQ0uXBHJ6mAAFV8xGBepA456.jpg

根据页面上的提示更改相关配置

wKioL1aQ0zXRdjT6AAGmJoikgXw293.jpg

1
2
3
4
5
[root@www ~] # vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date .timezone = Asia /Shanghai
1
2
3
[root@www ~] # service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

刷新页面,【Next】

wKiom1aQ1Hax1tp1AAFC5n83LCg058.jpg

wKioL1aQ1ZOA1R4hAAE7SbWG4rc628.jpg   Test connection --->Next

wKioL1aQ1p7RMatYAAEF2MEBCos813.jpg

自定义Name--->Next

wKiom1aQ1sLDD5PZAAE4bOBDa9Q891.jpgwKioL1aQ1xHxH5anAAD3x1-T7dU603.jpgFinish,跳转到登录页面,默认的管理员用户:admin 密码:zabbix

wKioL1aQ1_7Bt23mAAE1jO2WXZM723.jpg

由于前面添加了zabbix用户,没有修改相应的配置文件/etc/zabbix/zabbix_server.conf,导致zabbix-server没有启动

wKiom1aQ2cnB1IUNAAFSfwVSD7A055.jpg


查看日志文件zabbix_server日志(提示没有设置zabbix数据库密码)

1
2
3
4
5
6
7
8
9
10
11
[root@www ~] # tail /var/log/zabbix/zabbix_server.log 
   6153:20160109:180057.467 [Z3001] connection to database  'zabbix'  failed: [1045] Access denied  for  user  'zabbix' @ 'localhost'  (using password: NO)
   6153:20160109:180057.467 Database is down. Reconnecting  in  10 seconds.
   6153:20160109:180107.470 [Z3001] connection to database  'zabbix'  failed: [1045] Access denied  for  user  'zabbix' @ 'localhost'  (using password: NO)
   6153:20160109:180107.470 Database is down. Reconnecting  in  10 seconds.
   6153:20160109:180117.473 [Z3001] connection to database  'zabbix'  failed: [1045] Access denied  for  user  'zabbix' @ 'localhost'  (using password: NO)
   6153:20160109:180117.473 Database is down. Reconnecting  in  10 seconds.
   6153:20160109:180127.474 [Z3001] connection to database  'zabbix'  failed: [1045] Access denied  for  user  'zabbix' @ 'localhost'  (using password: NO)
   6153:20160109:180127.474 Database is down. Reconnecting  in  10 seconds.
   6153:20160109:180137.476 [Z3001] connection to database  'zabbix'  failed: [1045] Access denied  for  user  'zabbix' @ 'localhost'  (using password: NO)
   6153:20160109:180137.476 Database is down. Reconnecting  in  10 seconds.

修改/etc/zabbix/zabbix_server.conf配置文件

1
2
3
4
5
6
7
8
[root@www ~] # vim /etc/zabbix/zabbix_server.conf
LogFile= /var/log/zabbix/zabbix_server .log
LogFileSize=0
PidFile= /var/run/zabbix/zabbix_server .pid
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix    #默认是注释的
DBSocket= /var/lib/mysql/mysql .sock


重启启动zabbix-server服务

1
2
3
[root@www ~] # service zabbix-server restart
Shutting down Zabbix server:                               [  OK  ]
Starting Zabbix server:                                    [  OK  ]
1
2
3
4
5
[root@www ~] # netstat -ntlp |grep zabbix
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      6106 /zabbix_agentd  
tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      6888 /zabbix_server  
tcp        0      0 :::10050                    :::*                        LISTEN      6106 /zabbix_agentd  
tcp        0      0 :::10051                    :::*                        LISTEN      6888 /zabbix_server

wKioL1aQ3CzToRSDAAFAOH6JU7Q759.jpg


七、添加监控客户端主机

1、安装zabbix20-agent

1
[root@sh ~] # yum -y install zabbix20-agent

2、配置zabbix_agentd.conf 文件

1
2
3
4
[root@sh ~] # vim /etc/zabbix_agentd.conf 
Server=192.168.1.21
ServerActive=0.0.0.0:10050
Hostname=sh_zabbix   #自定义名称

3、启动zabbix-agent

1
2
[root@sh ~] # /etc/init.d/zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]

4、服务端测试

1
2
[root@www ~] # zabbix_get -s 192.168.1.251 -p10050 -k "system.hostname"
sh.huangmingming.com


5、web界面下配置

Configuration--->Hosts--->Create hosts

wKiom1aQ5tWCFF2uAAD6PR9C2kI333.jpg

添加主机:Host name(自定义)--->Visible name(自定义)--->Groups(添加一个组)--->IP address--->Save

wKioL1aQ6g-xdD0aAAEoZ8PxQbg125.jpg

添加模板:Host list--->sh_ming--->Templates--->add--->Template OS Linux(选择一个模板)--->Select--->Save

wKioL1aQ6oLiW_IqAAEjjvfUjIs253.jpg

wKioL1aQ7PeS11bqAAEambT7Bk4055.jpg

自定义模板:Configuration--->Create template--->Template--->Template name(自定义)--->Visible name(自定义)--->Groups(Templates)---Save

wKioL1aQ7_WCEgpLAADDnMefalQ670.jpg

拷贝项目:MySQL Items--->Copy Select to--->my_tem

wKioL1aQ8c-jcs9VAAIBcxBfOxc287.jpg

wKiom1aQ8iOzsFMAAACpQxEWeYo931.jpg

查看:Templates list

wKioL1aQ8pySV9xaAAEJIK_do_o452.jpg


八、配置zabbix邮件告警

1、安装sendmail,使用sendmail发送邮件

1
2
3
4
[root@www ~] # yum install sendmail
[root@www ~] # /etc/init.d/postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]
1
2
3
4
5
6
[root@www ~] # mail -s "test11" 741616710@qq.com </etc/inittab 
[root@www ~] # mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender /Recipient-------
1E86460728*    1347 Sat Jan  9 19:57:03  root@www.huangmingming.net
                                          741616710@qq.com
-- 1 Kbytes  in  1 Request.

2、编写脚本

1
2
3
4
5
6
[root@www ~] # mkdir /home/zabbix_mail/bin/ -p
[root@www ~] # vim /home/zabbix_mail/bin/baojing.sh
#!/bin/bash
echo  "$3"  | /bin/mail  -s  "$2"  $1
 
[root@www ~] # chmod a+x /home/zabbix_mail/bin/baojing.sh

3、修改zabbix_server.conf文件

1
2
3
[root@www ~] # vim /etc/zabbix_server.conf
AlertScriptsPath= /home/zabbix_mail/bin
ExternalScripts= /home/zabbix_mail/bin

4、zabbix服务端web页面配置

Administration--->Media types--->Create Media type--->Type(script)--->Save

wKioL1aQ-0rzT8mIAADEU6vDS1g101.jpg

创建user:

wKiom1aQ_JDgUX3dAAEJ48mhnT0143.jpg

wKioL1aQ_yGQoKi_AADjhYveq34723.jpgwKiom1aQ_wzxu41iAAD5sOwEcEM239.jpg

创建action:

wKioL1aQ_8vSTHiuAADsYiOdKms569.jpg

Action:name(自定义)

wKioL1aRAM-jfeBkAAD4YeSN3Qw595.jpg

Operations:

wKiom1aRAMLwal6DAAEA740dDQg942.jpg

wKioL1aRAtygjRiRAAEHPMEBE9U066.jpg



本文转自 HMLinux 51CTO博客,原文链接:http://blog.51cto.com/7424593/1733330

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
9天前
|
安全 Ubuntu Java
Linux配置使用篇
Linux配置使用篇
|
21天前
|
存储 负载均衡 索引
linux7安装elasticsearch-7.4.0集群配置
linux7安装elasticsearch-7.4.0集群配置
109 0
|
26天前
|
监控 Linux Shell
【Shell 命令集合 网络通讯 】Linux 配置和管理网络流量的形状 shapecfg命令 使用指南
【Shell 命令集合 网络通讯 】Linux 配置和管理网络流量的形状 shapecfg命令 使用指南
36 0
|
26天前
|
网络协议 Shell Linux
【Shell 命令集合 网络通讯 】Linux 设置和配置PPP pppsetup命令 使用教程
【Shell 命令集合 网络通讯 】Linux 设置和配置PPP pppsetup命令 使用教程
34 0
|
26天前
|
缓存 网络协议 Linux
【Shell 命令集合 网络通讯 】Linux 配置DNS dnsconf 命令 使用教程
【Shell 命令集合 网络通讯 】Linux 配置DNS dnsconf 命令 使用教程
38 0
|
28天前
|
网络协议 Ubuntu Linux
Linux 动态/静态配置ip网卡信息
Linux 动态/静态配置ip网卡信息
36 0
|
26天前
|
域名解析 网络协议 Linux
【Shell 命令集合 网络通讯 】Linux 设置和管理网络接口配置信息 netconfig命令 使用指南
【Shell 命令集合 网络通讯 】Linux 设置和管理网络接口配置信息 netconfig命令 使用指南
49 1
|
26天前
|
监控 网络协议 Shell
【Shell 命令集合 网络通讯 】Linux 监控和记录网络中ARP(Address Resolution Protocol)活动 arpwatch命令 使用指南
【Shell 命令集合 网络通讯 】Linux 监控和记录网络中ARP(Address Resolution Protocol)活动 arpwatch命令 使用指南
33 0
|
26天前
|
存储 Shell Linux
【Shell 命令集合 系统管理 】Linux 修改用户的属性和配置 usermod命令 使用指南
【Shell 命令集合 系统管理 】Linux 修改用户的属性和配置 usermod命令 使用指南
30 1
|
9天前
|
网络协议 Linux
在Linux中,管理和配置网络接口
在Linux中管理网络接口涉及多个命令,如`ifconfig`(在新版本中被`ip`取代)、`ip`(用于网络设备配置)、`nmcli`(NetworkManager的CLI工具)、`nmtui`(文本界面配置)、`route/ip route`(处理路由表)、`netstat/ss`(显示网络状态)和`hostnamectl/systemctl`(主机名和服务管理)。这些命令帮助用户启动接口、设置IP地址、查看连接和路由信息。不同发行版可能有差异,建议参考相应文档。
19 4