Get the App
SLTechnology News&Howtos  ›  Database  › 

How to install and configure redis on Ali CVM and add it to boot (recommended)

Shulou Source: shulou.com Published: 2022-06-01 04:34:58 09月17日 Update

System AliyunLinux

Install Redis (I installed redis under / alidata/server/redis)

Go to http://redis.io/download to download redis and transfer it to the server with the FTP tool or follow the steps written on the redis official website to operate wget http://download.redis.io/releases/redis-2.8.18.tar.gz// download tar xzf redis-2.8.18.tar.gz// extract cd redis-2.8.18 make// compilation

2. Configure Redis

Cp redis.conf / etc/redis.conf# copy a redis configuration file to the etc directory open the redis configuration file vi / etc/redis.conf modify whether daemonize yes# runs as a daemon dir / var/lib/redis/ cache storage location useradd redis# add redis user mkdir-p / var/lib/redis# create db folder chown redis.redis / var/lib/redis# db file here

Edit the startup script (found on the Internet)

# description: Start and Stop redis PATH=/usr/local/bin:/sbin:/usr/bin:/bin REDISPORT=6379 EXEC=/alidata/server/redis-2.8.18/src/redis-server REDIS_CLI=/alidata/server/redis-2.8.18/src/redis-cli PIDFILE=/var/run/redis.pid CONF= "/ etc/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-a $AUTH 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

4. Add boot entry

Vi / etc/rc.d/rc.local

Increase

/ etc/init.d/redis start

5. Testing

Create a php file in your site directory

$redis = new Redis (); $redis- > connect ('127.0.0.1, 6379); $redis- > set (' test', '11111'); echo $redis- > get (' test')

All right, this is the end of the configuration of the redis, because my novice is also in the groping configuration, if there is something wrong, welcome to correct, grateful!

Tags: Configuration file directory server service no so far location place tool folder novice is in step user site system cache script process Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia vpn MariaDB Xiaomi Shulou Technology