zabbix学习1:zabbix-简单介绍和zabbix的安装

1:什么是监控?

监视和控制,
生活中的监控:事后追责
运维中的监控:事后追责,事前预警,性能分析,实时报警

2:常见的linux监控命令

cpu,内存,磁盘,网络

top
htop
uptime
free
vmstat
iostat
df
iftop
nethogs

3:使用shell脚本来监控服务器

没有监控工具的时候,shell脚本+定时任务 监控服务器

[root@k8s ~]# cat mem_alter.sh
#!/bin/bash
MEM=`free -m|awk 'NR==2{print $NF}'`
if [ $MEM -lt 100 ];then
echo "web服务器 192.168.2.104 可用内存不足,当前可用内存
$MEM" | mail -s "web服务器内存不足" [email protected]
fi

缺点:效率低,不能实现集中报警,不能分析历史数据
我只有一台云主机需要监控,适合shell脚本+定时任务

4: zabbix的基础服务架构

在这里插入图片描述

5: zabbix生产环境安装

主机 :zabbix-server
ip地址: 10.0.0.71
操作系统版本: centos 7.6

5.1:安装php运行环境

要求php版本 7.2以上+
安装php第三方源

yum install epel-release -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtaticrelease.rpm
yum install php72w-fpm php72w-gd.x86_64 php72wbcmath.x86_64 php72w-xml.x86_64 php72w-mbstring.x86_64
php72w-ldap.x86_64 php72w-mysqlnd.x86_64 -y

安装nginx

yum install nginx -y

配置php-fpm和nginx

vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
vim /etc/nginx/nginx.conf
worker_processes 1;
events {
    
    
	worker_connections 1024;
}
http {
    
    
	include mime.types;
	default_type application/octet-stream;
	sendfile on;
	keepalive_timeout 65;
	server {
    
    
		listen 80;
		server_name localhost;
		location / {
    
    
			root /html;
			index index.php index.html index.htm;
		}
		location ~ \.php$ {
    
    
				root /html;
				fastcgi_pass 127.0.0.1:9000;
				fastcgi_index index.php;
				fastcgi_param SCRIPT_FILENAME /html$fastcgi_script_name;
				include fastcgi_params;
		}
	}
}

启动nginx和php-fpm

mkdir /html
nginx -t
systemctl start nginx
systemctl enable nginx
systemctl start php-fpm
systemctl enable php-fpm

准备zabbix-web的php代码

wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.8.tar.gz
tar xf zabbix-5.0.8.tar.gz
cd zabbix-5.0.8/ui/
cp -a * /html/
chown -R nginx:nginx /html
#解决首次访问 zabbix-web安装界面 error 500的错误
mkdir /var/lib/php/session
chown -R nginx:nginx /var/lib/php/session/

在这里插入图片描述
在这里插入图片描述

#解决方法:
vim /etc/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
systemctl restart php-fpm.service

在这里插入图片描述

5.2:安装数据库

#参数链接https://www.jianshu.com/p/dd7137c4efa5
120 tar xf mysql-5.7.32-linux-glibc2.12-
x86_64.tar.gz
122 mkdir /app
123 mv mysql-5.7.32-linux-glibc2.12-x86_64
/app/mysql
125 vim /etc/profile
126 source /etc/profile
127 useradd mysql
128 mkdir /data/mysql -p
129 chown -R mysql.mysql /app/*
130 chown -R mysql.mysql /data/*
132 yum install libaio-devel -y
133 mysqld --initialize --user=mysql --
basedir=/app/mysql --datadir=/data/mysql
138 vim /etc/my.cnf
139 vim /etc/systemd/system/mysqld.service
140 systemctl start mysqld.service
141 netstat -lntup
142 systemctl enable mysqld
143 mysql -uroot -p'j>jd&D;2(1_E'
146 mysqladmin -uroot -p'j>jd&D;2(1_E' password
'1qaz@WSX'
147 mysql -uroot -p'1qaz@WSX'
#创库授权
create database zabbix character set utf8 collate utf8_bin;
create user 'zabbix'@'localhost' identified by '123456';
grant all privileges on zabbix.* to 'zabbix'@'localhost';

5.3:安装zabbix-server

配置zabbix 5.0的源

rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbixrelease-5.0-1.el7.noarch.rpm
sed -i 's#http://repo.zabbix.com#https://mirrors.tuna.tsinghua.edu.cn/zabbix#g' /etc/yum.repos.d/zabbix.repo

安装zabbix-server

1 yum install zabbix-server-mysql -y

导入zabbix初始数据

zcat /usr/share/doc/zabbix-server-mysql-*/create.sql.gz|mysql -uzabbix -p123456 zabbix

配置zabbix-server

vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBSocket=/tmp/mysql.sock

启动zabbix-server

systemctl start zabbix-server.service
systemctl enable zabbix-server.service
netstat -lntup|grep 10051

5.4: 安装zabbix-web

在这里插入图片描述
解决方法:

vim /etc/php.ini
pdo_mysql.default_socket= /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

systemctl restart php-fpm

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
登录zabbix
用户名: Admin
密码:zabbix
在这里插入图片描述
在这里插入图片描述
调整语言为中文
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xiaoleinb/article/details/113757468