【澳门金沙vip】CentOS6.4 安装Redis 教程详解

按照下面步骤依次执行

在VMware的Linux系统上安装Redis

下载、解压、重命名并且编译安装Redis
~ wget
~ tar xzf redis-3.2.9.tar.gz
~ mv redis-3.2.9 redis
~ cd redis
~ make
~ make test
~ make install
配置文件redis.conf
redis解压目录里有一个配置文件redis.conf ,编辑此配置文件,找到 dir ./
这一行[247行]。redis会将内存中的数据写入文件中,而此配置就是指定数据文件保存的路径。
我本机指定的目录:
dir ./
修改为
dir /Users/houxiurong/Software/redis_data/
编辑过后,将配置文件移动到 /usr/local/etc 目录下
~ sudo mv redis.conf /usr/local/etc/
启动Redis
终端输入:
~ /usr/local/bin/redis-server /usr/local/etc/redis.conf
服务启动成功画面:
houxiurong-MacBook-Pro:src houxiurong$ /usr/local/bin/redis-server
/usr/local/etc/redis.conf
6508:M 01 Jul 18:21:33.662 * Increased maximum number of open files to
10032 (it was originally set to 256).
_._
_.-“__ ”-._
_.-“ `. `_. ”-._ Redis 3.2.9 (00000000/0) 64 bit
.-“ .-“`. “`\/ _.,_ ”-._
( ‘ , .-` | `, ) Running in standalone mode
|`-._`-…-` __…-.“-._|’` _.-‘| Port: 6379
| `-._ `._ / _.-‘ | PID: 6508
`-._ `-._ `-./ _.-‘ _.-‘
|`-._`-._ `-.__.-‘ _.-‘_.-‘|
| `-._`-._ _.-‘_.-‘ |
`-._ `-._`-.__.-‘_.-‘ _.-‘
|`-._`-._ `-.__.-‘ _.-‘_.-‘|
| `-._`-._ _.-‘_.-‘ |
`-._ `-._`-.__.-‘_.-‘ _.-‘
`-._ `-.__.-‘ _.-‘
`-._ _.-‘
`-.__.-‘

1.检查依赖,安装依赖

具体过程如下:

6508:M 01 Jul 18:21:33.664 # Server started, Redis version 3.2.9
6508:M 01 Jul 18:21:33.664 * DB loaded from disk: 0.000 seconds
6508:M 01 Jul 18:21:33.664 * The server is now ready to accept
connections on port 6379

[root@ecs-3c46 ~]# whereis gccgcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz[root@ecs-3c46 ~]# whereis tctc: /sbin/tc /usr/lib64/tc /usr/share/tc /usr/share/man/man8/tc.8.gz[root@ecs-3c46 ~]# whereis wgetwget: /usr/bin/wget /usr/share/man/man1/wget.1.gz[root@ecs-3c46 ~]# yum -y install tcl 

下载,解压和编译:

测试连通性
~ cd /usr/local/bin
~ ./redis-cli
127.0.0.1:6379> set me houxiurong
OK
127.0.0.1:6379> get me
“houxiurong”
设置开机自动启动redis server
新建plist文件
~ sudo vi /Library/LaunchDaemons/io.redis.redis-server.plist
文件内容如下
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN”
“;
<plist version=”1.0″>
<dict>
<key>Label</key>
<string>io.redis.redis-server</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/redis-server</string>
<string>/usr/local/etc/redis.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
使用launchctl设置开机自动启动
~ sudo launchctl load
/Library/LaunchDaemons/io.redis.redis-server.plist
使用launchctl启动redis server
~ sudo launchctl start io.redis.redis-server
使用launchctl停止redis server
~ sudo launchctl stop io.redis.redis-server

2.进入/user/local/src/

$ wget
$ tar xzf redis-2.6.14.tar.gz
$ cd redis-2.6.14
$ make

[root@ecs-3c46 ~]# cd /user/local/src/ 

在执行make的时候报错,具体报错信息如下:

3.wget下载redis

zmalloc.o: In function `zmalloc_used_memory’:
/usr/local/redis-2.6.14/src/zmalloc.c:223: undefined reference to
`__sync_add_and_fetch_4′
collect2: ld returned 1 exit status
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/usr/local/redis-2.6.14/src’
make: *** [all] Error 2

[root@ecs-3c46 src]# wget  

网上查了下资料,主要是因为我的linux是32位的,所以会报这个错,解决方案如下:

4.解压

在make操作的时候加一个执行参数:make CFLAGS=”-march=i686″

[root@ecs-3c46 src]tar zxvf redis-3.0.7.tar.gz 

然后就不报错了。

5.将文件转存到/usr/local/redis

附:启动并运行Redis

[root@ecs-3c46 src]mkdir /usr/local/redis[root@ecs-3c46 src]mv redis-3.0.7 /usr/local/redis[root@ecs-3c46 src]ll /usr/local/redis 

编译的可执行文件在src目录中,使用以下命令运行Redis: