阿里云服务器安装配置redis的方法并且加入到开机启动(推荐)
程序员文章站
2022-09-02 11:51:26
系统aliyunlinux
一、安装redis(我把redis安装在了/alidata/server/redis下)
去http://redis.io/dow...
系统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,由于本人新手也是在摸索中配置了如有不对的地方欢迎大家指正,不胜感激!