$ wget http://download.redis.io/releases/redis-3.2.5.tar.gz $ tar xzf redis-3.2.5.tar.gz $ cd redis-3.2.5 $ make
执行第一行命令就出错了
-bash: wget: 未找到命令
原因是CentOS最小化安装没有装wget,使用下面命令安装即可:
yum -y install wget
然后往下执行,在make的时候又报错了:
cd src && make all make[1]: 进入目录“/usr/soft/redis-3.2.5/src” CC adlist.o /bin/sh: cc: 未找到命令 make[1]: *** [adlist.o] 错误 127 make[1]: 离开目录“/usr/soft/redis-3.2.5/src” make: *** [all] 错误 2
原因是虚拟机系统中缺少gcc,安装一下gcc:
yum -y install gcc automake autoconf libtool make
重新make redis ,发现又报错了:
cd src && make all make[1]: 进入目录“/usr/soft/redis-3.2.5/src” CC adlist.o In file included from adlist.c:34:0: zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录 #include <jemalloc/jemalloc.h> ^ 编译中断。 make[1]: *** [adlist.o] 错误 1 make[1]: 离开目录“/usr/soft/redis-3.2.5/src” make: *** [all] 错误 2
解决方法:
make MALLOC=libc
这样就顺利安装了,接下来运行:
src/redis-server
设置防火墙(没开启防火墙的可以跳过):
firewall-cmd --zone=public --add-port=6379/tcp --permanent firewall-cmd --reload
接下来就可以测试了,结果在windows中测试的时候发现连接不上,原来是redis默认绑定监听:
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # JUST COMMENT THE FOLLOWING LINE. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bind 127.0.0.1
注释掉,还有这里:
# By default protected mode is enabled. You should disable it only if # you are sure you want clients from other hosts to connect to Redis # even if no authentication is configured, nor a specific set of interfaces # are explicitly listed using the "bind" directive. protected-mode yes
把yes改成no,再次运行
src/redis-server
从Windows测试,测试代码如下:
string redisIP = ConfigurationManager.AppSettings["redisIP"]; try { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(redisIP); IDatabase db = redis.GetDatabase(); string value = "abcdefg"; db.StringSet("mykey", value); string value1 = db.StringGet("mykey"); Console.WriteLine(value1); } catch (Exception ex) { Console.WriteLine(ex.Message); }
这里用的是StackExchange.Redis,用包管理器就可以安装:
Install-Package StackExchange.Redis
运行程序,发现还是连接不上,什么问题呢?再仔细看下redis的提示:
2599:C 11 Nov 01:34:54.682 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
也就是说我们上面修改的配置redis没有使用,接下来改下命令
src/redis-server redis.conf
这样就可以使用我们自己的配置了,再次连接,OK了。