zabbix监控部署
Zabbix部署实验环境:1、安装Nginx2、部署MySQL3、部署php实验环境:主机操作系统IPServerCentOS 7.5172.16.3.226/21ClientCentOS 7.5172.16.3.227/211、安装Nginx[root@k8s-node01 ~]# yum install epel-releasr -y[root@k8s-node01 ~]# yum insta
·
实验环境:
主机 | 操作系统 | IP |
---|---|---|
Server | CentOS 7.5 | 172.16.3.226/21 |
1、安装Nginx
[root@bogon ~]# systemctl stop firewalld
[root@bogon ~]# systemctl disable firewalld
[root@bogon ~]# setenforce 0
[root@bogon ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@bogon ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
[root@bogon ~]# yum clean all
[root@bogon ~]# yum -y install nginx
# 查看Nginx版本
[root@bogon ~]# nginx -v
nginx version: nginx/1.18.0
# 启用Nginx
[root@bogon ~]# systemctl start nginx
[root@bogon ~]# systemctl enable nginx
# 测试
[root@bogon ~]# netstat -anltp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4152/nginx: worker
[root@bogon ~]# curl 127.0.0.1 -I
HTTP/1.1 200 OK
Server: nginx/1.18.0
Date: Wed, 14 Apr 2021 00:58:35 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 29 Oct 2020 15:25:17 GMT
Connection: keep-alive
ETag: "5f9adedd-264"
Accept-Ranges: bytes
2、部署MySQL
[root@bogon ~]# wget https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm
[root@bogon ~]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm
[root@bogon ~]# yum install -y mysql-server
[root@bogon ~]# systemctl start mysqld
[root@bogon ~]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 13451 mysql 15u IPv6 271080 0t0 TCP *:mysql (LISTEN)
3、部署php
[root@bogon ~]# yum -y install epel-release.noarch # 多执行几次
[root@bogon ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@bogon ~]# yum -y install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql
php72w:语言
php72w-devel:语言开发包
php72w-fpm:处理动态请求
php72w-gd:支持图像化处理
php72w-mbstring:可以处理多文本字符串
php72w-mysql:数据库中支持php语言的驱动
# 查看php版本
[root@bogon ~]# php -v
PHP 7.2.34 (cli) (built: Oct 1 2020 13:37:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
# 修改PHP 用户跟组
[root@bogon ~]# vim /etc/php-fpm.d/www.conf
8 user = nginx
10 group = nginx
# 修改Nginx默认访问页面
[root@bogon ~]# vim /etc/nginx/conf.d/default.conf
10 index index.php index.html index.htm; # 添加index.php
# 取消注释
30 location ~ \.php$ {
31 root /usr/share/nginx/html;
32 fastcgi_pass 127.0.0.1:9000;
33 fastcgi_index index.php;
34 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
35 include fastcgi_params;
36 }
[root@bogon ~]# vim /etc/php.ini
//202 short_open_tag = On # 支持php短标签
//359 expose_php = Off # 隐藏php版本
//368 max_execution_time = 300 # 修改执行时间为300s
//378 max_input_time = 300 # 修改接收数据等待时间
//656 post_max_size = 16M # post数据大小
//799 upload_max_filesize = 2M # 上传文件大小为2M
//800 always_populate_raw_post_data = -1 # 使原始数据可以直接被处理
//878 date.timezone = Asia/Shanghai # 修改时区
[root@bogon ~]# systemctl start php-fpm
[root@bogon ~]# systemctl enable php-fpm
[root@bogon ~]# netstat -anltp | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 31043/php-fpm: mast
4、测试连接数据库
[root@bogon ~]# vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
[root@bogon ~]# systemctl restart php-fpm.service
[root@bogon ~]# systemctl restart nginx
==访问一下index.php==
http://172.16.3.226/index.php
[root@bogon ~]# vim /usr/share/nginx/html/index.php # 再次编写刚刚页面
<?php
$link=mysqli_connect('127.0.0.1','root','chinaedu');
if ($link) echo '连接成功';
else echo '连接失败';
?>
==访问一下index.php==
http://172.16.3.226/index.php
[root@bogon ~]# mysql -uroot -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to 'zabbix'@'%' identified by 'chinaedu';
mysql> flush privileges;
[root@bogon ~]# vim /usr/share/nginx/html/index.php
<?php
$link=mysqli_connect('127.0.0.1','zabbix','chinaedu');
if ($link) echo 'zabbix连接成功';
else echo 'zabbix连接失败';
?>
5、部署Zabbix Server
[root@bogon ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@bogon ~]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
[root@bogon ~]# cd /usr/share/doc/zabbix-server-mysql-4.0.30/
[root@bogon zabbix-server-mysql-4.0.30]# zcat create.sql.gz | mysql -uzabbix -p zabbix # 导入sql文件
[root@bogon zabbix-server-mysql-4.0.30]# mysql -uzabbix -p
mysql> use zabbix
mysql> show tables;
[root@bogon zabbix-server-mysql-4.0.30]# vim /etc/zabbix/zabbix_server.conf # 编写zabbix服务端配置文件
//38 LogFile=/var/log/zabbix/zabbix_server.log # 定义日志文件位置和名称
//49 LogFileSize=0 # 定义日志文件大小,0表示不限制大小
//72 PidFile=/var/run/zabbix/zabbix_server.pid # 进程文件位置
//82 SocketDir=/var/run/zabbix # 通信sock文件
//91 DBHost=localhost # 数据库所在服务器,本地
//100 DBName=zabbix # 数据库名称
//116 DBUser=zabbix # 数据库用户
//124 DBPassword=chinaedu # 数据库密码
//356 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log # snmp协议日志位置
//473 Timeout=4 # 定义超时时间
//516 AlertScriptsPath=/usr/lib/zabbix/alertscripts # 告警的脚本存放位置
//527 ExternalScripts=/usr/lib/zabbix/externalscripts # 扩展性脚本存放位置
//563 LogSlowQueries=3000 # 定义慢查询时间
[root@bogon zabbix-server-mysql-4.0.30]# cp -r /usr/share/zabbix/ /usr/share/nginx/html
[root@bogon zabbix-server-mysql-4.0.30]# chown -R zabbix.zabbix /etc/zabbix
[root@bogon zabbix-server-mysql-4.0.30]# chown -R zabbix.zabbix /usr/share/nginx
[root@bogon zabbix-server-mysql-4.0.30]# chown -R zabbix.zabbix /usr/lib/zabbix
[root@bogon zabbix-server-mysql-4.0.30]# chmod -R 755 /etc/zabbix/web
[root@bogon zabbix-server-mysql-4.0.30]# chmod -R 777 /var/lib/php/session
[root@bogon zabbix-server-mysql-4.0.30]# systemctl start zabbix-server.service
[root@bogon zabbix-server-mysql-4.0.30]# systemctl enable zabbix-server.service
[root@bogon zabbix-server-mysql-4.0.30]# netstat -napl | grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 1733/zabbix_server
tcp6 0 0 :::10051 :::* LISTEN 1733/zabbix_server
[root@bogon zabbix-server-mysql-4.0.30]# systemctl restart php-fpm
==访问zabbix==
http://172.16.3.226/zabbix
[root@bogon zabbix-server-mysql-4.0.30]# cd /etc/zabbix/web
[root@bogon web]# chmod +x zabbix.conf.php
# 默认用户密码
Admin zabbix
设置中文
更多推荐
已为社区贡献9条内容
所有评论(0)