下载安装包:
######################## 将redis-stable.tar.gz下载到本地/app/目录下[root@iZ23zw1ss97Z app]# wget -P /app/ http://download.redis.io/releases/redis-stable.tar.gz
安装步骤以及验证:
[root@iZ23zw1ss97Z ~]# cd /app/[root@iZ23zw1ss97Z app]# lltotal 171672-rw-r--r-- 1 root root 1120445 Nov 9 20:04 redis-stable.tar.gz######################## 解压安装包[root@iZ23zw1ss97Z app]# tar -xvzf redis-stable.tar.gz...[root@iZ23zw1ss97Z app]# lltotal 171676drwxrwxr-x 6 root root 4096 Apr 22 2014 redis-stable-rw-r--r-- 1 root root 1120445 Nov 9 20:04 redis-stable.tar.gz######################## 进入解压后的目录[root@iZ23zw1ss97Z app]# cd redis-stable######################## 编译[root@iZ23zw1ss97Z redis-stable]# makecd src && make allmake[1]: Entering directory `/app/redis-stable/src'rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-dump redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html(cd ../deps && make distclean)....#省略Hint: To run 'make test' is a good idea ;)make[1]: Leaving directory `/app/redis-stable/src'[root@iZ23zw1ss97Z redis-stable]# cd src/[root@iZ23zw1ss97Z src]# lsadlist.c asciilogo.h debug.o lzf_c.o networking.o rdb.o redis.h sds.h syncio.c util.oadlist.h bio.c dict.c lzf_d.c notify.c redisassert.h redis.o sds.o syncio.o valgrind.supadlist.o bio.h dict.h lzf_d.o notify.o redis-benchmark redis-sentinel sentinel.c testhelp.h version.hae.c bio.o dict.o lzf.h object.c redis-benchmark.c redis-server sentinel.o t_hash.c ziplist.cae_epoll.c bitops.c endianconv.c lzfP.h object.o redis-benchmark.o release.c setproctitle.c t_hash.o ziplist.hae_evport.c bitops.o endianconv.h Makefile pqsort.c redis.c release.h setproctitle.o t_list.c ziplist.oae.h config.c endianconv.o Makefile.dep pqsort.h redis-check-aof release.o sha1.c t_list.o zipmap.cae_kqueue.c config.h fmacros.h memtest.c pqsort.o redis-check-aof.c replication.c sha1.h t_set.c zipmap.hae.o config.o help.h memtest.o pubsub.c redis-check-aof.o replication.o sha1.o t_set.o zipmap.oae_select.c crc64.c hyperloglog.c migrate.c pubsub.o redis-check-dump rio.c slowlog.c t_string.c zmalloc.canet.c crc64.h hyperloglog.o migrate.o rand.c redis-check-dump.c rio.h slowlog.h t_string.o zmalloc.hanet.h crc64.o intset.c mkreleasehdr.sh rand.h redis-check-dump.o rio.o slowlog.o t_zset.c zmalloc.oanet.o db.c intset.h multi.c rand.o redis-cli scripting.c solarisfixes.h t_zset.oaof.c db.o intset.o multi.o rdb.c redis-cli.c scripting.o sort.c util.caof.o debug.c lzf_c.c networking.c rdb.h redis-cli.o sds.c sort.o util.h######################## 将redis-server、redis-cli复制一份到/usr/local/bin/下[root@iZ23zw1ss97Z src]# cp redis-server /usr/local/bin/[root@iZ23zw1ss97Z src]# cp redis-cli /usr/local/bin/######################## 修改/app/redis-stable/redis.conf配置,以后台方式启动redis服务[root@iZ23zw1ss97Z src]# cd ../[root@iZ23zw1ss97Z redis-stable]# lltotal 120-rw-rw-r-- 1 root root 17612 Apr 22 2014 00-RELEASENOTES-rw-rw-r-- 1 root root 52 Apr 22 2014 BUGS-rw-rw-r-- 1 root root 1439 Apr 22 2014 CONTRIBUTING-rw-rw-r-- 1 root root 1487 Apr 22 2014 COPYINGdrwxrwxr-x 6 root root 4096 Nov 9 20:12 deps-rw-rw-r-- 1 root root 11 Apr 22 2014 INSTALL-rw-rw-r-- 1 root root 151 Apr 22 2014 Makefile-rw-rw-r-- 1 root root 4223 Apr 22 2014 MANIFESTO-rw-rw-r-- 1 root root 4404 Apr 22 2014 README-rw-rw-r-- 1 root root 31205 Apr 22 2014 redis.conf-rwxrwxr-x 1 root root 271 Apr 22 2014 runtest-rwxrwxr-x 1 root root 277 Apr 22 2014 runtest-sentinel-rw-rw-r-- 1 root root 5660 Apr 22 2014 sentinel.confdrwxrwxr-x 2 root root 4096 Nov 9 20:20 srcdrwxrwxr-x 10 root root 4096 Apr 22 2014 testsdrwxrwxr-x 3 root root 4096 Apr 22 2014 utils[root@iZ23zw1ss97Z redis-stable]# vi redis.conf# Redis configuration file example# Note on units: when memory size is needed, it is possible to specify# it in the usual form of 1k 5GB 4M and so forth:## 1k => 1000 bytes# 1kb => 1024 bytes# 1m => 1000000 bytes# 1mb => 1024*1024 bytes# 1g => 1000000000 bytes# 1gb => 1024*1024*1024 bytes## units are case insensitive so 1GB 1Gb 1gB are all the same.################################## INCLUDES #################################### Include one or more other config files here. This is useful if you# have a standard template that goes to all Redis server but also need# to customize a few per-server settings. Include files can include# other files, so use this wisely.## Notice option "include" won't be rewritten by command "CONFIG REWRITE"# from admin or Redis Sentinel. Since Redis always uses the last processed# line as value of a configuration directive, you'd better put includes# at the beginning of this file to avoid overwriting config change at runtime.## If instead you are interested in using includes to override configuration######################## 修改redis.conf中daemonize参数为yes######################## /daemonize 表示向下搜索内容,将no改为yes后,保存退出/daemonize[root@iZ23zw1ss97Z redis-stable]# [root@iZ23zw1ss97Z redis-stable]# cd src####启动redis服务[root@iZ23zw1ss97Z src]# ./redis-server ../redis.conf######################## 检查进程中是否已有redis服务[root@iZ23zw1ss97Z src]# ps -ef|grep -v grep |grep redisroot 5715 1 0 20:33 ? 00:00:00 ./redis-server *:6379[root@iZ23zw1ss97Z src]# ######################## 测试redis服务能否ping通,能否set和get[root@iZ23zw1ss97Z src]# ./redis-cli 127.0.0.1:6379> pingPONG127.0.0.1:6379> set mykey somevalueOK127.0.0.1:6379> get mykey"somevalue"127.0.0.1:6379> ####停止redis服务[root@iZ23zw1ss97Z src]# ./redis-cli shutdown[root@iZ23zw1ss97Z src]#
注:外部访问时,需要将该端口在防火墙中放开
linux下redis设置密码登录
redis设置密码访问
你的redis在真是环境中不可以谁想访问就可以访问,所以必须要设置密码
设置密码的流程如下:
[root@iZ23zw1ss97Z redis-stable]# pwd/app/redis-stable[root@iZ23zw1ss97Z redis-stable]# vi redis.conf
#requirepass foobared去掉注释,foobared改为自己的密码,我在这里改为
requirepass 123456
然后保存,重启服务
[root@iZ23zw1ss97Z redis-stable]# [root@iZ23zw1ss97Z redis-stable]# cd src####启动redis服务[root@iZ23zw1ss97Z src]# ./redis-server ../redis.conf######################## 检查进程中是否已有redis服务[root@iZ23zw1ss97Z src]# ps -ef|grep -v grep |grep redisroot 5715 1 0 20:33 ? 00:00:00 ./redis-server *:6379[root@iZ23zw1ss97Z src]#
测试连接:./redis-cli
输入命令 会提示(error) NOAUTH Authentication required. 这是属于正常现象。
我们输入 auth 123456#你刚才设置的密码