注意:我这里使用之前写好脚本进行安装Docker,如果已经有Docker请省略此步骤,安装Docker是为了方便部署Redis数据库,如果已经有数据库前两步骤都可以省略。
点击获取Docker离线安装脚本
tar zxf docker20.10.14Install.tar.gz
cd docker20.10.14Install
bash install.sh
查看Docker状态如下图表示没问题:
systemctl status docker
1、前提准备:
docker pull redis:6.2.6
mkdir /home/software/redis/{data,logs} -p
chmod 777 /home/software/redis/logs
systemctl stop firewalld
systemctl disable firewalld
iptables -F
2、创建配置文件
cat > /home/software/redis/data/redis.conf << EOF
bind 0.0.0.0
port 6379
requirepass 123456
logfile /tmp/redis.log
save 60 1
EOF
2、运行容器:
docker run -itd --name redis \
-v /home/software/redis/data:/data \
-v /home/software/redis/logs:/tmp \
-v /etc/localtime:/etc/localtime \
-p 6379:6379 --restart=always \
redis:6.2.6 redis.conf
3、测试容器是否可连接
docker exec -it redis redis-cli
127.0.0.1:6379> AUTH 123456
OK
连接到redis数据库后,输入我们设置的密码,可以连接证明没问题了,如下图:
1、时间和时区同步
timedatectl set-timezone Asia/Shanghai
yum -y install ntpdate
/usr/sbin/ntpdate -u ntp1.aliyun.com
配置计划任务定时同步时间
echo "0 5 * * * /usr/sbin/ntpdate -u ntp1.aliyun.com >/dev/null &" >> /var/spool/cron/root
crontab -l
2、安装Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.42.0/prometheus-2.42.0.linux-amd64.tar.gz
tar zxf prometheus-2.42.0.linux-amd64.tar.gz
mv prometheus-2.42.0.linux-amd64 /usr/local/prometheus
3、配置systemd管理
cat > /usr/lib/systemd/system/prometheus.service << EOF
[Unit]
[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
Alias=dbus-org.fedoraproject.FirewallD1.service
EOF
4、启动并设置开机自启
systemctl enable prometheus --now
systemctl status prometheus
显示如上图,表示Prometheus也没问题了,默认端口是9090,我们可以浏览器访问一下
点击 Status
> Targets
可以查看到Prometheus自己的metrics如下图:
1、安装Grafana
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.4.1-1.x86_64.rpm
sudo yum install grafana-enterprise-9.4.1-1.x86_64.rpm -y
systemctl enable grafana-server.service --now
2、WEB页面验证
默认端口是3000,第一次访问会提示重新设置密码,如下图:
1、安装redis_exporter
wget https://github.com/oliver006/redis_exporter/releases/download/v1.48.0/redis_exporter-v1.48.0.linux-amd64.tar.gz
tar zxf redis_exporter-v1.48.0.linux-amd64.tar.gz -C /usr/local
cd /usr/local
mv redis_exporter-v1.48.0.linux-amd64 redis_exporter
2、配置systemd管理
cat > /usr/lib/systemd/system/redis_exporter.service << EOF
[Unit]
Description=redis_exporter Service
After=network.target
[Service]
Type=simple
# 注意指定Redis 主机+密码(根据当前环境指定)
ExecStart=/usr/local/redis_exporter/redis_exporter -redis.addr 16.32.15.115 -redis.password 123456
ExecReload=/bin/kill -HUP \$MAINPID
Restart=on-failure
RestartSec=30s
[Install]
WantedBy=multi-user.target
EOF
启动并加入开机自启动
systemctl enable redis_exporter --now
systemctl status redis_exporter
默认端口为9121
netstat -anput |grep 9121
4、Prometheus配置文件中指定redis_exporter信息
vim /usr/local/prometheus/prometheus.yml
- job_name: "Redis_115"
static_configs:
- targets: ["16.32.15.115:9121"]
添加完成配置文件后使用命令测试格式上是否有问题
cd /usr/local/prometheus/
./promtool check config prometheus.yml
重启Prometheus
systemctl restart prometheus.service
这里使用Redis的模板ID:11835
点击 下方红圈地方
> import
> 输入模板ID
最终效果图如下: