centOS redis安装

安装准备:redis2.8.7,redhat

只供参考 

1.解压

?
1
[root@dell1 soft] # tar -xzvf redis-2.8.7.tar.gz


2.进入解压后的目录,直接执行make命令

?
1
2
3
4
[root@dell1 soft] # cd redis-2.8.7 
[root@dell1 redis-2.8.7] # pwd 
/home/soft/redis-2 .8.7 
[root@dell1 redis-2.8.7] # make

 

3.执行make test

执行成功make命令后,会提示执行make test,如果没有安装tcl,则会报错 
报错,提示没有You need 'tclsh8.5' in order to run the Redis test, 
所以接下来应该安装tcl,这个不清楚是什么东西。下载tcl8.6.1 

?
1
2
3
4
5
#cd tcl8.6.1/unix/ 
#./configure 
#make 
#make test 
#make install

这样应该完成安装完tcl了

 

4.回到redis的安装目录重新执行make test

?
1
2
3
4
\o/ All tests passed without errors! 
make  test 执行成功
Cleanup: may take some  time ... OK 
make [1]: Leaving directory ` /home/soft/redis-2 .8.7 /src '

 

5.执行make install

?
1
[root@dell1 redis-2.8.7] # make install

 

6.执行install_server.sh文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@dell1 redis-2.8.7] # cd utils/ 
[root@dell1 utils] # ls 
build-static-symbols.tcl  redis-copy.rb          speed-regression.tcl 
generate- command -help.rb  redis_init_script      whatisdoing.sh 
install_server.sh         redis_init_script.tpl 
mkrelease.sh              redis-sha1.rb 
[root@dell1 utils] # ./install_server.sh
Welcome to the redis service installer 
This script will help you easily  set  up a running redis server
 
Please  select  the redis port  for  this instance: [6379] 
Selecting default: 6379 
Please  select  the redis config  file  name [ /etc/redis/6379 .conf] 
Selected default -  /etc/redis/6379 .conf 
Please  select  the redis log  file  name [ /var/log/redis_6379 .log] 
Selected default -  /var/log/redis_6379 .log 
Please  select  the data directory  for  this instance [ /var/lib/redis/6379
Selected default -  /var/lib/redis/6379 
Please  select  the redis executable path [ /usr/local/bin/redis-server
s #^port [0-9]{4}$#port 6379#;s#^logfile .+$#logfile /var/log/redis_6379.log#;s#^dir .+$#dir /var/lib/redis/6379#;s#^pidfile .+$#pidfile /var/run/redis_6379.pid#;s#^daemonize no$#daemonize yes#; 
Copied  /tmp/6379 .conf =>  /etc/init .d /redis_6379 
Installing service... 
. /install_server .sh: line 178: update-rc.d:  command  not found 
exists, process is already running or crashed 
Installation successful!

执行完成。这里使用了默认配置


7.启动redis服务

?
1
2
3
4
5
[root@dell1 utils] # cd /usr/local/bin 
[root@dell1 bin] # ls 
event_rpcgen.py  memcached-debug  redis-check-aof   redis-cli     tclsh8.6 
memcached        redis-benchmark  redis-check-dump  redis-server 
[root@dell1 bin] # ./redis-server /etc/redis/6379.conf


8.查看服务是否启动

?
1
2
3
[root@dell1 bin] # ps -ef | grep 6379 
root      3206     1  0 13:06 ?        00:00:00  /usr/local/bin/redis-server  *:6379              
root      7996  3294  0 13:45 pts /0     00:00:00  grep  6379

 

9.修改redis启动文件

在init.d下有一个默认文件redis_6379,打开文件,修改后如下

#/bin/sh 
#Configurations injected by install_server below.... 

EXEC=/usr/local/bin/redis-server 

CLIEXEC=/usr/local/bin/redis-cli 

PIDFILE=/var/run/redis_6379.pid 

CONF="/etc/redis/6379.conf" 

REDISPORT="6379"

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 
        ;; 
    stop) 
        if [ ! -f $PIDFILE ] 
        then 
                echo "$PIDFILE does not exist, process is not running" 
        else 
                PID=$(cat $PIDFILE) 
                echo "Stopping ..." 
                $CLIEXEC -p $REDISPORT shutdown 
                while [ -x /proc/${PID} ] 
                do 
                    echo "Waiting for Redis to shutdown ..." 
                    sleep 1 
                done 
                echo "Redis stopped" 
        fi 
        ;; 
    *) 
        echo "Please use start or stop as first argument" 
        ;; 
esac

保存退出

 

10更改redis_6379的名字

?
1
[root@dell1 init.d] # mv redis_6379 redis

 

11.刚才已经启动服务,现在使用service关闭服务,开启服务

?
1
2
3
4
5
[root@dell1 bin] # service redis stop 
Stopping ... 
Redis stopped 
[root@dell1 bin] # service redis start 
Starting Redis server...

3.0 启动:redis-server

12.使用redis-cli登录

?
1
2
3
4
5
6
7
8
9
10
11
[root@dell1 bin] # cd /usr/local/bin 
[root@dell1 bin] # ls 
event_rpcgen.py  memcached-debug  redis-check-aof   redis-cli     tclsh8.6 
memcached        redis-benchmark  redis-check-dump  redis-server 
[root@dell1 bin] # ./redis-cli 
127.0.0.1:6379>  set  key 122 
OK 
127.0.0.1:6379> get key 
"122" 
127.0.0.1:6379> exists key 
(integer) 1


==================

 这里记录一下我安装过程中出现的问题: 

make: Warning: File `Makefile' has modification time 5.4e+06 s in the future

cd src && make all

make[1]: Entering directory `/redis/redis-2.4.7/src'

make[1]: Warning: File `Makefile' has modification time 5.4e+06 s in the future

MAKE hiredis

make[2]: Entering directory `/redis/redis-2.4.7/deps/hiredis'

make[2]: Warning: File `Makefile' has modification time 5.4e+06 s in the future

cc -c -std=c99 -pedantic -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings    -g -ggdb  net.c

make[2]: cc: Command not found

make[2]: *** [net.o] Error 127

make[2]: Leaving directory `/redis/redis-2.4.7/deps/hiredis'

make[1]: *** [dependencies] Error 2

make[1]: Leaving directory `/redis/redis-2.4.7/src'

make: *** [all] Error 2

 

 

第一个问题

make: Warning: File `Makefile' has modification time 5.4e+06 s in the future

系统时间调整错了,调过来就好了

 

第二个问题:

make[2]: Entering directory `/redis/redis-2.4.7/deps/hiredis'

cc -c -std=c99 -pedantic -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings    -g -ggdb  net.c

make[2]: cc: Command not found

没安装gcc

yum install gcc-c++

 

第三个问题:

make的时候显示

make[1]: Entering directory `/redis/redis-2.4.7/src'

which: no tclsh8.5 in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

You need 'tclsh8.5' in order to run the Redis test

没安装tcl

按照官网http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html 上的安装
 

安装完成之后,make成功!

 

安装成功之后会在src文件夹内有redis-server和redis-cli两个命令

建议将其放到bin

sudo cp redis-server /usr/local/bin/

sudo cp redis-cli /usr/local/bin/

 

 

好了,现在redis就安装成功了

 

2 测试redis安装情况 

我只在一台虚拟机上安装了redis,所以这台虚拟机既是服务器,又是客户端

测试:

 

使用secureRt打开一个会话,redis-server,让其作为服务器运行

[19282] 19 Feb 23:52:57 - 1 clients connected (0 slaves), 726248 bytes in use

[19282] 19 Feb 23:53:02 - DB 0: 1 keys (0 volatile) in 4 slots HT.

[19282] 19 Feb 23:53:02 - 1 clients connected (0 slaves), 726248 bytes in use

[19282] 19 Feb 23:53:07 - DB 0: 1 keys (0 volatile) in 4 slots HT.

[19282] 19 Feb 23:53:07 - 1 clients connected (0 slaves), 726248 bytes in use

 

打开另一个会话:

ast login: Tue Feb 19 22:49:49 2013 from 192.168.1.103


 

set keyget key都正确

redis搭建测试通过 


==============

配置防火墙打开对应的端口:

vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT

 重启防火墙

service iptables restart


启动redis-cli
关闭redis-cli -h 127.0.0.1 -p 6379 shutdown

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值