一、zabbix监控的安装:
1、zabbix服务器端:
1.1 先在官网安装zabbix源:

1.2 修改zabbix源(把默认的国外源,更换为清华源):
[root@zabbix ~]# cat /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=1
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=1
1.3 安装zabbix服务端和zabbix-web前端 (可以用2台服务器分别安装,也可以根据实际情况装在一台机器):
[root@zabbix ~]#yum install zabbix-server-mysql zabbix-web-mysql -y
1.4 安装mariadb,并启动和添加开机自启动:
[root@zabbix ~]#yum install mariadb-server -y
[root@zabbix ~]#systemctl start mariadb
[root@zabbix ~]#systemctl enable mariadb
1.5 优化数据库(mysql安全初始化):
[root@zabbix yum.repos.d]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS 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):
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
... 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
... 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
- 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.
Thanks for using MariaDB!
1.6 添加数据库:
[root@zabbix ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> Bye
[root@zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix zabbix
1.7 导入zabbix表结构和初始数据(检查表是否倒入成功):
[root@zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql-3.0.*/create.sql.gz | mysql -uzabbix -pzabbix zabbix
检查表是否倒入成功:
[root@zabbix ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4909
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
1.8 为zabbix server/proxy配置数据库:
编辑zabbix_server.conf或zabbix_proxy.conf文件以使用自己创建的数据库:
[root@zabbix ~]# cat /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
1.9 文件配置完成后,启动zabbix-server服务:
[root@zabbix ~]#systemctl start zabbix-server
[root@zabbix ~]#systemctl enable zabbix-server
1.10 监听端口是否开启(端口10051):
[root@zabbix yum.repos.d]# netstat -lntup
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:3306 0.0.0.0:* LISTEN 8987/mysqld
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7217/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7298/master
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 9199/zabbix_server
tcp6 0 0 :::22 :::* LISTEN 7217/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7298/master
tcp6 0 0 :::10051 :::* LISTEN 9199/zabbix_server
udp 0 0 127.0.0.1:323 0.0.0.0:* 6510/chronyd
udp6 0 0 ::1:323 :::* 6510/chronyd
1.11 修改Zabbix前端的PHP配置,并启动httpd(对于RHEL7和更高版本,zabbix前段的apache配置文件位于/etc/httpd/conf.d/zabbix.conf ,只需要修改文件内容里面的时区即可)
[root@zabbix ~]# vim /etc/httpd/conf.d/zabbix.conf
#
# Zabbix monitoring system php web frontend
#
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Require all granted
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
1.12 时区修改完以后,重启httpd服务:
[root@zabbix ~]# systemctl start httpd
[root@zabbix ~]# systemctl enable httpd
2、zabbix服务器web页面的注册:
2.1 先进行本地输入10.0.0.71/zabbix 进入登录页面:

2.2 登录创建的数据库页面:

2.3 要是进行数据库迁移则需要找下图标识的路径,用于修改上图连接数据库配置:

2.4 需要输入zabbix服务的本地名,端口和服务器名称(自己随意取名):

2.5 zabbix登录用户名为:Admin,密码为:zabbix

二、常见的linux监控命令:

1、内存监控命令:

注:tab键使用的内存,所以当遇到tab键卡的无法使用时,那就是内存已经耗尽,系统会默认去杀进程,比较危险。
2、一般监控磁盘的方法(磁盘如果沾满,程序则无法使用,所以必须监控):

三、使用shell脚本来做监控服务:
应用场景:当公司服务器很少,不需要使用zabbix服务的情况下。
使用方法:shell脚本+crontab定时任务。
1、检测在线用户登录数
1.1、检测命令行:
[root@zabbix ~]# who |wc -l
3
1.2、写监控登录用户数量的脚本:
[root@zabbix scripts]# cat yhshu.sh
#!/bin/bash
users='who|wc -l'
if [$users -ge 4];then
echo “当前用户登录数多于$users个”|mail -s '报警' 429632385@qq.com
fi
1.3、书写定时任务:
[root@zabbix scripts]# crontab -l
*/10 * * * * /bin/bash /server/scripts/yhshu.sh >/dev/null 2&>1
2、一分钟监控一次内存的书写方法:

四、zabbix架构:
1、客户端需要安装zabbix-agent服务进行采集数据;
2、服务器端安装的zabbix-server用于数据分析,报警
3、数据库需要安装mariadb-server服务,用来存储数据
4、zabbix-web页面,用来展示zabbix直观的数据监控服务。

五、给zabbix服务端和客户端均安装zabbix-agent检测服务:
1、zabbix服务器上安装方法:
1.1、下载zabbix-agent压缩包
[root@zabbix scripts]# wget
https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.9-3.el7.x86_64.rpm
1.2 安装zabbix-agent服务:
[root@zabbix]#rpm -ivh zabbix-agent-4.0.9-3.el7.x86_64.rpm
1.3 在服务器端配置zabbix-agent检测服务的配置文件:

2、zabbix客户端上安装方法:
2.1、下载zabbix-agent压缩包
[root@web01]# wget
https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.9-3.el7.x86_64.rpm
2.2 安装zabbix-agent服务:
[root@web01]#rpm -ivh zabbix-agent-4.0.9-3.el7.x86_64.rpm
2.3 在客户端配置zabbix-agent检测服务的配置文件(路径:/etc/zabbix/zabbix_agentd.conf):

六、在zabbix的web服务页面,创建监控主机步骤:
1、步骤1:

2、步骤2:

3、步骤3:

4、步骤4:

七、在zabbix的web服务页面,配置自定义监控项:
1、现在配置文件中写入自定义监控项目:

2、

3、

4、

5、

6、

7、

网友评论