天天看點

一鍵安裝redis6.0(Rocky Linux 9/CentOS Stream 9)(shell)

作者:街頭角落裡
一鍵安裝redis6.0(Rocky Linux 9/CentOS Stream 9)(shell)
一鍵安裝redis6.0(Rocky Linux 9/CentOS Stream 9)(shell)

推薦

Zabbix拓撲圖繪制,快速定位故障主機位置

CentOS 7.9伺服器,一分鐘部署完mysql8.0

mysql自動備份,并zabbix檢測備份檔案是否正常,備份檔案大小

mongodb自動備份,并zabbix檢測備份檔案是否正常,備份檔案大小

windows 添加zabbix_agent監控,開機自動修改主機名

centos7部署zabbix-agent,開機自動修改主機名和系統主機名

一/編寫腳本

程式包:http://download.redis.io/releases/redis-6.0.5.tar.gz

#cat redis_6_0_5_install.sh
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename:    安裝redis
# Revision:    1.2.3
# Author 		
# Description: 解壓安裝
# Notes:       Rocky Linux 9/CentOS Stream 9
# --------------------------------------------------------------------------------

redis_6_0_5_install(){
dnf -y install vim net-tools lrzsz  wget telnet lsof  gcc-c++  gcc
local sredis=`ps -ef |grep redis |wc -l`
if [ $sredis -ge 2 ];then
	echo "redis在運作中,請檢查一下"
else
	tar -xf redis-6.0.5.tar.gz -C  /data/
	mv /data/redis-6.0.5 /data/redis
	cd /data/redis
	make PREFIX=/data/redis install
	mkdir -p /data/redis/log
	mv /data/redis/redis.conf  /data/redis/redis.conf_bak
	
	cat > /data/redis/redis.conf  <<EOF
#bind 127.0.0.1
protected-mode no
port 6379
tcp-backlog 511
timeout 600
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel verbose
logfile "/data/redis/log/redis.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /data/redis/

replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100

slave-serve-stale-data yes
slave-read-only yes
slave-priority 100

maxclients 2000
maxmemory 2048M

acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del 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
jemalloc-bg-thread yes

EOF

    cd /etc/systemd/system
	cat > /etc/systemd/system/redis.service << EOF
[Unit]
Description=redis
After=network.target

[Service]
User=root
Group=root
ExecStart=/data/redis/bin/redis-server /data/redis/redis.conf
ExecStop=/data/redis/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

EOF

	#設定開機啟動
    sudo systemctl daemon-reload  &&  sudo systemctl enable redis.service && sudo systemctl restart redis.service
    #判斷啟動情況
	aredis=`ps -ef |grep redis |wc -l`
		if [ $aredis -ge 2 ];then
			redis_po=`ps -ef |grep redis |awk -F ':' '{print $5}'`
			echo "結果為$redis_po端口  就ok了;"
			local_service=`systemctl list-dependencies multi-user.target | grep rc-local`
				if [ -z "$local_service" ];then
					echo "安裝redis已經安裝了,設定了開機自啟"
					echo -e "\n"
				else
					echo "安裝redis已經安裝了,但未設定開機自啟"
				fi
		else
			echo "安裝redis失敗"
		fi
fi
}

redis_6_0_5_install           

二/安裝完成

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory '/data/redis/src'
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /etc/systemd/system/redis.service.
結果為6379端口  就ok了;
安裝redis已經安裝了,設定了開機自啟           

三/檢視

[root@R9-10-1-1-13 install]# netstat -tlunp |grep redis
tcp        0      0 0.0.0.0:53379           0.0.0.0:*               LISTEN      17548/redis-server  
tcp6       0      0 :::53379                :::*                    LISTEN      17548/redis-server