Centos7+Prometheus2.31.1监控Redis6.2.6Nginx1.20.2Grafana8.3.3(亲测有效)

1、Nginx1.20.2安装:

# wget http://nginx.org/download/nginx-1.20.2.tar.gz
# yum -y install  gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel firewalld autoconf automake
# useradd -M -s /sbin/nologin www
# cat /etc/passwd
# cat /etc/group
# tar -zxvf nginx-1.20.2.tar.gz
# cd nginx-1.20.2/
# ./configure --prefix=/usr/local/nginx --user=www --group=www  --with-http_ssl_module --with-http_realip_module  --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module
# make&&make install

编辑nginx服务:vim /etc/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

开机启动:systemctl enable nginx.service        
启动nginx:/usr/local/nginx/sbin/nginx
平滑重启:/usr/local/nginx/sbin/nginx -s reload
强行停止:/usr/local/nginx/sbin/nginx -s stop 
从容停止:/usr/local/nginx/sbin/nginx -s quit
启动:systemctl start nginx 
停止:systemctl stop nginx 
重启:systemctl reload nginx 
查看服务状态:systemctl status nginx

卸载nginx:

# systemctl stop nginx.service
# rm -rf /usr/local/nginx/
# rm -rf /etc/systemd/system/multi-user.target.wants/nginx.service

2、Redis6.2.6安装:

# wget https://download.redis.io/releases/redis-6.2.6.tar.gz
# tar xzf redis-6.2.6.tar.gz -C /usr/local/
# cd /usr/local/
# mv redis-6.2.6/ redis
# cd redis
# make
# make install PREFIX=/usr/local/redis
# make test 

如果出现这行英文All tests passed without errors! 证明redis服务已安装完毕。

cp ./redis.conf /usr/local/redis/bin/

修改配置参数:
vim /usr/local/redis/redis.confvi /usr/local/redis/bin/redis.conf
protected-mode no #关闭保护模式
daemonize yes #守护进程模式开启
#bind 127.0.0.1 #注释配置后开启远程访问
并改成自己的IP地址
requirepass 123456 #密码
logfile "/data/redis6/logs/redis.log" #需要设置日志目录
dir /data/redis6/data/ #需要设置数据保存目录
io-threads 1 #需要设置io线程数

开机自动运行:vim /lib/systemd/system/redis.service

[Unit]
Description=Redis
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
ExecReload=/usr/local/redis/bin/redis-server -s reload
ExecStop=/usr/local/redis/bin/redis-server -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重新加载服务:systemctl daemon-reload
启动redis服务:systemctl start redis.service
停止redis服务:systemctl stop redis.service
重新启动服务:systemctl restart redis.service
查看服务当前状态:systemctl status redis.service  
设置开机自启动:systemctl enable redis.service
停止开机自启动:systemctl disable redis.service
查看端口:ss -anlt

卸载:
find / -name redis
rm -rf 显示的目录

3、Redis监控

1、下载和安装redis_exporter
下载redis_exporter安装包,下载地址:wget https://github.com/oliver006/redis_exporter/releases/download/v1.32.0/redis_exporter-v1.32.0.linux-amd64.tar.gz

tar -zxf redis_exporter-v1.32.0.linux-amd64.tar.gz -C /usr/local/prometheus/P_tools/
cd /usr/local/prometheus/P_tools/
mv redis_exporter-v1.32.0.linux-amd64 /usr/local/prometheus/P_tools/redis_exporter

2、编辑redis_exporter 服务:vim /etc/systemd/system/redis_exporter.service

[Unit]
Description=redis_exporter
Documentation=https://github.com/oliver006/redis_exporter
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus/P_tools/redis_exporter/redis_exporter -redis.addr 192.168.159.131:6379  -redis.password 123456
Restart=on-failure

[Install]
WantedBy=multi-user.target

 3、创建prometheus用户并授权

# groupadd prometheus
# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
# chown -R prometheus:prometheus /usr/local/redis_exporter

重新载入配置文件:systemctl daemon-reload
开机启动:systemctl enable redis_exporter
开启服务:systemctl start redis_exporter
查看服务状态:systemctl status redis_exporter
查看端口:ss -tln | grep 9121

4、编辑 prometheus.yml 

 重启prometheus:systemctl restart prometheus

现在进入https://grafana.com/grafana/dashboards/网站去搜索Redis的json模板文件,我这里下载的是Redis Dashboard for Prometheus Redis Exporter
把刚才下载的json模板文件在Grafana平台里点击左侧菜单的Import导入按钮进行导入,也可以直接输入下载json模板文件的ID编号后点击load进行读取
成功导入json模板文件后,监控的各项模块相继的就展示出来了。(如果数据没出来,稍微等一会儿就好了,下面是所展示的监控数据。)

 

持续更新~

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>