惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

博客园 - herobeast

hadoop 2.7.1 高可用安装部署 MySql篇 Tomcat篇 JDK篇 web一次下载多个附件 Implementing a Custom Security Manager(翻译) 腾达路由器设置 正则表达式 jQuery Resizable笔记 OSGi规范 OSGi bundle 与 fragment OSGi bundle之间互相通信的方法 Apache CXF 分布式OSGi部署HelloWorld 五米测试 Spring.DM web 开发环境搭建 - herobeast Spring.DM版HelloWorld 腾讯资深产品经理谈敏捷开发于游戏 js矢量图类库:Raphaël—JavaScript Library 关于生成id的问题
Redis篇
herobeast · 2015-09-23 · via 博客园 - herobeast

一:下载redis

    官网地址:http://redis.io/

    如果系统没有安装make,请查看mysql篇

  1. wget http://download.redis.io/redis-stable.tar.gz
  2. tar xzf redis-stable.tar.gz
  3. cd redis-stable
  4. make MALLOC=libc
  5. make install

Redis默认支持16个数据库,不同的应用应该使用不同的Redis实例存储数据。由于Redis非常轻量级,一个空Redis实例占用的内存只有1MB左右,所以不用担心多个Redis实例会占用很多内存。

二、测试是否安装成功

注意:redis服务默认端口号是6379,请设置防火墙保持该端口可以访问,设置好后可以在客户端使用telnet命令测试

  1. telnet 172.19.32.xx 6379

启动redis服务

  1. redis-server

也可以使用下面的

  1. redis-server redis.conf

关闭服务

  1. redis-cli SHUTDOWN

(//停止Redis,Redis收到SHUTDOWN命令后,会先断开所有客户端连接,然后根据配置执行持久化,最后完成退出,“kill Redis进程PID”也可以正常结束)

使用客户端测试

  1. redis-cli -h 127.0.0.1 -p 6379

或者使用下面的命令测试

  1. redis-cli PING

如果接收到PONG说明一切正常,客户端请求收到服务端的响应。

参考:

http://blog.csdn.net/rachel_luo/article/details/8858250

首先拷贝一份redis.conf,到/etc下,做为服务启动配置

  1. cp redis.conf /etc

配置启动init脚本(install的时候,redis的命令会被拷贝到/usr/local/bin下面)

  1. # chkconfig: 2345 90 10
  2. # description: Redis is a persistent key-value database
  3. PATH=/usr/local/bin:/sbin:/usr/bin:/bin
  4. REDISPORT=6379
  5. EXEC=/usr/local/bin/redis-server
  6. REDIS_CLI=/usr/local/bin/redis-cli
  7. PIDFILE=/var/run/redis.pid
  8. CONF="/etc/redis.conf"
  9. case "$1" in
  10. start)
  11. if [ -f $PIDFILE ]
  12. then
  13. echo "$PIDFILE exists, process is already running or crashed"
  14. else
  15. echo "Starting Redis server..."
  16. $EXEC $CONF
  17. fi
  18. if [ "$?"="0" ]
  19. then
  20. echo "Redis is running..."
  21. fi
  22. ;;
  23. stop)
  24. if [ ! -f $PIDFILE ]
  25. then
  26. echo "$PIDFILE does not exist, process is not running"
  27. else
  28. PID=$(cat $PIDFILE)
  29. echo "Stopping ..."
  30. $REDIS_CLI -p $REDISPORT SHUTDOWN
  31. while [ -x ${PIDFILE} ]
  32. do
  33. echo "Waiting for Redis to shutdown ..."
  34. sleep 1
  35. done
  36. echo "Redis stopped"
  37. fi
  38. ;;
  39. restart|force-reload)
  40. ${0} stop
  41. ${0} start
  42. ;;
  43. *)
  44. echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
  45. exit 1
  46. esac
  47. ##############################

把上述代码存为redis,放到/etc/init.d/下面

可以使用下面的命令

  1. vi /etc/init.d/redis

然后把上面的代码拷贝上去,然后保存就可以了,然后设置文件的权限

  1. chmod +x /etc/init.d/redis

设置为开机启动(注意:redis文件中前两行注释代码是必须的,否则下面的命令会报:redis 服务不支持 chkconfig,错误

  1. chkconfig redis on

启动停止服务

  1. service redis start #或者 /etc/init.d/redis start
  2. service redis stop #或者 /etc/init.d/redis stop

测试服务

  1. redis-cli
  2. redis 127.0.0.1:6379> set foo 123
  3. OK
  4. redis 127.0.0.1:6379> get foo
  5. "123"
  6. redis 127.0.0.1:6379> exit