Aliyun server installation configuration redis method and add to boot of recommended

  • 2020-05-27 07:34:02
  • OfStack

System AliyunLinux

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


  Go to the http://redis.io/download download redis with FTP Tools to the server or by redis Official website to write the steps to operate 
   wget http://download.redis.io/releases/redis-2.8.18.tar.gz// download 
   tar xzf redis-2.8.18.tar.gz// Unpack the 
   cd redis-2.8.18
   make// compile 

2. Configuration Redis


cp redis.conf /etc/redis.conf# copy 1 Copy of the redis Configuration file to etc directory 
    Open the redis The configuration file vi /etc/redis.conf
    Modify the 
   daemonize yes# Whether to run as a daemon 
   dir /var/lib/redis/   Cache location 
   useradd redis  # increase redis The user 
   mkdir -p /var/lib/redis# create db folder 
   chown redis.redis /var/lib/redis #db I'll put it here 

3. Edit startup script (found online)


<span style="font-family:Microsoft YaHei;font-size:14px;"># 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</span> 

4. Add startup items


vi /etc/rc.d/rc.local

increase


/etc/init.d/redis start

5. Test

Create an php file in your site directory


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

Good so far configuration good redis, because my novice is also in the groping configuration if there is a wrong place welcome everyone to correct, very grateful!


Related articles: