从今天开始开辟Redis相关方面的东西
首先是关于Redis的安装
系统为 Redhat 7.4
数据库为 Redis 5.0.8
所有安装包也可使用下面链接下载
链接:https://pan.baidu.com/s/1hoDE8WyVyjkc5uXn4uuqtQ 提取码:jce0
目录名称 | 参数名称 |
---|---|
安装目录 | /usr/local/redis |
数据文件目录 | /home/redis |
日志目录 | /home/redis |
在下载安装前需要对系统参数进行调优
http://www.zhaibibei.cn/redis/config/
当前最新的版本为 6.0.5
这次我们使用5.0.8
http://download.redis.io/releases/redis-5.0.8.tar.gz
root用户
yum -y install gcc
tar zxvf redis-5.0.8.tar.gz -C /usr/local/
cd /usr/local
mv redis-5.0.8/ redis
cd redis/
make
make install
这里我们新建redis用户用于存放redis的相关文件
useradd redis
echo "redis" |passwd redis --stdin
然后配置环境变量
vim /home/redis/.bash_profile
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/redis/src
export PATH
alias start_redis='redis-server /home/redis/redis_6380.conf'
alias stop_redis='redis-cli -p 6380 -a 123456 shutdown'
alias connect_redis='redis-cli -p 6380 -a 123456'
接下来我们创建redis启动的配置文件
redis用户执行,在redis的家目录下建立文件
6380代表端口号以便于识别
vim /home/redis/redis_6380.conf
daemonize yes
bind 172.18.95.84 127.0.0.1
port 6380
tcp-backlog 1024
timeout 300
tcp-keepalive 300
databases 16
requirepass 123456
masterauth 123456
pidfile "/home/redis/redis_6380.pid"
loglevel notice
logfile "/home/redis/redis_6380.log"
dir "/home/redis"
dbfilename "dump.rdb"
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum yes
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
aof-load-truncated yes
no-appendfsync-on-rewrite no
aof-rewrite-incremental-fsync yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 32mb
maxclients 65503
maxmemory 1gb
maxmemory-policy allkeys-lru
# replication
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
repl-backlog-size 32mb
# slow log
slowlog-log-slower-than 10000
slowlog-max-len 1024
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 512mb 512mb 60
client-output-buffer-limit pubsub 64mb 16mb 60
protected-mode yes
# security
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command KEYS ""
上面参数我们需要根据实际情况修改一些参数
接下来我们启动redis
su - redis
redis-server /home/redis/redis_6380.conf
su - redis
redis-cli -p 6380 -a 123456
使用如下命令查询redis相关信息
info
su - redis
redis-cli -p 6380 -a 123456
shutdown
也可以直接运行
redis-cli -p 6380 -a 123456 shutdown
也可直接kill掉进程,但不推荐
最后也可以通过上面设置别名来进行相关的操作