Cacti | 特点:将监控到的数据,绘制成各种图形 | 基于SNMP协议 (网络管理协议) 的监控软件,强大的绘图能力 |
Nagios | 特点:状态检查和报警机制 (例如:内存不足或CPU负载高时,及时的给管理员发送报警信息(邮件报警,短信报警等) ) | 基于Agent监控,强大的状态检查与报警机制,插件极多,自己写监控脚本嵌入到Nagios非常方便 |
zabbix | 特点:支持多种报警机制,支持分布式监控,支持数据绘图 | 基于多种监控机制,支持分布式监控 |
Zabbix 是一个高度集成的监控解决方案,可以实现企业级的开源分布式监控,
Zabbix 通过 C/S模式采集监控数据
C/S (client/server): 客户端/服务器
客户端程序负载采集要监控的数据,然后发送给监控服务器;
监控服务器对客户发送过来的数据进行存储和处理;
Zabbix通过B/S模式实现Web管理
1.3.2 监控拓扑B/S (browser/server): 浏览器/服务器
管理员可以通过浏览器,访问监控服务器web页面,并可以查看和管理监控系统
Zabbix监控原理: |
部署一个Zabbix监控服务器, 用于存储和处理监控数据; |
如果被监控的是Linux或Windows主机,需要安装客户端程序agent来采集监控数据; |
如果被监控的是网络设备(交换机,路由器等),通过SNMP协议进行监控; |
最后Zabbix监控服务器,将客户端收集来的数据存储到数据库中,通过web页面来管理 |
监控角色 |
监控服务器 |
监控服务器可以通过SNMP (网络管理协议)或Agent采集数据 |
数据可以写入MYSQL、Oracle等数据库中 |
被监控主机 |
被监控主机需要安装Agent |
常见的网络设备一般支持SNMP (网络管理协议) |
这里的话,因为zabbix web系统使用的是php,所以需要配置LNMP环境。
服务器使用LNMP实现web前端的管理
Nginx是一款小巧而高效的Web服务器软件,可帮您在Linux系统下快速方便地搭建出LNMP Web服务环境。在ECS实例上搭建LNMP环境,其中LNMP分别代表Linux、Nginx、MySQL和PHP。
2.1 部署LNMP这里小伙伴可以参考这个:手动部署LNMP环境(CentOS 7)
- 监控服务器(需要使用Web页面操作,因此需要先部署LNMP)设置主机名(zabbixserver)设置IP地址(192.168.26.15)关闭防火墙、SELinux
- 监控客户端 (2.100和2.200)主机web1(192.168.26.14)主机web2(192.168.26.13)关闭防火墙、SELinux
虚拟机环境准备(克隆centos7 模板机): ——> 关闭防火墙和SELinux,嗯,因为需要多个机器,所以我们用ansible,方便一点,这里,192.168.26.15为控制机,192.168.26.14,192.168.26.13 为节点机
主机名 | IP地址 |
zabbixserver | 192.168.26.15 |
web1 | 192.168.26.14 |
web2 | 192.168.26.13 |
配置到物理机的SSH免密
┌──(liruilong㉿Liruilong)-[/mnt/e/docker]
└─$ ssh-copy-id root@192.168.26.13
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/liruilong/.ssh/id_RSA.pub"
The authenticity of host '192.168.26.13 (192.168.26.13)' can't be established.
ECDSA key fingerprint is SHA256:1F/T20FjhEaLDtutI1rXCwOFGZ5nPs3hFzHyjsnAs3Q.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.26.13's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.26.13'"
and check to make sure that only the key(s) you wanted were added.
┌──(liruilong㉿Liruilong)-[/mnt/e/docker]
└─$ ssh-copy-id root@192.168.26.14
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/liruilong/.ssh/id_rsa.pub"
The authenticity of host '192.168.26.14 (192.168.26.14)' can't be established.
ECDSA key fingerprint is SHA256:cfpb8zAi otnaU0YIoRb76iaOYiFDI4JHyU9N0LmNkY.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.26.14's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.26.14'"
and check to make sure that only the key(s) you wanted were added.
┌──(liruilong㉿Liruilong)-[/mnt/e/docker]
└─$ ssh-copy-id root@192.168.26.15
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/liruilong/.ssh/id_rsa.pub"
The authenticity of host '192.168.26.15 (192.168.26.15)' can't be established.
ECDSA key fingerprint is SHA256:Ix6WxiXXJVdMFdSqiXLaPYdg khbzkjuYO4raDDnih0.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.26.15's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.26.15'"
and check to make sure that only the key(s) you wanted were added.
┌──(liruilong㉿Liruilong)-[/mnt/e/docker]
└─$
ansible环境准备
┌──[root@zabbixserver]-[/]
└─$ mkdir ansible;cd ansible;vim ansible.cfg
┌──[root@zabbixserver]-[/ansible]
└─$ cat ansible.cfg
[defaults]
# 主机清单文件,就是要控制的主机列表
inventory=inventory
# 连接受管机器的远程的用户名
remote_user=root
# 角色目录
roles_path=roles
# 设置用户的su 提权
[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False
┌──[root@zabbixserver]-[/ansible]
└─$ vim inventory
┌──[root@zabbixserver]-[/ansible]
└─$ cat inventory
[web]
192.168.26.13
192.168.26.14
[zabbix]
192.168.26.13
192.168.26.14
127.0.0.1
┌──[root@zabbixserver]-[/ansible]
└─$
配置控制机到节点机的SSH免密
┌──[root@zabbixserver]-[/ansible]
└─$ ssh-copy-id root@192.168.26.13
/usr/bin/ssh-copy-id: ERROR: failed to open ID file '/root/.pub': No such file or directory
(to install the contents of '/root/.pub' anyway, look at the -f option)
┌──[root@zabbixserver]-[/ansible]
└─$ ssh-copy-id root@192.168.26.14
/usr/bin/ssh-copy-id: ERROR: failed to open ID file '/root/.pub': No such file or directory
(to install the contents of '/root/.pub' anyway, look at the -f option)
┌──[root@zabbixserver]-[/ansible]
└─$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:/wLemqRJd5tsIWj/hxole6EpNTZ9M2lDooVGnYTx3I4 root@zabbixserver
The key's randomart image is:
---[RSA 2048]----
| o=.. |
| .. o. |
| o = o |
| . = . |
| .S E O |
| oooX. |
| .ooB o |
| . *o*= . |
| o ==o. |
----[SHA256]-----
┌──[root@zabbixserver]-[/ansible]
└─$ ssh-copy-id root@192.168.26.14
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.26.14 (192.168.26.14)' can't be established.
ECDSA key fingerprint is SHA256:cfpb8zAi otnaU0YIoRb76iaOYiFDI4JHyU9N0LmNkY.
ECDSA key fingerprint is MD5:35:32:02:28:b3:2f:9b:11:3c:d9:16:29:ab:2f:75:73.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.26.14's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.26.14'"
and check to make sure that only the key(s) you wanted were added.
┌──[root@zabbixserver]-[/ansible]
└─$ ssh-copy-id root@192.168.26.13
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.26.13 (192.168.26.13)' can't be established.
ECDSA key fingerprint is SHA256:1F/T20FjhEaLDtutI1rXCwOFGZ5nPs3hFzHyjsnAs3Q.
ECDSA key fingerprint is MD5:b3:c9:31:0e:08:31:5b:7b:25:dd:a3:a7:f1:db:ac:7a.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.26.13's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.26.13'"
and check to make sure that only the key(s) you wanted were added.
┌──[root@zabbixserver]-[/ansible]
└─$ ssh-copy-id root@192.168.26.15
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.26.15's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.26.15'"
and check to make sure that only the key(s) you wanted were added.
┌──[root@zabbixserver]-[/ansible]
测试ansible
┌──[root@zabbixserver]-[/ansible]
└─$ ansible all -m ping
192.168.26.13 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.26.14 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
127.0.0.1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
┌──[root@zabbixserver]-[/ansible]
└─$
检查防火墙和selinux
┌──[root@zabbixserver]-[/ansible]
└─$ ansible all -m shell -a 'sed -n 7p /etc/selinux/config'
[WARNING]: Consider using the replace, lineinfile or template module rather than running 'sed'. If
you need to use command because replace, lineinfile or template is insufficient you can add 'warn:
false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this
message.
127.0.0.1 | CHANGED | rc=0 >>
SELINUX=disabled
192.168.26.14 | CHANGED | rc=0 >>
SELINUX=disabled
192.168.26.13 | CHANGED | rc=0 >>
SELINUX=disabled
┌──[root@zabbixserver]-[/ansible]
└─$ ansible all -m shell -a ' systemctl status firewalld | grep Active'
127.0.0.1 | CHANGED | rc=0 >>
Active: active (running) since Fri 2021-10-01 17:48:56 CST; 51min ago
192.168.26.14 | CHANGED | rc=0 >>
Active: active (running) since Fri 2021-10-01 17:49:47 CST; 50min ago
192.168.26.13 | CHANGED | rc=0 >>
Active: active (running) since Fri 2021-10-01 17:49:14 CST; 51min ago
发现防火墙还没有关闭,所以在关闭一下防火墙:
┌──[root@zabbixserver]-[/ansible]
└─$ ansible all -m shell -a 'systemctl disable firewalld --now'
192.168.26.14 | CHANGED | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
192.168.26.13 | CHANGED | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
127.0.0.1 | CHANGED | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
┌──[root@zabbixserver]-[/ansible]
└─$
2.1.2 部署LNMP
┌──[root@zabbixserver]-[/ansible]
└─$ yum -y install nginx php php-fpm php-mysql mariadb-server mariadb mariadb-devel
安装需要的软件包,也可以分别安装
##安装Ng
[root@zabbixserver ~]yum -y install nginx
###安装php解释器及相关软件包
[root@zabbixserver ~]# yum -y install php #php解释器
[root@zabbixserver ~]# yum -y install php-fpm #可以支持 Fastcgi 通用语言
[root@zabbixserver ~]# yum -y install php-mysql #php和数据通信的扩展包
###安装数据库及相关软件包
[root@web1 ~]# yum -y install mariadb-server #数据库服务端软件
[root@web1 ~]# yum -y install mariadb #数据库客户端软件
[root@web1 ~]# yum -y install mariadb-devel #相关的依赖包
修改nginx配置
┌──[root@zabbixserver]-[~]
└─$ vim /etc/nginx/nginx.conf
┌──[root@zabbixserver]-[~]
└─$ cat /etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
fastcgi_buffers 8 16k; #缓存php生成的数据,缓存大小为8个16k
fastcgi_buffer_size 32k; #缓存php产生的头部信息,缓存大小为32k
fastcgi_connect_timeout 300; #连接php的超时时间为300秒
fastcgi_send_timeout 300; #发送请求的超时时间为300秒
fastcgi_read_timeout 300; #读取请求的超时时间为300秒
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
# 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_params;
#}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
通过systemd的方式管理nginx服务,通过源码安装的NG需要
##此文件,每次Linux开机时,都会运行里面的所有命令
[root@zabbixserver ~]# vim /etc/rc.d/rc.local
/usr/local/nginx/sbin/nginx
[root@zabbixserver ~]# chmod x /etc/rc.d/rc.local
####nginx管理服务模板文件路径,也可在百度搜索nginx systemd
https://www.nginx.com/resources/wiki/start/topics/examples/systemd/
#####在/usr/lib/systemcd/systemd下创建nginx服务配置文件
##拷贝模板
[root@web1 ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP server #描述信息
##After 指nginx开机时,启动服务的顺序
After=syslog.target network-online.targetnss-lookup.target
[Service]
#Type 指启动服务后只有一个进程使用simple,有多个进程使用forking
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
####修改路径为/usr/local/nginx/sbin 实际nginx安装路径
##ExecStartPre 指启动服务之前检测nginx配置语法是否正确
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx #启动nginx服务
ExecReload=/usr/local/nginx/sbin/ -s reload #重启nginx服务
ExecStop=/bin/kill -s QUIT $MAINPID #停止nginx服务
PrivateTmp=true
[Install]
#WantedBy 指将nginx服务放到 multi-user.target 服务组
#路径在/etc/systemd/system/multi-user.target
#重启multi-user.target,会启动这个目录下的所有服务
WantedBy=multi-user.target
2.1.4 启动服务
┌──[root@zabbixserver]-[~]
└─$ systemctl enable mariadb.service --now
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
┌──[root@zabbixserver]-[~]
└─$ systemctl enable php-fpm --now
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
┌──[root@zabbixserver]-[~]
└─$ systemctl enable nginx --now
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
┌──[root@zabbixserver]-[~]
└─$
页面测试
######编写php动态测试页面
[root@zabbixserver ~]# vim /usr/local/nginx/html/test.php
<?php
$i=33;
echo $i;
?>
官方文档: 从部署包安装
3.1 部署Zabbix监控端服务器3.1.1 安装软件┌──[root@zabbixserver]-[~]
└─$ ls
anaconda-ks.cfg calico.yaml one-client-install.sh zabbix-3.4.4
calico_3_14.tar download set.sh zabbix-3.4.4.tar.gz
##########安装zabbix相关依赖包
┌──[root@zabbixserver]-[~]
└─$ yum -y install net-snmp-devel curl-devel libevent-devel gcc
##########获取mysql_config的绝对路径 (此命令用于编译mysql的客户端程序)
┌──[root@zabbixserver]-[~]
└─$ mysql_config
Usage: /usr/bin/mysql_config [OPTIONS]
Options:
--cflags [-I/usr/include/mysql]
--include [-I/usr/include/mysql]
--libs [-L/usr/lib64/mysql -lmysqlclient -lpthread -lz -lm -ldl -lssl -lcrypto]
--libs_r [-L/usr/lib64/mysql -lmysqlclient -lpthread -lz -lm -ldl -lssl -lcrypto]
--plugindir [/usr/lib64/mysql/plugin]
--socket [/var/lib/mysql/mysql.sock]
--port [0]
--version [5.5.68]
--libmysqld-libs [-L/usr/lib64/mysql -lmysqld]
--variable=VAR VAR is one of:
pkgincludedir [/usr/include/mysql]
pkglibdir [/usr/lib64/mysql]
plugindir [/usr/lib64/mysql/plugin]
源码安装zabbix软件
#########进入到zabbix源码包下,源码安装zabbix软件
#--enable-server 指安装zabbix服务端模块;
#--enable-agent 指安装zabbix客户端模块(用于收集监控数据,在客户端安装,服务器也可以按照,用于监控自己);
#--enable-proxy 指安装zabbix的代理模块,实现代理功能(此实验用不到);
#--with-mysql= 指定mysql数据库,用于存放客户端收集的监控数据;
#--with-net-snmp 指安装此模块,可以通过snmp协议,去监控网络设备(路由器,交换机);
#--with-libcurl 指安装此模块,可以让zabbix调用curl,获取被监控主机的信息,做健康检查
┌──[root@zabbixserver]-[~]
└─$ cd zabbix-3.4.4/
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$ ls
aclocal.m4 ChangeLog config.sub database INSTALL Makefile.in NEWS src
AUTHORS compile configure depcomp install-sh man README upgrades
bin conf configure.ac frontends m4 misc README.txt
build config.guess COPYING include Makefile.am missing sass
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$ ./configure --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config
#########直接安装,不需要make
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$ make install
查看zabbix相关的配置文件
#########查看zabbix相关的配置文件
#zabbix_server.conf zabbix服务端配置文件
#zabbix_agentd.conf zabbix客户端配置文件
#zabbix_proxy.conf zabbix监控代理的配置文件
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$ ls /usr/local/etc/
zabbix_agentd.conf zabbix_proxy.conf zabbix_server.conf
zabbix_agentd.conf.d zabbix_proxy.conf.d zabbix_server.conf.d
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$
获取目标主机监控数据和向目标主机发送监控数据的命令
#########获取目标主机监控数据和向目标主机发送监控数据的命令
#zabbix_get 获取监控数据的命令
#zabbix_sender 发送监控数据的命令
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$ ls /usr/local/bin/
zabbix_get zabbix_sender
启动zabbix的命令,zabbix默认无法通过systemd管理
########启动zabbix的命令,zabbix默认无法通过systemd管理
#zabbix_agentd zabbix 客户端的启动命令
#zabbix_proxy zabbix 监控代理服务的启动命令
#zabbix_server zabbix 服务端的启动命令
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$ ls /usr/local/sbin/
zabbix_agentd zabbix_proxy zabbix_server
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$
3.1.2初始化准备创建数据库与数据库账户
###########创建zabbix数据库并授权
[root@zabbixserver ~]# mysql
#创建一个zabbix空数据库,用于存储监控数据,设置为utf8格式,可以存储中文
MariaDB [(none)]> create database zabbix character set utf8;
#授权,zabbix用户可以从本机登录mysql
#登录密码为zabbix,对zabbix库下的表拥有所有权限(增删改查)
MariaDB [(none)]> grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix';
#退出数据库
MariaDB [(none)]> exit
导入zabbix提供的备份数据库文件,导入顺序不能发生改变(否则报错)
#########导入zabbix提供的备份数据库文件,导入顺序不能发生改变(否则报错)
##mysql备份数据库文件在zabbix源码包路径:zabbix-3.4.4/database/mysql/
#Oracle备份数据库文件在zabbix源码包路径:zabbix-3.4.4/database/oracle/
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$ ls
aclocal.m4 compile config.sub depcomp m4 misc sass
AUTHORS conf configure frontends Makefile missing src
bin config.guess configure.ac include Makefile.am NEWS upgrades
build config.log COPYING INSTALL Makefile.in README
ChangeLog config.status database install-sh man README.txt
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$ cd database/mysql/
┌──[root@zabbixserver]-[~/zabbix-3.4.4/database/mysql]
└─$ ls
data.sql images.sql schema.sql
┌──[root@zabbixserver]-[~/zabbix-3.4.4/database/mysql]
└─$ mysql -uzabbix -pzabbix zabbix < schema.sql
┌──[root@zabbixserver]-[~/zabbix-3.4.4/database/mysql]
└─$ mysql -uzabbix -pzabbix zabbix < images.sql
┌──[root@zabbixserver]-[~/zabbix-3.4.4/database/mysql]
└─$ mysql -uzabbix -pzabbix zabbix < data.sql
┌──[root@zabbixserver]-[~/zabbix-3.4.4/database/mysql]
└─$
查看mysql的zabbix下的表
┌──[root@zabbixserver]-[~/zabbix-3.4.4/database/mysql]
└─$ mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
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)]> 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 |
| application_discovery |
| application_prototype |
| application_template |
| applications |
。。。。。
| widget |
| widget_field |
----------------------------
140 rows in set (0.00 sec)
#查看zabbix用户名和密码
MariaDB [zabbix]> select alias,passwd from users;
------- ----------------------------------
| alias | passwd |
------- ----------------------------------
| Admin | 5fce1b3e34b520afeffb37ce08c7cd66 |
| guest | d41d8cd98f00b204e9800998ecf8427e |
------- ----------------------------------
2 rows in set (0.00 sec)
MariaDB [zabbix]> exit
Bye
┌──[root@zabbixserver]-[~/zabbix-3.4.4/database/mysql]
└─$
上线Zabbix页面
┌──[root@zabbixserver]-[~/zabbix-3.4.4]
└─$ cd frontends/php/
#拷贝所有内容到nginx网页的默认路径下
┌──[root@zabbixserver]-[~/zabbix-3.4.4/frontends/php]
└─$ cp -r * /usr/share/nginx/html
cp: cannot overwrite non-directory ‘/usr/share/nginx/html/img’ with directory ‘img’
┌──[root@zabbixserver]-[~/zabbix-3.4.4/frontends/php]
└─$ cd /usr/share/nginx/html/
┌──[root@zabbixserver]-[/usr/share/nginx/html]
└─$ chown -R nginx.nginx /usr/share/nginx/html/
┌──[root@zabbixserver]-[/usr/share/nginx/html]
└─$
安装依赖软件
┌──[root@zabbixserver]-[~/zabbix-3.4.4/frontends/php]
└─$ yum -y install php-gd php-xml php-ldap;yum -y install php-bcmath php-mbstring
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package php-gd-5.4.16-48.el7.x86_64 already installed and latest version
Package php-xml-5.4.16-48.el7.x86_64 already installed and latest version
Package php-ldap-5.4.16-48.el7.x86_64 already installed and latest version
Nothing to do
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package php-bcmath-5.4.16-48.el7.x86_64 already installed and latest version
Package php-mbstring-5.4.16-48.el7.x86_64 already installed and latest version
Nothing to do
┌──[root@zabbixserver]-[~/zabbix-3.4.4/frontends/php]
└─$
修改PHP配置文件
######php中,分号【;】 代表注释
┌──[root@zabbixserver]-[~/zabbix-3.4.4/frontends/php]
└─$ vim /etc/php.inii
......
#每个php脚本可最大以执行的时间
384 max_execution_time = 300
......
#服务器接收数据的时间限制为300s
394 max_input_time = 300
......
#客户端连接时,最多可以接受多大的POST请求数据
672 post_max_size = 32M
......
#设置时区
878 date.timezone = Asia/Shanghai
......
重启php-fpm服务
#########重启php-fpm服务
[root@zabbixserver ~]# systemctl restart php-fpm
3.1.3 初始化
嗯。这里可能会遇到配置文件无法写入,无法覆盖的问题,主要是权限的问题,需要给/usr/share/nginx/html/授权
默认登录账户admin,默认密码zabbix
默认登录账户admin,默认密码zabbix |