redis 前言
Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。
redis 参考
redis下载 | RedisDesktopManager |
download | download |
Linux 各系统下载使用参考
Red Hat | Rocky Linux | Oracle Linux | AlmaLinux | ubuntu | suselinux | esxi | RHEL标准安装 | 系统安装参考 | YUM参考 | MobaXterm 远程连接工具 | Red Hat Enterprise 9.0 文档 | Kickstart 生成器 | |||||
download | download | download | download | download | download | download | 参考 | 参考 | 配置参考 | download | 参考 | Kickstart | |||||
版本兼容性 |
安装 Redis
-
创建安装自动化脚本
- 实现在线下载redis,配置redis配置文件,环境变量,防火墙配置,企业微信机器人通知。
- 以下基于Redhat系统
- redis目录 /opt/redis/
- redis 配置文件/opt/redis/conf/
- redis 持久化数据存储 /opt/redis/data/
- redis log 输出到/var/log/redis.log
- redis登录密码Report@123
- redis端口 6379
- Redhat 9 functions使用需要执行安装yum install initscripts -y
- curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXXX' #更改自己的企业微信机器人地址
- curl -o /etc/yum.repos.d/redhat.repo http://mirrors.aliyun.com/repo/Centos-8.repo #阿里在线repo
- yum install figlet -y #用于将文字转换为放大艺术字(使用figlet Mysql显示)
vim /redis_install.sh
#!/bin/sh
# -*- coding: utf-8 -*-
# Author: CIASM
# Date: 2022/04/06
<<!
██████╗ ███████╗██████╗ ██╗███████╗
██╔══██╗██╔════╝██╔══██╗██║██╔════╝
██████╔╝█████╗ ██║ ██║██║███████╗
██╔══██╗██╔══╝ ██║ ██║██║╚════██║
██║ ██║███████╗██████╔╝██║███████║
╚═╝ ╚═╝╚══════╝╚═════╝ ╚═╝╚══════╝
!
source /etc/rc.d/init.d/functions
#Define data path variables
data_downloads=/data/downloads
#Define redis path variables
Redis_URL=http://download.redis.io/releases/
Redis_gz=redis-6.2.9.tar.gz
Redis_FILE_DIR=redis-6.2.9
Redis_PREFIX=/opt/redis
Redis_catalogue=/opt
Redis_new=redis
redis_service=/usr/lib/systemd/system/redis.service
function install_redis (){
if [ ! -d ${Redis_PREFIX} ];then
mkdir -p $data_downloads
yum install -y gcc gcc-c++ cmake net-tools wget
wget -N -P $data_downloads $Redis_URL/$Redis_gz
tar -xf $data_downloads/$Redis_gz -C $Redis_catalogue
if [ $? -eq 0 ];then
mv $Redis_catalogue/$Redis_FILE_DIR $Redis_catalogue/$Redis_new
cd $Redis_catalogue/$Redis_new
make && make install PREFIX=$Redis_PREFIX
ln -s $Redis_catalogue/$Redis_new/bin/* /usr/local/sbin/
redis_config
action "The redis Install Sussess..." /bin/true
else
action "The redis Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[31mThe redis already Install...\033[0m"
fi
}
function redis_config (){
echo "limits config"
cat >>/etc/security/limits.conf<<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
echo "system Maximum number of connections"
echo "fs.file-max=65535" >> /etc/sysctl.conf
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
echo "net.core.somaxconn= 1024" >> /etc/sysctl.conf
echo never > /sys/kernel/mm/transparent_hugepage/enabled
sysctl -p
echo "redis.conf config"
mkdir -p $Redis_PREFIX/conf
mkdir -p $Redis_PREFIX/data
cat >>/opt/redis/conf/redis.conf<<EOF
bind 0.0.0.0
requirepass Report@123
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
loglevel notice
logfile "/var/log/redis.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./opt/redis/data/
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
EOF
echo "redis serves the script"
cat >>$redis_service<<EOF
[Unit]
Description=Redis
After=network.target
[Service]
ExecStart=/opt/redis/bin/redis-server /opt/redis/conf/redis.conf
ExecStop=/opt/redis/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown
Restart=always
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
echo "start redis"
systemctl daemon-reload
systemctl enable --now redis.service
systemctl restart redis.service
echo "firewall redis port"
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload
echo "rm redis"
rm -rf $data_downloads/*
}
function Deployment_completion_notification (){
host_ID=`dmidecode -s system-serial-number | sed -r 's/\s+//g'`
host_IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2}' | awk 'NR==1'`
memory_Size=`dmidecode -t memory | grep Size | grep -v No | awk '{sum+=$2} END {printf "%.0fG\n",sum/1^C4}'`
CPU_Model=`cat /proc/cpuinfo | grep 'model name' | awk '{print $6}' | uniq`
Disk_size=`fdisk -l | grep "sda:" | awk '{print $3$4}'`
redhat_version=`cat /etc/redhat-release | grep "release" | awk '{print $6}'`
redhat_core=`cat /proc/version | grep "version" | awk '{print $3}'`
redis_server=`systemctl status redis.service | grep "Active" | awk '{print $2}'`
redis_version=`/opt/redis/bin/redis-cli -v | grep "redis" | awk '{print $2}'`
redis_port=`netstat -lntp | grep "redis-server" | awk '{print $4}'`
curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXX' \
-H 'Content-Type: application/json' \
-d '
{
"msgtype": "markdown",
"markdown": {
"content": " **system check** <font color=\"info\"> complete </font> \n
> **Host IP Address** \n
[http://'$host_IP'](http://'$host_IP') \n
> **Hardware information** \n
hostSN:<font color=\"info\"> '$host_ID' </font> \n
CPU_Model:<font color=\"info\"> '$CPU_Model' </font> \n
memory_Size:<font color=\"info\"> '$memory_Size' </font> \n
Disk_size:<font color=\"info\"> '$Disk_size' </font> \n
System_version:<font color=\"info\"> '$redhat_version' </font> \n
system_core:<font color=\"info\"> '$redhat_core' </font> \n
> **redis install** \n
redis_version:<font color=\"info\"> '$redis_version' </font> \n
redis_server:<font color=\"info\"> '$redis_server' </font> \n
redis_port:<font color=\"info\"> '$redis_port' </font> \n",
}
}'
}
function main (){
install_redis
Deployment_completion_notification
}
main
执行安装
sh /redis_install.sh
企业微信通知
远程连接redis
- 密码 Report@123
- IP 地址
- 端口 6379