码迷,mamicode.com
首页 > 系统相关 > 详细

Linux下Redis的安装配置

时间:2017-09-13 10:48:07      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:开机自启   path   移动   etc   sage   local   pidfile   stop   编译   

 

环境: centos7  PHP7

 

1.切到准备安装的目录

cd /usr/local

 

2.下载Redis

wget http://download.redis.io/redis-stable.tar.gz

 

3.解压

tar -zxf redis-stable.tar.gz

 

4.编译

make

 

5. 第5行 after 1000 改为 after 10000

vi tests/integration/replication-psync.tcl

 

6.进入src目录

cd src

 

7.编译检查

make test

 

8.安装

make install    

 

9.切到外层将目录改名

cd /usr/local

mv redis-stable redis

 

10.修改配置

vi redis/redis.conf

 

搜索daemonize 改为  daemonize yes

 

搜索pidfile 改为 pidfile /usr/local/redis/redis.pid

 

搜索logfile 改为 logfile /usr/local/redis/redis.log

 

搜索save 60 10000  改为 save 60 1000

 

搜索#maxmemory <bytes>  改为 maxmemory 256M

 

 

11.启动Redis

/usr/local/redis/src/redis-server

技术分享

 

 

12.开机启动

vi /etc/init.d/redis

输入以下内容  路径换成实际路径:

#!/bin/bash
# chkconfig: 2345 10 90
# description: Start and Stop redis

PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis/src/redis-server
REDIS_CLI=/usr/local/redis/src/redis-cli

PIDFILE=/usr/local/redis/redis.pid
CONF="/usr/local/redis/redis.conf"
AUTH="1234"

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

 

保存退出:wq

 

13.开启服务

/etc/init.d/redis start

如果看到以下信息则成功
Starting Redis server...
Redis is running...

 

14.启动客户端:

/usr/local/redis/src/redis-cli 

用一下set get

技术分享

存储数据正常  

 

15.设置开机自启

chkconfig redis on

 

 

安装Redis扩展

 

16.下载地址:

https://github.com/phpredis/phpredis/archive/php7.zip

用ftp传到Linux
注意 请根据自己的PHP实际版本去网上找合适的扩展

 

17.移动到准备安装的目录

mv phpredis-php7.zip /usr/local/phpredis-php7.zip

 

18.解压

unzip phpredis-php7.zip

 

19.进入目录中

cd phpredis-php7

 

20.执行PHP安装目录下的phpize

/usr/local/php7/bin/phpize

 

21.报错信息:

Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

解决办法:

yum install m4
yum install autoconf

再次执行phpize:

/usr/local/php7/bin/phpize

 

22.搜索php-config路径

find /usr/local/php7/ -name php-config
得到/usr/local/php7/bin/php-config

 

23.配置

./configure --with-php-config=/usr/local/php7/bin/php-config

 

24.编译

make

 

25.安装

make install

出现如下结果:

技术分享

 

26.编辑php.ini

vi /usr/local/php7/etc/php.ini

在一排extension的地方加入:
extension=redis.so

 

27.重启Apache

systemctl restart httpd

 

28.新建PHP文件运行phpinfo()

搜索有无Redis扩展

 

29.运行以下代码 如果存取正常 则安装成功

$redis = new Redis();
$redis->connect(‘127.0.0.1‘, 6379);
$redis->set("name", "hello world");
echo $redis->get("name");

 

 

感谢阅读

 

Linux下Redis的安装配置

标签:开机自启   path   移动   etc   sage   local   pidfile   stop   编译   

原文地址:http://www.cnblogs.com/fengyumeng/p/7513699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!