系统AliyunLinux

一、安装Redis(我把redis安装在了/alidata/server/redis下)

 去http://redis.io/download下载redis用FTP工具传到服务器或者按照redis官网写的步骤进行操作
   wget http://download.redis.io/releases/redis-2.8.18.tar.gz//下载
   tar xzf redis-2.8.18.tar.gz//解压
   cd redis-2.8.18
   make//编译

二、 配置Redis 

cp redis.conf /etc/redis.conf#复制一份redis配置文件到etc目录下
   打开redis配置文件vi /etc/redis.conf
   修改
   daemonize yes#是否作为守护进程运行
   dir /var/lib/redis/  缓存存放位置
   useradd redis  #增加redis用户
   mkdir -p /var/lib/redis#创建db文件夹
   chown redis.redis /var/lib/redis #db文件放在这里

三、编辑启动脚本(网上找的)

<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> 

四、加入开机启动项

vi /etc/rc.d/rc.local

增加

/etc/init.d/redis start

五、测试

在你的站点目录下创建一个php文件

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

好了到此为止就配置好了redis,由于本人新手也是在摸索中配置了如有不对的地方欢迎大家指正,不胜感激!

标签:
安装配置阿里云服务器,redis,安装配置

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
千金楼资源网 Copyright www.htabc.com