环境部署
两台服务器:
1、监控端:192.168.35.100
2、被监控端:192.168.35.101
监控端安装部署
1、关闭防火墙
[[email protected] ~]# systemctl stop firewalld.service #关闭防火墙
[[email protected] ~]# systemctl disable firewalld.service #开机禁用
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[[email protected] ~]# setenforce 0 #关闭增强性安全功能
2、安装LMAP
(1)安装必要的环境包以及服务
[[email protected] ~]#
yum install -y \
httpd \
mariadb-server mariadb \
php \
php-mysql \
php-gd \
libjpeg* \
php-ldap \
php-odbc \
php-pear \
php-xml \
php-xmlrpc \
php-mhash
(2)更改httpd服务配置文件
[[email protected] ~]# vim /etc/httpd/conf/httpd.conf
/ 95 ServerName www.yun.com:80
/ 164 DirectoryIndex index.html index.php
(3)更改时区
[[email protected] ~]# vim /etc/php.ini
/ 878 date.timezone = PRC #设置中国时区
(4)开启服务
[[email protected] ~]# systemctl start httpd.service
[[email protected] ~]# systemctl start mariadb.service[[email protected] ~]# netstat -ntap | egrep '(80|3306)' #查看端口
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 80222/mysqld
tcp6 0 0 :::80 :::* LISTEN 79961/httpd
(5)初始化mysql配置
[[email protected] ~]# 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] Y #设置密码
New password: #abc123
Re-enter new password: #abc123
Password updated successfully!
Reloading privilege tables..
... Success!
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] n #不删除匿名用户
... skipping.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] n #允许远程登录
... skipping.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] n #不删除测试数据库
... skipping.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!
[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.64-MariaDB MariaDB ServerCopyright (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; #创建zabbix数据库
Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123'; #创建管理用户
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> flush privileges; #刷新
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)MariaDB [(none)]> \q
Bye
(6)写一个简单的PHP测试网页,保证能进行访问
[[email protected]alhost ~]# vim /var/www/html/index.php
<?php
phpinfo();
?>
打开浏览器进行访问
(7)用新创建用户登录数据库,看能否登陆
[[email protected] ~]# mysql -uzabbix -p
Enter password:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES) #登录失败
解决方法:
[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.64-MariaDB MariaDB ServerCopyright (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)]> select user,host from mysql.user; #有空用户名称占用导致本地无法登录远程可登录
+--------+-----------------------+
| user | host |
+--------+-----------------------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+--------+-----------------------+
7 rows in set (0.00 sec)MariaDB [(none)]> drop user ''@localhost; #删掉空用户localhost
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> drop user ''@localhost.localdomain; #删掉空用户localhost.localdomain
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> flush privileges; #刷新
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------------------+
| user | host |
+--------+-----------------------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| root | localhost.localdomain |
+--------+-----------------------+
5 rows in set (0.00 sec)MariaDB [(none)]> \q
Bye
再试着去登陆
[[email protected] ~]# mysql -uzabbix -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.64-MariaDB MariaDB ServerCopyright (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)]> \q
Bye #成功
(7)测试数据库是否能互通
[[email protected] ~]# vim /var/www/html/index.php
<?php
$link=mysql_connect('192.168.35.100','zabbix','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>
打开浏览器进行刷新
3、部署zabbix Server
(1)安装必要的环境包
[[email protected] html]# yum install php-bcmath php-mbstring -y
(2)安装zabbix的yum源
[[email protected] html]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm #会自动生成yum源文件,保证系统可以上网
获取http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.Yg93VM: 头V4 RSA/SHA512 Signature, ** ID a14fe591: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:zabbix-release-3.5-1.el7 ################################# [100%]
[[email protected] html]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo zabbix.repo
[[email protected] html]# cat /etc/yum.repos.d/zabbix.repo #查看源
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://repo.zabbix.com/zabbix/3.5/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=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
(3)安装服务
[[email protected] html]# yum install zabbix-server-mysql zabbix-web-mysql -y
(4)初始化数据模块(生成数据库文件,注意密码不要输成root的)
[[email protected] html]# zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbix
Enter password: #输入密码admin123
(5)修改配置文件
[[email protected] html]# grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
101:DBName=zabbix
117:DBUser=zabbix
125:DBPassword=admin123 #只需修改此行
357:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
475:Timeout=4
518:AlertScriptsPath=/usr/lib/zabbix/alertscripts
529:ExternalScripts=/usr/lib/zabbix/externalscripts
565:LogSlowQueries=3000
(6)修改时区
[[email protected] html]# vim /etc/httpd/conf.d/zabbix.conf
/20 php_value date.timezone Asia/Shanghai
(7)修正图表中文乱码
[[email protected] html]# vim /usr/share/zabbix/include/defines.inc.php
:%s /graphfont/kaiti/g #把所有graphfont替换成kaiti
从微软系统下复制相应的字体文件到 /usr/share/zabbix/fonts 目录中注意字体名称要对应配置文件,且注意大小写
[[email protected] zabbix]# cp STKAITI.TTF /usr/share/zabbix/fonts/
(8)开启服务
[[email protected] zabbix]# systemctl start zabbix-server
[[email protected] zabbix]# systemctl enable zabbix-server
[[email protected] zabbix]# netstat -ntap | grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 6132/zabbix_server
tcp6 0 0 :::10051 :::* LISTEN 6132/zabbix_server
(9)重启apache服务
[[email protected] zabbix]# systemctl restart httpd.service
(10)打开浏览器访问:http://192.168.35.100/zabbix/,安装后登录 用户名Admin 密码:zabbi。
输入用户名:Admin 密码:zabbix
主界面:
设置中文环境:
被监控端配置
1、关闭防火墙
[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.[[email protected] ~]# setenforce 0
2、安装yum源
[[email protected] ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
获取http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.UQWhjo: 头V4 RSA/SHA512 Signature, ** ID a14fe591: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:zabbix-release-3.5-1.el7 ################################# [100%][[email protected] ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo zabbix.repo
3、安装zabbix-agent
[[email protected] ~]# yum install -y zabbix-agent
4、更改配置文件
[[email protected] ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf
13:PidFile=/var/run/zabbix/zabbix_agentd.pid
32:LogFile=/var/log/zabbix/zabbix_agentd.log
43:LogFileSize=0
98:Server=192.168.35.100 #指向监控服务器
139:ServerActive=192.168.35.100 #指向监控服务器
150:Hostname=test #改名字
268:Include=/etc/zabbix/zabbix_agentd.d/*.conf
5、开启服务
[[email protected] ~]# systemctl start zabbix-agent.service
[[email protected] ~]# 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.[[email protected] ~]# netstat -anpt | grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 83504/zabbix_agentd
tcp6 0 0 :::10050 :::* LISTEN 83504/zabbix_agentd
6、增加被控主机--在WEB平台上做
配置-主机-创建主机:
主机:
模板:
返回主界面,刷新,会发现检测到有问题,原因:被监控主机并没有安装apache服务。
当把HTTP服务去掉以后,再去刷新查看就没有问题了