为方便以后使用,记录一些redis安装
一、安装gcc
yum -y install gcc
二、解压并进入redis源码包
tar -xf redis-5.0.9.tar.gz
cd redis-5.0.9/
三、编译安装
make
cd src
make install
四、移动启动文件到指定的文件方便管理,本次为/data/redis
mkdir /data/redis/bin
mkdir /data/redis/etc
cd redis-5.0.9/
cp redis.conf /data/redis/etc/
cd src/
cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server /data/redis/bin/
五、修改/data/redis/etc/redis.conf文件
本次我修修改密码和dir文件路径、监听地址、以及端口,配置文件如下:
bind 0.0.0.0 监听地址
protected-mode yes
port 6389 #端口
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes #后台运行
supervised no
pidfile /var/run/redis_6389.pid
loglevel notice
logfile ""
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
dir /data/redis #修改redis工作目录,dump.rdb保存在该目录
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
requirepass pass_pass@123 #密码
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
#按需求开启
#输⼊的参数中⾄少要有⼀个 K 或者 E,否则的话,不管其余的参数是什么,都不会有任何通知被#分发。
#如:notify-keyspace-events "Ex"表⽰对过期事件进⾏通知发送;notify-keyspace-events "kx"
#表⽰想监控某个 key 的失效事件。
#将参数设为字符串 AKE 表⽰发送所有类型的通知。
notify-keyspace-events "AKE"
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
六、指定配置文件启动redis
cd /data/redis
./bin/redis-server ./etc/redis.conf
七、验证
ss -nltup | grep redis
redis-cli -p 6389 -a 'pass_pass@123'
127.0.0.1:6389> set a test2
OK
127.0.0.1:6389> get a
"test2"
八、设置开机自启
vim /etc/rc.d/rc.local
/lyzh/redis_install_dir/bin/redis-server /lyzh/redis_install_dir/etc/redis.conf