Under Linux build redis

First, download redis

This can go to the official website to download, directly in the Baidu search inside redis

Second, install redis

1, install gcc

yum install gcc-c++

 2, unzip the file and rename redis

[root@localhost local]#tar -zxvf /root/redis-3.2.12.tar.gz -C /usr/local/
[root@localhost local]# cd /usr/local/
[root@localhost local]# mv redis-3.2.12/  mv redis

3, compile redis

[root@localhost local]# cd redis
[root@localhost local]# make
[root@localhost local]# make PREFIX=/usr/local/redis install

4, to test whether or not already installed

[root@localhost redis]# cd /usr/local/redis/bin
[root@localhost bin]# ./redis-server

Display reads as follows:

9190:C 03 Sep 10:19:09.291 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9190:C 03 Sep 10:19:09.292 # Redis version=4.0.1, bits=32, commit=00000000, modified=0, pid=9190, just started
9190:C 03 Sep 10:19:09.292 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
9190:M 03 Sep 10:19:09.295 * Increased maximum number of open files to 10032 (it was originally set to 1024).
9190:M 03 Sep 10:19:09.312 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 4.0.1 (00000000/0) 32 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 9190
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

9190:M 03 Sep 10:19:09.316 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9190:M 03 Sep 10:19:09.316 # Server initialized
9190:M 03 Sep 10:19:09.318 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition.
9190:M 03 Sep 10:19:09.318 * Ready to accept connections

Third, adding the boot

1, adding the boot

[root@localhost local]# cd /usr/local/redis/utils
[root@localhost utils]#  cp redis_init_script /etc/init.d/redis

2, edit the startup file

[root@localhost utils]# vim  /etc/init.d/redis
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server   #指向正确的bin地址
CLIEXEC=/usr/local/redis/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

3, create a profile

[root @ localhost local] # mkdir / etc / Redis 
[root @ localhost local] # cp /usr/local/redis/redis.conf /etc/redis/6379.conf 
[root @ localhost local] # cd / etc / Redis / 
[root @ localhost Redis] # vim 6379.conf 
#bind 127.0.0.1 # this line comments 
protected-mode no # no representation without having to change the password 
daemonize yes # yes change

4, start redis

[root@localhost local]# service redis start
[root@localhost local]# ps -ef|grep redis
root     60252     1  0 15:27 ?        00:00:00 /usr/local/redis/bin/redis-server *:6379
root     61165 48206  0 15:44 pts/0    00:00:00 grep --color=auto redis

 

Guess you like

Origin www.cnblogs.com/zhangqigao/p/12331543.html