准备一个纯净环境10.0.0.99
首先修改yum源,修改为zabbix清华源,清华源玉zabbix官方源都是同步的,下载速度更快!
zabbix官方
Download Zabbixwww.zabbix.com清华源
Tsinghua Open Source Mirrormirrors.tuna.tsinghua.edu.cnrpm -ivh rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
配置zabbix的yum源
[root@hb-99 ~]# ll /etc/yum.repos.d/
total 40
-rw-r--r--. 1 root root 2523 Jun 16 2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Nov 23 2018 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Nov 23 2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Nov 23 2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Nov 23 2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Nov 23 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 Nov 23 2018 CentOS-Vault.repo
-rw-r--r-- 1 root root 664 May 11 2018 epel.repo
-rw-r--r-- 1 root root 451 Jul 11 18:35 zabbix.repo #这个屌炸天得清华源修改/etc/yum.repos.d/zabbix.repo文件
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=0下载zabbix
# yum install zabbix-server-mysql zabbix-web-mysql -y
安装数据库mariadb
[root@hb-99 ~]# yum install mariadb-server.x86_64 -y
[root@hb-99 ~]# systemctl start mariadb.service
[root@hb-99 ~]# systemctl enable mariadb.service 优化数据库
[root@hb-99 ~]# mysql_secure_installation
回车 n y y y yNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.Enter current password for root (enter for none): # 输入当前root用户密码当前密码为空 ----> 回车即可
OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.Set root password? [Y/n] n # 是否给root用户设置密码... skipping.By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.Remove anonymous users? [Y/n] y # 是否删除空用户... Success!Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] y # 是否禁止root远程登陆... Success!By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.Remove test database and access to it? [Y/n] y # 是否删除test测试库 - Dropping test database...... Success!- Removing privileges on test database...... Success!Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.Reload privilege tables now? [Y/n] y # 是否刷新数据库... Success!Cleaning up...All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
创建数据库+授权
mysql
create database zabbix character set utf8 collate utf8_bin; (修改字符集,指定好符集,以后不会乱码)
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
将zabbix初始数据导入库
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix zabbix
修改zabbix配置文件
[root@98 ~]# egrep '^DB' /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
zabbix日志文件(记录错误)
[root@zabbix-server ~]# ll /var/log/zabbix/zabbix_server.log
-rw-rw-r-- 1 zabbix zabbix 4223 Jul 8 10:52 /var/log/zabbix/zabbix_server.log
启动服务检查进程
[root@98 ~]# systemctl start zabbix-server.service
[root@98 ~]# systemctl enable zabbix-server.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@98 ~]# systemctl is-active zabbix-server.service
active
[root@98 ~]# netstat -luntp|grep 10051 #检查端口开启,服务才是真正得开启
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 9719/zabbix_server
tcp6 0 0 :::10051 :::* LISTEN 9719/zabbix_server
修改时区
[root@98 ~]# grep Asia/Shanghai /etc/httpd/conf.d/zabbix.confphp_value date.timezone Asia/Shanghai
启动httpd
[root@zabbix-server ~]# systemctl start httpd.service
[root@zabbix-server ~]# systemctl enable httpd.serviceweb
配置zabbix网站
http://10.0.0.98/zabbix/setup.php
用户名:Admin 密码:zabbix
压力测试(用于测试高并发数量)利于监控
ab -n 200000 -c 300 http://10.0.0.98/zabbix/zabbix.php
-n 数量
-c 次数
zabbix客户端部署
安装客户端软件
yum install zabbix-agent -y
[root@zabbix-server ~]# egrep "^Server=" /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1 #改成服务端IP即可
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service
修改配置文件:/etc/zabbix/zabbix_agentd.conf
UserParameter=tcp.estab,netstat -antp|grep -c ESTABLISHED
web界面配置
配置---主机---创建主机---*号的必填---点击主机名----配置模板----重启服务端
创建监控项---配置触发器
查看yum下载的历史命令
201 yum history 202 yum history info 4203 yum history info 5
错误案例
# 更改用户权限或者命令权限4755
服务端收集信息慢,导致超时解绝方法
[root@web01 ~]# grep '# Timeout' /etc/zabbix/zabbix_agentd.conf
# Timeout=3 #设置超时时间zabbix_get命令执行时间
[root@web01 ~]#
常见的linux监控命令
free #查看内存
df #查看磁盘大小
top #查看内存磁盘负载等
uptime #当前时间,运行时间,用户数量,负载
who #查看登陆用户数量及其负载
iostat #查看磁盘的读写效率及其压力
[root@web01 ~]# top
top - 20:21:37 up 4:43, 4 users, load average: 0.00, 0.06, 0.06
当前系统时间 系统运行时间 系统登陆用户 负载信息
Tasks: 134 total, 1 running, 133 sleeping, 0 stopped, 0 zombie
总进程数量 运行的数量 休眠的数量 停止的进程 僵尸进程
%Cpu(s): 2.0 us, 1.7 sy, 0.0 ni, 96.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
us #用户进程占用cpu资源百分比
sy #内核态进程占用的cpu资源百分比
ni #用户进程空间内改变过优先级的进程cpu百分比
改变进程优先级的命令:renice -10 -p pid
进程优先级排序 -1 ....20 数字越小执行越优先
wa #等待输入输出(io)进程占用的百分比
hi #硬中断
si #软中端
st #虚拟机占用内存的百分比(真实的服务器可见)
KiB Mem : 997956 total, 624784 free, 173148 used, 200024 buff/cache
内存信息
KiB Swap: 1048572 total, 1048572 free, 0 used. 629432 avail Mem
swap分区信息PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 775 root 20 0 298708 6104 4776 S 0.3 0.6 0:26.33 vmtoolsd 1277 root 20 0 590168 15012 4904 S 0.3 1.5 1:04.17 glusterd
PID #进程号
PR #进程优先级
NI #优先级的值(负数表示优先级很高,正数表示优先级比较低)
VIRT #虚拟内存
虚拟内存=物理内存+swap
1、进程"需要的"虚拟内存大小,包括进程使用的库、代码、数据等
2、假如进程申请100m的内存,但实际只使用了10m,那么它会增长100m,而不是实际的使用量
RES #常驻内存
1、进程当前使用的内存大小,但不包括swap out
2、包含其他进程的共享
3、如果申请100m的内存,实际使用10m,它只增长10m,与VIRT相反
4、关于库占用内存的情况,它只统计加载的库文件所占内存大小
SHR #共享内存
1、除了自身进程的共享内存,也包括其他进程的共享内存
2、虽然进程只使用了几个共享库的函数,但它包含了整个共享库的大小
3、计算某个进程所占的物理内存大小公式:RES – SHR
4、swap out后,它将会降下来