Redis下载

wget

Redis安装

进入下载目录解压会生成一个redis-5.0.5的目录

tar

安装GCC依赖(如果有GCC可以跳过)

yum install

编译&安装

cd

编译安装

make
make install

运行Redis,可在任意目录下运行,因为redis-server命令在/usr/local/bin目录里面,而该目录又配置在PATH中,所以你可以像执行ls、mkdir等命令的方式去执行redis-cli或者redis-server等命令。

redis-server
redis-cli

Redis配置

复制文件到配置文件目录

cp

设置redis配置文件

vim /etc/redis/redis.conf

内容如下

bind 0.0.0.0 ::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
loglevel notice
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
requirepass 123456
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
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
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

加载配置文件并启动服务端

redis-server redis.conf

启动1客户端

redis-cli

将Redis添加到Systemctl

vi

加入如下代码

[Unit]
Description=redis
After=network.target

[Service]
#Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/TRS/APP/redis/src/redis-server /TRS/APP/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重新加载systemctl

systemctl daemon-reload
systemctl reload redis.service
$ systemctl enable

开启防火墙3306

firewall-cmd --permanent --add-port=6379/tcp
firewall-cmd --reload