设为首页 收藏本站
查看: 761|回复: 0

[经验分享] Redis install and config

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-1-26 08:42:16 | 显示全部楼层 |阅读模式
  本文参照官方文档。最初安装redis时,编译后只能在当前目录使用,并且 init 脚本也是参照网络而写。最近在官方看了部分文档,对其编译与使用过程有了进一步了解,遂整理此文,以备查阅。

准备和说明:
    系统:centos6.5
    软件源码目录:/usr/local/src
    软件安装目录:/usr/local/bin
    软件官网:redis.io
    软件下载地址及版本(截至本文发布最新稳定版):http://download.redis.io/releases/redis-3.0.6.tar.gz


软件安装:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$wget -c  -P /usr/local/src
$cd /usr/local/src
$tar zxvf redis-3.0.6.tar.gz
$cd /usr/local/src/redis-3.0.6
#查看REDME得知
#编译安装到当前路径src目录
$sudo make                           

#编译redis并安装到目录/usr/local/bin
#此文采用此种方式
$sudo make install                    

#编译redis并安装到自定义目录/usr/local/redis
$sudo make prefix=/usr/local/redis




经过上面的编译,生成以下二进制文件
  • redis-server is the Redis Server itself.
  • redis-sentinel is the Redis Sentinel executable (monitoring and failover).
  • redis-cli is the command line interface utility to talk with Redis.
  • redis-benchmark is used to check Redis performances.
  • redis-check-aof and redis-check-dump are useful in the rare event of corrupted data files.


完善安装:
在完成以上编译,就已完成redis软件安装,可使用 ./redis-server 运行 redis 服务。但在生产环境这并不可取,所以需要后续工作进行完善。

如只使用 make 编译,请将 server 和 cli 拷贝到 /usr/local/bin 下:
1
2
$sudo cp src/redis-server /usr/local/bin
$sudo cp src/redis-cli /usr/local/bin




创建配置文件和数据存储目录:

1
2
$sudo mkdir /etc/redis
$sudo mkdir /var/redis




复制 init 脚本到 /etc/init.d 并使用 redis 加实例端口命名

1
$sudo utils/redis_init_script /etc/init.d/redis_6379




编辑 init 脚本,修改确认 REDISPORT 端口和 PIDFILE 、CONF 文件路径及名称,增加 chkconfig 级别
1
$sudo vim /etc/init.d/redis_6379




/etc/init.d/redis_6379

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
#
# redis        init file for starting up the redis daemon
#
# chkconfig:   - 20 80
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
# Source function library.
. /etc/rc.d/init.d/functions

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac





复制配置模板到 /etc/redis 目录,并以运行实例端口命名
1
$sudo cp redis.conf /etc/redis/6379.conf



创建运行实例工作目录
1
$sudo mkdir /var/redis/6379





编辑配置文件,确保以下更改
  • Set daemonize to yes (by default it is set to no).
  • Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).
  • Change the port accordingly. In our example it is not needed as the default port is already 6379.
  • Set your preferred loglevel.
  • Set the logfile to /var/log/redis_6379.log
  • Set the dir to /var/redis/6379 (very important step!)


redis.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
daemonize yes
pidfile /var/run/redis_6379.pid
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile "/var/log/redis_6379.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/redis/6379
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
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-entries 512
list-max-ziplist-value 64
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 加入系统服务,并设置默认运行级别
1
2
chkconfig --add redis_6379
chkconfig --level 2345 redis_6379 on



启动 redis 服务
1
$sudo service redis_6379 start




至此完成安装及配置,可使用 redis-cli 链接 redis 服务测试

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-169563-1-1.html 上篇帖子: Redis安装教程 下篇帖子: Redis install and config
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表