Install redis for Ubuntu 16.04

Time:2021-7-29

brief introduction

RedisIs an open source(BSDLicense), memory storage data structure server, is a high-performance serverkey-valueDatabase, cache and message queuing agent. It supports strings, hash tables, lists, collections, ordered collections, bitmaps,hyperloglogsAnd other data types. Built in replication, Lua script, LRU retraction, transaction and disk persistence at different levels, andRedis SentinelProvide high availability throughRedis ClusterProvide automatic zoning.

Download and install

wget http://download.redis.io/releases/redis-4.0.1.tar.gz
tar xzf redis-4.0.1.tar.gz
cd redis-4.0.1
make
make isntall

Service management

Start by specifying a profile

sudo redis-server /opt/redis-4.0.1/redis.conf

22090:C 20 Sep 09:52:39.951 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
22090:C 20 Sep 09:52:39.951 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=22090, just started
22090:C 20 Sep 09:52:39.951 # Configuration loaded
If the above information is output, the redis service has been started successfully.

Start the redis server command

redis-server

Close redis service

redis-cli shutdown

Client login and verification

redis-cli

127.0.0.1:6379> set a b
OK
127.0.0.1:6379> get a
“b”
127.0.0.1:6379> exit

Set redis startup

Create redis configuration directory

sudo mkdir /etc/redis

Copy profile

sudo cp /opt/redis-4.0.1/redis.conf /etc/redis/

Modify directory/etc/redis/Belowredis.confFile, add the following

> daemonize no
> logfile ""

Amend to read:

#Turn on background run options
daemonize yes
#Set log file path
logfile “/var/log/redis/redis.log”

#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis

PATH=/usr/local/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/redis/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 exists, 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)  
        
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
PATH=/usr/local/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/redis/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 exists, 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|fore-reload}"
exit 1
esac
stop
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
PATH=/usr/local/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/redis/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 exists, 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|fore-reload}"
exit 1
esac
start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|fore-reload}" exit 1 esac

Question one

insserv: warning: script ‘K01redis’ missing LSB tags and overrides

resolvent
Install a Chinese language, the system will knowzh_CN.UTF-8If you use Perl at this time, you won’t report an error

sudo apt-get install language-pack-zh-hans

Question two

insserv: warning: script ‘redis’ missing LSB tags and overrides

resolvent
Modify directory/etc/init.d/BelowredisFile, in the file header#!/bin/shAdd the following:

### BEGIN INIT INFO
# Provides: OSSEC HIDS
# Required-Start: $network $remote_fs $syslog $time
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OSSEC HIDS
### END INIT INFO

Start service using script

  • Enable redis:service redis start
  • Stop redis:service redis stop
  • Restart redis:service redis restart
  • View service status:service redis status

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]