Centos Redis installation + Remote Access + startup, centosredis
1. Install redis
1. Download The redis installation package
Go to the official website http://redis.io, you can also through the wget command
cd /usr/local/soft/wget http://download.redis.io/releases/redis-4.0.6.tar.gz
2. Decompress
tar xzf redis-4.0.6.tar.gz
3. Compile and install
cd redis-4.0.6 make
Ii. Remote Access
1. Copy the redis configuration file to the etc
cp /usr/local/soft/redis-4.0.6/src/redis.conf /etc/
2. modify the configuration file
# Comment out bind 127.0.0.1 so that all ip addresses can access redisprotected-mode yes
3. Disable the Firewall
service iptables statuschkconfig iptables off
4. Shutdown and restart
reboot
Iii. Self-start upon startup
1. Set daemonize to yes in redis. conf to ensure that the daemonize process is enabled.
2. Compile the boot script
vi /etc/init.d/redis
The script is as follows:
chkconfig: 2345 10 90 # description: Start and Stop redis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379 EXEC=/usr/local/soft/redis-4.0.6/src/redis-server
REDIS_CLI=/usr/local/soft/redis-4.0.6/src/redis-cli
PIDFILE=/var/run/redis.pid CONF="/etc/redis.conf" AUTH="1234" 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
sleep 2
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
3. Save and exit VI.
4. Set permissions
chmod 755 redis
5. Start the test
/etc/init.d/redis start
The following message is displayed when the startup is successful:
Starting Redis server...Redis is running...
Test with redis-cli:
[root@rk ~]# /usr/redisbin/redis-cli127.0.0.1:6379> set foo barOK127.0.0.1:6379> get foo"bar"127.0.0.1:6379> exit
6. Set auto-start upon startup
chkconfig redis on
7. Shutdown and restart Test
reboot
Then you can test it with redis-cli.
View comments