Download it on the official website Redis -3.2.0.tar.gz, put redis-3.2.0.tar.gz in the / opt directory
Unzip redis-3.2.0.tar.gz
xiaoyao@xiaoyao-virtual-machine:/opt$ sudo tar -zxvf redis-3.2.0.tar.gz
Compile redis
xiaoyao@xiaoyao-virtual-machine:/opt$ cd redis-3.2.0/ xiaoyao@xiaoyao-virtual-machine:/opt/redis-3.2.0$ sudo make
install
xiaoyao@xiaoyao-virtual-machine:/opt/redis-3.2.0$ sudo make install
Test whether the installation passes
xiaoyao@xiaoyao-virtual-machine:/opt/redis-3.2.0$ sudo make test See the following words: \ o/ All tests passed without errors
If you need TCL 8.5 or new in order to run the redis test error occurs
Solution
xiaoyao@xiaoyao-virtual-machine:/opt/redis-3.2.0$ sudo apt-get install tcl8.5
Modify the configuration file so that other machines can connect to the redis service
xiaoyao@xiaoyao-virtual-machine:/opt/redis-3.2.0$ sudo vim /opt/redis-3.2.0/redis.conf
Change bind 127.0.0.1 to bind 0.0.0.0
Copy the redis.conf file to the / etc/redis directory
xiaoyao@xiaoyao-virtual-machine:/opt/redis-3.2.0$ sudo mkdir /etc/redis xiaoyao@xiaoyao-virtual-machine:/opt/redis-3.2.0$ sudo cp redis.conf /etc/redis/redis.conf
Start redis service
xiaoyao@xiaoyao-virtual-machine:/opt/redis-3.2.0$ /usr/local/bin/redis-server /etc/redis/redis.conf
Enter the redis client and test redis
xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ ./redis-cli 127.0.0.1:6379> ping PONG
There is no problem to connect to redis through redisclient software.
Set power on self start
-
Modify redis.conf
#Turn on background run options daemonize yes #Set log file path logfile "/var/log/redis.log"
-
Script writing
xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ sudo touch /etc/init.d/redis xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ sudo vim /etc/init.d/redis
Here's the script
#!/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
-
Add execution permission for script
xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ sudo chmod +x /etc/init.d/redis
-
Set automatic startup
xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ sudo update-rc.d redis defaults
-
Start service with script
open redis xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ service redis start //Stop redis xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ service redis stop //Restart redis xiaoyao@xiaoyao-virtual-machine:/usr/local/bin$ service redis restart
- Shut down and restart the machine
It is found that the redis service is also started