系統(tǒng)AliyunLinux
一、安裝Redis(我把redis安裝在了/alidata/server/redis下)
去http://redis.io/download下載redis用FTP工具傳到服務(wù)器或者按照redis官網(wǎng)寫的步驟進(jìn)行操作
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#復(fù)制一份redis配置文件到etc目錄下
打開redis配置文件vi /etc/redis.conf
修改
daemonize yes#是否作為守護(hù)進(jìn)程運(yùn)行
dir /var/lib/redis/ 緩存存放位置
useradd redis #增加redis用戶
mkdir -p /var/lib/redis#創(chuàng)建db文件夾
chown redis.redis /var/lib/redis #db文件放在這里
三、編輯啟動(dòng)腳本(網(wǎng)上找的)
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>
四、加入開機(jī)啟動(dòng)項(xiàng)
增加
五、測(cè)試
在你的站點(diǎn)目錄下創(chuàng)建一個(gè)php文件
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('test', '11111');
echo $redis->get('test');
好了到此為止就配置好了redis,由于本人新手也是在摸索中配置了如有不對(duì)的地方歡迎大家指正,不勝感激!
您可能感興趣的文章:- 詳解阿里云Linux啟動(dòng)tomcat并能外網(wǎng)訪問
- 阿里云Centos7下安裝Redis及tomcat設(shè)置自啟動(dòng)的方法