redis installation and configuration
Information:
Link: https://pan.baidu.com/s/1TNKs_xcMuL5VHPln8oiorg
Extraction code: rjqv
1. Installation
-
Download the installation package
The installation package provided by the pre-class materials, or: download from the official website It is
recommended to upload it to our home: /usr/local/leyou -
Unzip
tar -xvf redis-4.0.9.tar.gz
- Compile and install
mv redis-4.0.9 redis
cd redis
make && make install
2. Configuration
Modify the redis.conf file in the installation directory
vim redis.conf
Modify the following configuration:
#bind 127.0.0.1 # 将这行代码注释,监听所有的ip地址,外网可以访问
protected-mode no # 把yes改成no,允许外网访问
daemonize yes # 把no改成yes,后台运行
3. Start or stop
Redis provides server-side commands and client-side commands:
- The redis-server server command can contain the following parameters:
start start
stop stop - redis-cli client console, including parameters:
-h xxx specifies the server address, the default value is 127.0.0.1
-p xxx specifies the server port, the default value is 6379
4. Set boot up
- Enter the command to create a new file
vim /etc/init.d/redis
Enter the following:
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/usr/local/leyou/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 does not exist, 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|force-reload}" >&2
exit 1
esac
Then save and exit
Note: The following information needs to be adjusted according to the installation directory:
EXEC=/usr/local/bin/redis-server # The address to execute the script
REDIS_CLI=/usr/local/bin/redis-cli # The address where the client executes the script
PIDFILE=/var/run/redis.pid # Process id file address
CONF="/usr/local/src/redis-3.0.2/redis.conf" #Configuration file address
2) Set permissions
chmod 755 /etc/init.d/redis
3) Start the test
/etc/init.d/redis start
A successful startup will prompt the following information:
Starting Redis server...
Redis is running...
4) Set up auto-start after power-on
chkconfig --add /etc/init.d/redis
chkconfig redis on