设为首页 收藏本站
查看: 1020|回复: 0

[经验分享] ubuntu下redis安装配置

[复制链接]

尚未签到

发表于 2018-5-9 08:45:27 | 显示全部楼层 |阅读模式
  ubuntu下redis安装配置  原文地址:http://www.ttlsa.com/archives/184
一.redis介绍
redis是一个key-value存储系统,与memcached类似,但是解决了断电后数据完全丢失的现象。支持数据类型有string,lists,sets,zsets。这些数据类型都支持push/pop,add/remove以及取交集并集差集等操作,对这些操作都是原子性的,redis还支持各种不同的排序能力。
  二.redis安装
$ sudo wget http://redis.googlecode.com/files/redis-2.2.12.tar.gz
$ sudo tar zxvf redis-2.2.12.tar.gz -C ../software/
$ sudo cd /usr/local/src/software/redis-2.2.12/src
$ sudo make PREFIX=/usr/local/redis-2.2.12
$ sudo make test
Testing Redis version 2.2.12 (00000000)
831 tests, 831 passed, 0 failed
$ sudo make PREFIX=/usr/local/redis-2.2.12  install
  常见错误:
(cd ..; tclsh8.5 tests/test_helper.tcl --tags "" --file "")
/bin/sh: tclsh8.5: not found
make: *** [test] Error 127
解决方法:
$ sudo apt-get install tcl8.5
  三.redis配置
$ sudo mkdir -p /usr/local/redis-2.2.12/{etc,var}
redis-server:redis服务的启动程序
redis-cli:redis命令行操作工具
redis-benchmark:redis性能测试工具
redis-check-aof:更新日志检查
redis-check-dump:本地数据检查
$ sudo cp redis.conf /usr/local/redis-2.2.12/etc/
  redis.conf配置参数说明:
daemonize  //是否以后台进程运行,默认为no
pidfile /var/run/redis.pid  //pid文件路径
port 6379  //监听端口
bind 127.0.0.1  //绑定主机ip
unixsocket /tmp/redis.sock   //sock文件路径
timeout 300  //超时时间,默认是300s
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel verbose  //日志等级,可选项有debug,verbose,notice,warning 默认是erbose
logfile stdout  //日志记录方式,默认是stdout
syslog-enabled no //日志记录到系统日志中,默认是no
syslog-ident redis  //指定系统日志标识
# Specify the syslog facility.  Must be USER or between LOCAL0-LOCAL7.
syslog-facility local0  //指定系统日志设备,默认是local0
# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16  //可用数据库数,默认值是16,默认数据库是0
  save <seconds> <changes>  //在多长时间内,有多少次更新操作,就将数据同步到数据文件。
save 900 1  //15min内至少1个key被改变
save 300 10 //5min内至少有300个key被改变
save 60 10000  //60s内至少有10000个key被改变
  rdbcompression yes  //存储至本地数据库时是否压缩数据,默认是yes
  dbfilename dump.rdb  //本地数据库文件名,默认是dump.rdb
dir ./  //本地数据库存放路径,默认是./
  slaveof <masterip> <masterport>  //当本机为从服务时,设置主服务的ip以及端口
masterauth <master-password>  //主服务的连接密码
  # When a slave lost the connection with the master, or when the replication
# is still in progress, the slave can act in two different ways:
#
# 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
#    still reply to client requests, possibly with out of data data, or the
#    data set may just be empty if this is the first synchronization.
#
# 2) if slave-serve-stale data is set to 'no' the slave will reply with
#    an error &quot;SYNC with master in progress&quot; to all the kind of commands
#    but to INFO and SLAVEOF.
#
slave-serve-stale-data yes
  requirepass foobared  //连接密码foobared
  maxclients 128  //最大连接数,默认不限制
  maxmemory <bytes>  //设置最大内存,达到最大内存设置后,redis会先尝试清除已到期或即将到期的key,当此方法处理后,任然到达最大内存设置,将无法再进行写入操作
  maxmemory设置策略
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys->random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy volatile-lru  //maxmemory设置策略,默认是volatile-lru.
maxmemory-samples 3
  appendonly no  //是否 在每次更新操作后进行日志记录,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为redis本身同步数据文件是按照上面save条件来进行同步的,所以有的数据会在一段时间内只存在于内存中。默认是no
appendfilename appendonly.aof  //更新日志文件名,默认是appendonly.aof
  redis支持的三种不同的同步方式:
# no: don't fsync, just let the OS flush the data when it wants. Faster.  //等待OS进行数据缓存同步到硬盘
# always: fsync after every write to the append only log . Slow, Safest.  //每次更新操作后调用fsync()将数据写到磁盘
# everysec: fsync only if one second passed since the last fsync. Compromise. //每秒同步一次
appendfsync everysec //更新日志条件,默认是everysec
no-appendfsync-on-rewrite no
  slowlog-log-slower-than 10000  //设置redis slow log时间,只包括命令执行时间,不包括IO操作时间,比如客户端连接,应答相应时间等等。单位是microseconds(一百万分之一秒),默认是10000.负值表示禁用slow log,0表示记录所有命令。
  slowlog-max-len 1024  //slowlog最大长度1024.这会消耗内存,使用SLOWLOG RESET来回收slowlog内存。
  
#在redis2.4版本,强烈不建议使用virtual memory。
vm-enabled no  //是否使用虚拟内存,默认是no
vm-swap-file /tmp/redis.swap  //虚拟内存文件路径,默认是/tmp/redis.swap,不可多个redis实例共享虚拟内存文件。
vm-max-memory 0 //设置最大vm,默认为0,所有的value存在于磁盘中。
vm-page-size 32  //设置vm的page大小,默认是32
vm-pages 134217728  //设置swap文件中最大memory pages,默认是134217728。swap大小=vm-page-size * vm-pages
vm-max-threads 4  //vm同时运行的最大io线程
  #指定在超过一定的数量或者最大的元素超过某一临界值时,采用一种特殊的哈希算法
hash-max-zipmap-entries 512
hash-max-zipmap-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
activerehashing yes  //是否重置hash表
  include /path/to/other.conf   //引用其他配置文件
  $ sudo vim /etc/sysctl.conf
vm.overcommit_memory = 1   //指定内核针对内存分配的策略,其值可以是0,1,2
0表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2表示内核允许分配超过所有物理内存和交换空间总和的内存
$ sudo sysctl -p
  $ sudo vim  redis.conf
daemonize yes
pidfile /var/run/redis.pid
port 6379
timeout 300
loglevel verbose
logfile /usr/local/redis-2.2.12/var/log/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /usr/local/redis-2.2.12/var/data
appendonly no
appendfsync everysec
no-appendfsync-on-rewrite no
slowlog-log-slower-than 10000
slowlog-max-len 1024
vm-enabled no
vm-swap-file /tmp/redis.swap
vm-max-memory 0
vm-page-size 32
vm-pages 134217728
vm-max-threads 4
hash-max-zipmap-entries 512
hash-max-zipmap-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
activerehashing yes
启动:
$ sudo /usr/local/redis-2.2.12/bin/redis-server /usr/local/redis-2.2.12/etc/redis.conf
  四.测试
$ cat /etc/passwd | ./redis-cli -x set mykey
OK
$ ./redis-cli get mykey
&quot;root:x:0:0:root:/root:/bin/bash\daemon:x:1:1:daemon:/usr/sbin:/bin/sh\mysql:x:111:120:MySQL Server,,,:/var/lib/mysql:/bin/false\&quot;
  ubuntu下redis安装配置  原文地址:http://www.ttlsa.com/archives/184

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-457412-1-1.html 上篇帖子: Ubuntu Eclipse Java EE中安装CDT 下篇帖子: Ubuntu安装shutter
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表