本文主要是介绍系统服务-redis,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
安装依赖
yum -y install tcl gcc
wget http://download.redis.io/releases/redis-5.0.2.tar.gz
tar zxvf redis-5.0.2.tar.gz
cd redis-5.0.2
make PREFIX=/usr/local/redis MALLOC=libc install
mkdir /usr/local/redis/{etc,data,log}
#cp redis.conf /usr/local/redis/etc/redis.conf
#sed -i 's/daemonize no/daemonize yes/' /usr/local/redis/etc/redis.conf
- /usr/local/redis/bin目录下几个文件
- redis-benchmark:性能测试工具
- redis-check-aof:检查aof日志的工具
- redis-check-rdb:检查rdb日志的攻击
- redis-cli:客户端工具
- redis-server:服务端工具
环境变量
echo -e '
#Setting Redis
export REDIS_HOME="/usr/local/redis/bin"
export PATH=$REDIS_HOME:$PATH' >> /etc/profile
source /etc/profile
配置文件
echo -e 'daemonize yes
pidfile /usr/local/redis/log/redis.pid
logfile /usr/local/redis/log/redis.log
port 6379
maxmemory 128mb
dir /usr/local/redis/data
requirepass 123456
databases 16
appendonly yes
rdbcompression yes
dbfilename dump.rdb
save 900 1
save 300 10
save 60 10000' >> /usr/local/redis/etc/redis.conf
- appendonly:启动持久化
- rdbcompression:持久化使用压缩
- 同步策略
- save 900 1:900秒内有1次操作,同步到本地
- save 300 10:300秒内有10次操作,同步到本地
- save 60 10000:60秒内有10000次操作,同步到本地
systemd服务
echo -e '[Unit]
Description=Redis Service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target'>>/usr/lib/systemd/system/redis.service
systemctl daemon-reload
systemctl enable redis
systemctl start redis
连接测试
redis-cli -p 6379 -h 192.168.0.199 -a 123456
# 或者
[oot@harbor redis]# redis-cli -p 6379 -h 192.168.0.199
192.168.0.199:6370> auth 123456
OK
这篇关于系统服务-redis的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!