centos6.8 安装redis

本文档详述了在CentOS 6.8上安装Redis 3.2.8的步骤,包括下载源码、编译安装、配置文件修改、创建启动脚本、添加到服务管理、防火墙设置以及验证Redis服务的运行和使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

.在(/usr/local/src)下,

1.下载: # wget  http://download.redis.io/releases/redis-3.2.8.tar.gz

2.解压: tar zxvf redis-3.2.8.tar.gz

3.进入目录: cd redis-3.2.8

4.编译并指定安装目录: make PREFIX=/usr/local/redis-3.2.8 install

5.创建软链接: ln -s /usr/local/redis-3.2.8 /usr/local/redis

6. 配置文件(当前还在redis源码目录[/usr/local/src/redis-3.2.8]内)

# cp redis.conf /etc/redis.conf

7.编辑 # vim /etc/redis.conf

 daemonize no  ==> daemonize yes    (设置redis为后台daemon进程)

8. 创建redis用户

[root@redis-server ~]# useradd -r -s /sbin/nologin -M redis

9. 创建启动脚本/etc/init.d/redis

#!/bin/sh
#
# redis        init file for starting up the redis daemon
#
# chkconfig:  - 20 80
# description: Starts and stops the redis daemon.
 
# Source function library.
#!/bin/sh
#
# redis        init file for starting up the redis daemon
#
# chkconfig:  - 20 80
# description: Starts and stops the redis daemon.
 
# Source function library.
. /etc/rc.d/init.d/functions
 
name="redis-server"
exec="/usr/local/redis/bin/$name"
pidfile="/var/run/redis/redis.pid"
REDIS_CONFIG="/etc/redis.conf"
 
[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis
 
lockfile=/var/lock/subsys/redis
 
start() {
    [ -f $REDIS_CONFIG ] || exit 6
    [ -x $exec ] || exit 5
    echo -n $"Starting $name: "
    daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $name: "
    killproc -p $pidfile $name
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    stop
    start
}
 
reload() {
    false
}
 
rh_status() {
    status -p $pidfile $name
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}"
        exit 2
esac
exit $?


10.修改脚本文件权限

[root@redis-server ~]# chmod 755 /etc/init.d/redis

11. 添加进service服务管理并设置开机启动 

[root@redis-server ~]# chkconfig --add redis
[root@redis-server ~]# chkconfig redis on

12.防火墙设置   # /etc/sysconfig/iptables      设置6390端口

13.防火墙重启  # service iptables restart

14.查看redis进程  有如下表示运行了[root@localhost bin]# ps -ef |grep -i redis
      redis     5392     1  0 20:55 ?        00:00:01 /usr/local/redis/bin/redis-server 127.0.0.1:6379 
       root      5551  2075  0 21:08 pts/0    00:00:00 grep -i redis

15.进入此文件夹 # cd  [root@localhost bin]# ./redis-cli 
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set name aa
OK
127.0.0.1:6379> get name
"aa" /usr/local/redis/bin
[root@localhost bin]# ll
总用量 26348
-rwxr-xr-x 1 root root 5580311 5月  23 20:08 redis-benchmark
-rwxr-xr-x 1 root root   22185 5月  23 20:08 redis-check-aof
-rwxr-xr-x 1 root root 7829978 5月  23 20:08 redis-check-rdb
-rwxr-xr-x 1 root root 5709187 5月  23 20:08 redis-cli
lrwxrwxrwx 1 root root      12 5月  23 20:08 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 7829978 5月  23 20:08 redis-server
[root@localhost bin]# 

16.测试:如下表示可行redis

     [root@localhost bin]# ./redis-cli 
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set name aa
OK
127.0.0.1:6379> get name
"aa"
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> exit



jedis的运用问题

1.导航栏java项目下没显示JRE System Library包==》window->show view->Java->Package Explorer



php扩展redis

1.安装解压编译

# wget https://github.com/phpredis/phpredis/archive/2.2.4.tar.gz
# cd phpredis-2.2.7                      # 进入 phpredis 目录
# /usr/local/php/bin/phpize              # php安装后的路径
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make && make install
	编辑后 在命令行下会显示安装的redis.so的路径,记录或复制下来
	/usr/local/php/lib/php/extensions/no-debug-zts-20090626
2.修改php.ini文件  # find / -name php.ini    --查找自己安装的php.ini安装路径
3.修改php.ini文件 # vim /etc/php.ini  
	 在最后边加上
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20090626"

extension=redis.so
4.重启 # service php-fpm restart
ok后可到phpinfo网页查看 是否有安装了redis扩展
Redis Supportenabled
Redis Version2.2.4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值