How to install Redis on Linux env

1. Download Redis

http://download.redis.io/releases/redis-4.0.10.tar.gz

2. Unzip package 

(e.g. /home/redis) 

tar xzvf redis-4.0.10.tar.gz

3. Make file

cd redis-4.0.10
make
cd src
make all
make install

4. Deploy Redis

mkdir -p/usr/local/redis/bin
mkdir -p/usr/local/redis/ect
mv /home/redis-4.0.10/redis.conf /usr/local/redis/etc
cd /home/redis-4.0.10/src
mv mkreleasdhdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server /usr/local/redis/bin

Right now, you should be able to execute ./redis-server under the path "/usr/local/redis/bin"

5. Config Redis

5.1 Background running

cd /usr/local/redis/etc/
Vi redis.conf

Set set "daemonize" to yes.

You can run redis in background via command "redis-server /usr/local/redis/etc/redis.conf"; and you may connect to redis with cli tool by invoke "redis-cli" command.

5.2 Register Service

vim /etc/init.d/redis

Copy following script into file

#!/bin/sh
#
# redis        Startup script for Redis Server
#
# chkconfig: - 80 12
# description: Redis is an open source, advanced key-value store.
#
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/redis/bin"
CONFIG="/usr/local/redis/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
        if [ -e $PIDFILE ];then
             echo "$desc already running...."
             exit 1
        fi
        echo -n $"Starting $desc: "
        daemon $BIN/$prog $CONFIG
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}
stop() {
        echo -n $"Stop $desc: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
        return $RETVAL
}
restart() {
        stop
        start
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
        RETVAL=$?
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac
exit $RETVAL
chmod +x /etc/init.d/redis
chkconfig --add redis

Now, you should be able to start/stop redis by the commands:

service redis start
service redis stop

5.3 Config PATH env

#vi /etc/profile
export PATH="$PATH:/usr/local/redis/bin"
#. /etc/profile

5.4 Config kernel parameter

#vim /etc/sysctl.conf
vm.overcommit_memory = 1 
#sysctl -p 

This configuration is for making sure cache data could be persisted to local disk before redis shutdown.

 

Copy from:

https://www.cnblogs.com/wangchunniu1314/p/6339416.html 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值