本篇文章将给大家介绍在CentOS6.9中源码编译安装redis,开机启动,和源码编译安装php-redis扩展的过程。
1.创建并进入源码保存目录,下载源码包,解压
- mkdir -p /usr/local/src
- cd /usr/local/src
- wget -c http://download.redis.io/releases/redis-4.0.10.tar.gz
- tar -zxvf redis-4.0.10.tar.gz
- cd redis-4.0.10
2.编译,安装
- #安装依赖
- yum -y install gcc gcc-c++
- make MALLOC=libc
- make PREFIX=/usr/local/redis install
3.配置
- #创建配置文件目录
- mkdir -p /usr/local/redis/etc/
- #将源码目录下的redis.conf复制到etc
- cp /usr/local/src/redis-4.0.10/redis.conf /usr/local/redis/etc/
- #修改redis.conf
- vim /usr/local/redis/etc/redis.conf
- daemonize yes #redis以守护进程的方式运行
- #配置环境变量
- vim /etc/profile
- PATH=$PATH:/usr/local/redis/bin
- export PATH
- #立即生效
- source /etc/profile
4.设置开机启动
- #将redis的启动脚本复制一份放到/etc/init.d目录下
- cp /usr/local/src/redis-4.0.10/utils/redis_init_script /etc/init.d/redisd
- #创建/etc/redis目录,复制redis.conf
- mkdir -p /etc/redis
- cp /usr/local/redis/etc/redis.conf /etc/redis/6379.conf
- #进入/etc/init.d
- cd /etc/init.d
- #修改启动脚本
- vim redisd
- #修改服务的位置
- EXEC=/usr/local/redis/bin/redis-server
- #修改命令行工具的位置
- CLIEXEC=/usr/local/redis/bin/redis-cli
- #开机启动
- chkconfig redisd on
5.启动redisd
- [root@jmsite init.d]# service redisd start
- Starting Redis server...
- 118991:C 21 Dec 08:39:46.508 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
- 118991:C 21 Dec 08:39:46.509 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=118991, just started
- 118991:C 21 Dec 08:39:46.509 # Configuration loaded
6.安装php-redis扩展
- #进入源码保存目录,下载,解压
- cd /usr/local/src
- wget -c http://pecl.php.net/get/redis-4.2.0.tgz
- tar -zxvf redis-4.2.0.tgz
- cd redis-4.2.0
- #生成configure文件
- /usr/local/php72/bin/phpize #这是我的phpize的位置
- #配置,编译,安装
- ./configure --with-php-config=/usr/local/php72/bin/php-config
- make -j4
- make install
- #将redis扩展加入php.ini
- echo "extension=redis.so" >> /usr/local/php72/etc/php.ini
- #重启php,查看phpinfo();
新闻热点
疑难解答