文章目录
- 命令行查看系统:内存,磁盘
内存使用查看(tot, use, free): free -k |awk '/Mem/{print $2,$3,$4}'
磁盘使用(tot,use,free ): df -kP |awk '/^\/dev/ {tot+=$2; use+=$3; free+=$4}END{print tot","use","free}'
#yum -y install sysstat: /usr/bin/sar, /usr/bin/iostat
cpu使用率: sar -u 1 1 |awk '/Average/{print 100-$NF}'
磁盘读写:(read, write): iostat -dk |awk '/^[hs]d[a-z]/{read+=$3; write+=$4; count+=1} END{print read/count,write/count}'
1,安装zabbix
a, CentOS7
- a, zabbix是一个php项目,依赖于httpd, php, mysql
- b,安装指南: https://www.zabbix.com/documentation/3.0/manual/installation/install_from_packages#from_distribution_packages
# 1,准备lamp环境
yum -y install httpd mariadb-server php php-mysql php-gd php-ldap php-mbstring
# 2,按照指南,安装zabbix
rpm -Uvh https://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
# 3,配置mysql数据库: root用户连接maraidb默认没有密码
systemctl start httpd mariadb
mysql -e "create database zabbix character set utf8"
mysql -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'"
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix zabbix
# 4,修改配置文件:
#/etc/zabbix/zabbix_server.conf = => DBPassword=zabbix
#/etc/httpd/conf.d/zabbix.conf = => php_value date.timezone=Asia/Shanghai
# 5,启动服务
systemctl restart httpd zabbix-server zabbix-agent
systemctl enable httpd zabbix-server zabbix-agent mariadb
# 6,访问zabbix web页面: http://server_ip_or_name/zabbix , 用户名密码:admin/zabbix
b, CentOS6
[root@test-c6 ~]# cat /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.4/rhel/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-deprecated]
name=Zabbix Official Repository deprecated - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.4/rhel/6/$basearch/deprecated
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[root@test-c6 ~]# cat /etc/yum.repos.d/webtatic.repo
[webtatic]
name=Webtatic Repository EL6 - $basearch
#baseurl=https://repo.webtatic.com/yum/el6/$basearch/
mirrorlist=https://mirror.webtatic.com/yum/el6/$basearch/mirrorlist
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el6
#安装php5.5+: https://blog.csdn.net/eyeofeagle/article/details/104472216
[root@test-c6 ~]# tail /etc/php.ini
date.timezone = Asia/Shanghai
max_execution_time= 300
post_max_size = 32M
max_input_time = 300
memory_limit = 128M
mbstring.func_overload =2
mbstring.func_overload = 1
2,zabbix配置主机监控
a, 添加cent6主机
Configuration --> Hosts --> 右上角:Create Host–> 填写参数,点击最后的Add按钮
b, 添加该主机的监控项:application, item, trigger
回到Configuration --> Hosts 页面,在该主机展示栏目中添加application, item
回到Configuration --> Hosts 页面,在该主机展示栏目中添加trigger
c, 添加该主机的action:发送邮件
I, 邮箱设置: 生成授权码,开启smtp服务
设置–> 客户端授权密码: (手机发送短信),设置第三方客户端的用户密码(如: 123123)
II, 添加action, 发送邮件
回到Administration --> Media types 页面–> 右上角:Create media type
(注:此处输入的邮箱密码是 --刚才邮箱设置的 ‘客户端授权密码’ )
回到Configuration --> Actions 页面— > 右上角:New Action
(设置action名称: 比如packets to much >5)
(Conditions 项:关联到哪个 item)
(Operations项: 关联发送邮箱)
3,测试
说明:在zabbix-server端(192.168.56.77) 发送ping 报文给被监控主机192.168.56.66
[root@c7 ~]# ping -c 10000 -i 0.01 192.168.56.66
64 bytes from 192.168.56.66: icmp_seq=6199 ttl=64 time=0.350 ms
.....
a, 观察zabbix事件