【Redis】Linux部署单个redis-3.0.6服务,实现开机启动,注册服务

安装

下载,解压,编译:

  1. $ wget http://download.redis.io/releases/redis-3.0.6.tar.gz
  2. $ tar xzf redis-3.0.6.tar.gz
  3. $ cd redis-3.0.6

  4. $ make

cd src

启动
./redis-server & >> log.txt
./redis-server ../redis.conf &


设置开机启动

redis.conf: 注释已删除

daemonize yes
pidfile /var/run/redis.pid
port 6379
tcp-backlog 511
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
databases 5

save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
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-min-size 64mb

aof-load-truncated yes

lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
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
1.Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程daemonizeno
当Redis以守护进程方式运行时,Redis默认会把pid写入/var/run/redis.pid文件
可以通过pidfile指定pidfile/var/run/redis.pid



2·redis启动脚本:

# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database
 
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
 
REDISPORT=6379
EXEC=/home/redis-3.0.6/src/redis-server
REDIS_CLI=/home/redis-3.0.6/src/redis-cli
 
PIDFILE=/var/run/redis.pid
CONF="/home/redis-3.0.6/redis.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
        if [ "$?"="0" ] 
        then
              echo "Redis is running..."
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $REDIS_CLI -p $REDISPORT SHUTDOWN
                while [ -x ${PIDFILE} ]
               do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac
该开机启动脚本文件放入到/etc/init.d/
3·将这个文件设置成可执行文件
chmod 755 redis
chown root:root redis
4·chkconfig redis on
注意: redis脚本中的第一句和第二句注释是必须要加入的,否则在设置开启自动启动时会提示service redis does not support chkconfig的错误信息
5·启动redis服务
service redis start
当然你也可以停止和重启这个服务
#重启redis服务
service redis restart
#关闭redis服务
service redis stop


你可能感兴趣的:(Java后端)