部署Zabbix监控平台(详解)

部署Zabbix监控平台

实验拓扑结构

主机名称

网卡IP地址

Zabbixserver

Eth1:192.168.2.5

zabbixclient_web1

Eth1:192.168.2.100

zabbixclient_web2

Eth1:192.168.2.200


步骤一:部署监控服务器

1)安装LNMP环境

Zabbix监控管理控制台需要通过Web页面展示出来,并且还需要使用MySQL来存储数据,因此需要先为Zabbix准备基础LNMP环境。

Nmcli  connection add type ethernet ifname eth1 con-name eth1

nmcli  connection modify eth0 ipv4.method manual ipv4.addresses"192.168.4.1/24" connection.autoconnect yes

nmcli  connection up eth0

ifconfig   eth0

nmcli   connection modify eth1 ipv4.method manual ipv4.addresses  "192.168.2.5/24"  connection.autoconnect yes

nmcli   connection up eth1

ifconfig   eth1


Nmcli   connection add type ethernet ifname eth1 con-name eth1

nmcli   connection modify eth0 ipv4.method manual ipv4.addresses "192.168.4.2/24" connection.autoconnect yes

nmcli   connection up eth0

ifconfig   eth0

nmcli   onnection modify eth1 ipv4.method manual ipv4.addresses"192.168.2.100/24" connection.autoconnect yes

nmcli   connection up eth1

ifconfig   eth1


Nmcli   connection add type ethernet ifname eth1 con-name eth1

nmcli   connection modify eth0 ipv4.method manual ipv4.addresses"192.168.4.3/24" connection.autoconnect yes

nmcli  connection up eth0

ifconfig   eth0

nmcli   connection modify eth1 ipv4.method manual ipv4.addresses   "192.168.2.200/24" connection.autoconnect yes

nmcli   connection up eth1

ifconfig   eth1


[root@rootroom9pc01~]# for i in {1..3}; do ssh-copy-id 192.168.4.$i; done

[root@rootroom9pc01~]# vim /etc/hosts

192.168.4.1 zabbixserver

192.168.4.2 zabbixclient_web1

192.168.4.3 zabbixclient_web2


hostnamectlset-hostname zabbixserver

hostnamectlset-hostname zabbixclient_web1

hostnamectlset-hostname zabbixclient_web1


[root@rootroom9pc01~]# ssh zabbixserver

[root@rootroom9pc01~]# ssh zabbixclient_web1

[root@rootroom9pc01~]# ssh zabbixclient_web1


[root@rootroom9pc01~]# for i in {1..3}

>do

>scp -r /etc/yum.repos.d/rhel7.4.repo 192.168.4.$i:/etc/yum.repos.d/

>done


[root@zabbixserver~]# yum -y install gcc pcre-devel openssl-devel

[root@rootroom9pc01~]# scp -r '/root/桌面/nginx-1.12.2.tar.gz'zabbixserver:/root

[root@zabbixserver~]# tar -xf nginx-1.12.2.tar.gz

[root@zabbixserver~]# cd nginx-1.12.2

[[email protected]]# useradd -s /sbin/nologin nginx

[[email protected]]# ./configure --user=nginx --group=nginx --with-http_ssl_module

[[email protected]]# make && make install

[[email protected]]# cd

[root@zabbixserver~]# yum -y install php php-mysql mariadb mariadb-develmariadb-server

[root@rootroom9pc01~]# scp -r '/root/桌面/lnmp_soft.tar.gz'zabbixserver:/root

[root@zabbixserver~]# tar -xf lnmp_soft.tar.gz

[root@zabbixserver~]# cd lnmp_soft/

[root@zabbixserverlnmp_soft]# yum -y install php-fpm-5.4.16-42.el7.x86_64.rpm

[root@zabbixserverlnmp_soft]# vim /usr/local/nginx/conf/nginx.conf

#user nobody;

worker_processes 1;


#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;


#pid logs/nginx.pid;



events{

worker_connections 1024;

}



http{

include mime.types;

default_type application/octet-stream;

fastcgi_buffers8 16k;

fastcgi_buffer_size32k;

fastcgi_connect_timeout300;

fastcgi_send_timeout300;

fastcgi_read_timeout300;

#log_format main '$remote_addr - $remote_user [$time_local] "$request"'

# '$status $body_bytes_sent "$http_referer"'

# '"$http_user_agent""$http_x_forwarded_for"';


#access_log logs/access.log main;


sendfile on;

#tcp_nopush on;


#keepalive_timeout 0;

keepalive_timeout 65;


#gzip on;


server{

listen 80;

server_name localhost;


#charsetkoi8-r;


#access_log logs/host.access.log main;


location/ {

root html;

index index.php index.html index.htm;

}


#error_page 404 /404.html;


#redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location= /50x.html {

root html;

}


#proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location~ \.php$ {

# proxy_pass http://127.0.0.1;

#}


#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

include fastcgi.conf;

}


#deny access to .htaccess files, if Apache's document root

#concurs with nginx's one

#

#location~ /\.ht {

# deny all;

#}

}



#another virtual host using mix of IP-, name-, and port-basedconfiguration

#

#server{

# listen 8000;

# listen somename:8080;

# server_name somename alias another.alias;


# location / {

# root html;

# index index.html index.htm;

# }

#}



#HTTPS server

#

#server{

# listen 443 ssl;

# server_name localhost;


# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;


# ssl_session_cache shared:SSL:1m;

# ssl_session_timeout 5m;


# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;


# location / {

# root html;

# index index.html index.htm;

# }

#}


}


[root@zabbixserverlnmp_soft]# cd

[root@zabbixserverlnmp_soft]# cd

[root@zabbixserver~]# /usr/local/nginx/sbin/nginx

[root@zabbixserver~]# ss -utnlp | grep :80

tcp LISTEN 0 128 *:80 *:* users:(("nginx",pid=11327,fd=6),("nginx",pid=11326,fd=6))

[root@zabbixserver~]# systemctl start mariadb

[root@zabbixserver~]# systemctl status mariadb

[root@zabbixserver~]# systemctl enable mariadb

[root@zabbixserver~]# systemctl start php-fpm

[root@zabbixserver~]# systemctl status php-fpm

[root@zabbixserver~]# systemctl enable php-fpm

[root@zabbixserver~]# firewall-cmd –set-default-zone=trusted

[root@zabbixserver~]# setenforce 0

[root@zabbixserver~]# vim /etc/php-fpm.d/www.conf

[www]

listen= 127.0.0.1:9000 //PHP端口号

pm.max_children= 32 //最大进程数量

pm.start_servers= 15 //最小进程数量

pm.min_spare_servers= 5 //最少需要几个空闲着的进程

pm.max_spare_servers= 32 //最多允许几个进程处于空闲状态


[root@zabbixserver~]# vim /usr/local/nginx/html/test2.php

<?php

$mysqli= new mysqli('localhost','root','','mysql');

//注意:rootmysql账户名称,密码需要修改为实际mysql密码,无密码则留空即可

if(mysqli_connect_errno()){

die('Unableto connect!'). mysqli_connect_error();

}

$sql= "select * from user";

$result= $mysqli->query($sql);

while($row= $result->fetch_array()){

printf("Host:%s",$row[0]);

printf("</br>");

printf("Name:%s",$row[1]);

printf("</br>");

}

?>


[root@rootroom9pc01~]# firefox http://192.168.4.1/test2.php











[root@zabbixserver~]# ln -s /usr/local/nginx/sbin/nginx /sbin/nginx


步骤二:部署监控服务器ZabbixServer


1)源码安装ZabbixServer

多数源码包都是需要依赖包的,zabbix也一样,源码编译前需要先安装相关依赖包。

[root@zabbixserverlnmp_soft]# yum -y install net-snmp-devel curl-devel

[root@zabbixserverlnmp_soft]# yum -y install libevent-devel-2.0.21-4.el7.x86_64.rpm

[root@zabbixserverlnmp_soft]# tar -xf zabbix-3.4.4.tar.gz

[root@zabbixserverlnmp_soft]# cd zabbix-3.4.4/

[[email protected]]# ./configure --enable-server --enable-proxy--enable-agent --with-mysql=/usr/bin/mysql_config --with-net-snmp–with-libcurl

[[email protected]]# make && make install


2)初始化Zabbix

创建数据库,上线ZabbixWeb页面

[[email protected]]# cd

[root@zabbixserver~]# mysql

MariaDB[(none)]> create database zabbix character set utf8;

MariaDB[(none)]> grant all on zabbix.* to zabbix@'localhost' identifiedby 'zabbix';

MariaDB[(none)]> \q

[root@zabbixserver~]# cd lnmp_soft/zabbix-3.4.4/database/mysql/

[root@zabbixservermysql]# mysql -uzabbix -pzabbix zabbix < schema.sql

[root@zabbixservermysql]# mysql -uzabbix -pzabbix zabbix < images.sql

[root@zabbixservermysql]#

mysql-uzabbix -pzabbix zabbix < data.sql

上线ZabbixWeb页面

[root@zabbixservermysql]# cd

[root@zabbixserver~]# cd lnmp_soft/zabbix-3.4.4/frontends/php/

[root@zabbixserverphp]# cp -r * /usr/local/nginx/html/

[root@zabbixserverphp]# chmod -R 777 /usr/local/nginx/html/*

修改Zabbix_server配置文件,设置数据库相关参数,启动Zabbix_server服务

[root@zabbixserverphp]# vim /usr/local/etc/zabbix_server.conf

DBHost=localhost

//数据库主机,默认该行被注释

DBName=zabbix

//设置数据库名称

DBUser=zabbix

//设置数据库账户

DBPassword=zabbix

//设置数据库密码,默认该行被注释

LogFile=/tmp/zabbix_server.log

//设置日志,仅查看以下即可

[root@zabbixserverphp]# useradd -s /sbin/nologin zabbix

[root@zabbixserverphp]# zabbix_server

[root@zabbixserverphp]# ss -ntulp | grep zabbix_server

tcp LISTEN 0 128 *:10051 *:*

提示:如果是因为配置文件不对,导致服务无法启动时,不要重复执行zabbix_server

一定要先使用killallzabbix_server关闭服务后,再重新启动一次。

修改Zabbix_agent配置文件,启动Zabbix_agent服务

Server=127.0.0.1,192.168.2.5//允许哪些主机监控本机

ServerActive=127.0.0.1,192.168.2.5 //允许哪些主机通过主动模式监控本机

Hostname=zabbixserver //设置本机主机名

LogFile=/tmp/zabbix_server.log //设置日志文件

UnsafeUserParameters=1 //是否允许自定义key

[root@zabbixserverphp]# zabbix_agentd

[root@zabbixserverphp]# ss -ntulp |grep zabbix_agentd

tcp LISTEN 0 128 *:10050 *:*

提示:如果是因为配置文件不对,导致服务无法启动时,不要重复执行zabbix_agentd

一定要先使用killallzabbix_agentd关闭服务后,再重新启动一次。

浏览器访问Zabbix_server服务器的Web页面

根据错误提示,修改PHP配置文件,满足Zabbix_serverWeb环境要求

php-bcmathphp-mbstring

[root@zabbixserverphp]# yum -y install php-gd php-xml

[root@zabbixserverphp]# cd

[root@zabbixserver~]# cd lnmp_soft/

[root@zabbixserverlnmp_soft]# yum -y install php-bcmath-5.4.16-42.el7.x86_64.rpm

[root@zabbixserverlnmp_soft]# yum -y install php-mbstring-5.4.16-42.el7.x86_64.rpm

[root@zabbixserverlnmp_soft]# vim /etc/php.ini

date.timezone= Asia/Shanghai //设置时区

max_execution_time= 300 //最大执行时间,秒

post_max_size= 32M //POST数据最大容量

max_input_time= 300 //服务器接收数据的时间限制

memory_limit= 128M //内存容量限制

[root@zabbixserverlnmp_soft]# systemctl restart php-fpm

[root@rootroom9pc01~]# firefox http://192.168.4.1/index.php











这里有一个PHPLDAPwarning状态是没有问题的!

在初始化数据库页面,填写数据库相关参数











Password:zabbix














可以在监测中--》最新数据--》选择主机群组--》主机--》应用--》查看图形


























在登陆页面,使用用户(admin)和密码(zabbix)登陆,登陆后设置语言环境为中文

步骤三:部署被监控主机ZabbixAgent

1)源码安装Zabbixagent软件

2.1002.200做相同操作(以zabbixclient_web1为例)。

[root@zabbixclient_web1~]# useradd -s /sbin/nologin zabbix

[root@zabbixclient_web1~]# yum -y install gcc pcre-devel

[root@zabbixserver~]# cd lnmp_soft/

[root@zabbixserverlnmp_soft]# scp -r zabbix-3.4.4.tar.gz 192.168.4.2:/root

[root@zabbixclient_web1~]# tar -xf zabbix-3.4.4.tar.gz

[root@zabbixclient_web1~]# cd zabbix-3.4.4/

[root@zabbixclient_web1zabbix-3.4.4]# ./configure –enable-agent

[root@zabbixclient_web1zabbix-3.4.4]# make && make install

[root@zabbixclient_web1zabbix-3.4.4]# vim /usr/local/etc/zabbix_agentd.conf

Server=127.0.0.1,192.168.2.5 //谁可以监控本机(被动监控模式)

ServerActive=127.0.0.1,192.168.2.5 //谁可以监控本机(主动监控模式)

Hostname=zabbixclient_web1 //被监控端自己的主机名

EnableRemoteCommands=1

[root@zabbixclient_web1zabbix-3.4.4]# zabbix_agentd

3)拷贝启动脚本(非必须操作,可选做),有启动脚本可以方便管理服务,启动与关闭服务。启动脚本位于zabbix源码目录下。

[root@zabbixclient_web1zabbix-3.4.4]# cd misc/init.d/fedora/core

[root@zabbixclient_web1zabbix-3.4.4]# cp zabbix_agentd /etc/init.d/

[root@zabbixclient_web1zabbix-3.4.4]# /etc/init.d/zabbix_agentd start

[root@zabbixclient_web1zabbix-3.4.4]# /etc/init.d/zabbix_agentd stop

[root@zabbixclient_web1zabbix-3.4.4]# /etc/init.d/zabbix_agentd status

[root@zabbixclient_web1zabbix-3.4.4]# /etc/init.d/zabbix_agentd restar

使用火狐浏览器登录http://192.168.2.5,通过Configuration(配置)-->Hosts(主机)-->CreateHost(创建主机)添加被监控Linux主机































此时先不点击“添加”等Zabbix通过监控模板来对监控对象实施具体的监控功能,根据模板来定义需要监控哪些数据,对于Linux服务器的监控,Zabbix已经内置了相关的模板(TemplateOS Linux),选择模板并链接到主机即可





















点击虚线的添加,然后添加





















cupload



猜你喜欢

转载自blog.csdn.net/weixin_40018205/article/details/81052299
今日推荐