一、下载安装zabbix
1.下载zabbix
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
2.安装
[root@localhost ~]# rpm -ivh zabbix-release-4.0-2.el7.noarch.rpm
3.查看里面有什么文件
[root@localhost ~]# rpm -ql zabbix-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
/etc/yum.repos.d/zabbix.repo
/usr/share/doc/zabbix-release-4.0
/usr/share/doc/zabbix-release-4.0/GPL
4.配置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-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=0
[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
5.安装zabbix-server-mysql和zabbix-web-mysql
[root@localhost yum.repos.d]# yum install zabbix-server-mysql zabbix-web-mysql -y
6.安装mariadb数据库
[root@localhost yum.repos.d]# yum install mariadb-server.x86_64 -y
[root@localhost yum.repos.d]# systemctl start mariadb.service
[root@localhost yum.repos.d]# systemctl enable mariadb.service
7.mariadb数据库安全初始化
[root@localhost yum.repos.d]# mysql_secure_installation
[root@localhost 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!
8.查看优化后的数据库
[root@localhost yum.repos.d]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.68-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)
9.创建数据库并授权给zabbix用户
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
10. 为数据库导入数据数据:
[root@localhost yum.repos.d]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p123456 zabbix
11.检查数据库是否有表
[root@localhost yum.repos.d]# mysql zabbix -e 'show tables;'
12.修改zabbix 配置文件
[root@localhost yum.repos.d]# cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.bak
[root@localhost yum.repos.d]# vim /etc/zabbix/zabbix_server.conf
[root@localhost yum.repos.d]# cat /etc/zabbix/zabbix_server.conf | grep -Ev "^$|^#"
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
13.启动zabbix
[root@localhost ~]#systemctl start zabbix-server.service
[root@localhost ~]#systemctl enable zabbix-server.service
14.配置zabbix前台页面httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
修改[root@localhost ~]# vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
重启httpd服务
[root@localhost ~]# systemctl restart httpd.service
15.安装zabbix-agent使其自己的服务器不报警
[root@localhost ~]# yum install zabbix-agent.x86_64
[root@localhost ~]# systemctl enable zabbix-agent.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@localhost ~]# systemctl start zabbix-agent.service
二、添加一台centos主机监控
1.在另一台机器上
[root@localhost yum.repos.d]# yum install -y zabbix-agent
[root@localhost yum.repos.d]# vim /etc/zabbix_agentd.conf
将sever改成服务器地址
[root@localhost yum.repos.d]# systemctl enable zabbix-agent.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@localhost yum.repos.d]# systemctl start zabbix-agent.service
2.添加自定义监控
a命令行取值
[root@localhost ~]# iostat | awk '/sda/{print $2}'
5.11
b修改zabbix-agent配置文件UserParameter(default下一行)
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=sda_tps, iostat | awk '/sda/{print $2}'
c.重启zabbix-agent服务
d安装zabbix-get用户测试取值
[root@localhost ~]# yum install zabbix-get.x86_64
[root@localhost ~]# zabbix_get -s 127.0.0.1 -k sda_tps
4.98
e.zabbix中文显示乱码解决
修改配置文件(文件位置:$zabbix_path/include/defines.inc.php)
vim /usr/share/zabbix/include/defines.inc.php
修改一:
原:define('ZBX_GRAPH_FONT_NAME', 'graphfont');
改为:define('ZBX_GRAPH_FONT_NAME', 'zabbix');
修改二:
原:define('ZBX_FONT_NAME', 'graphfont');
改为:define('ZBX_FONT_NAME', 'zabbix');
2、拷贝windows文字文件到服务器上
C:\Windows\Fonts目录下拷贝自己需要的中文语言文件
拷贝文件到服务器目录下($zabbix_path/assets/fonts/):/usr/share/zabbix/assets/fonts/
重命名:mv xxx.ttf zabbix.ttf
3、重启服务
systemctl restart zabbix-server
三、配置邮件报警
a.配置发件人
b.配置收件人
c.定义动作启用
d.改成中文报警