Ubuntu12.04安装redis

ubuntu 12.04 安装redis

1.$wget http://download.redis.io/releases/redis-2.8.3.tar.gz

2.$tar xzf redis-2.8.3.tar.gz

3.$cd redis-2.8.3

4.$make

5.$ sudo make install

 

启动服务:

 

mnclab@lmn:~$cd redis-2.8.3/

mnclab@lmn:~/redis-2.8.3$src/redis-server

[11480]26 Jan 10:44:01.022 # Warning: no config file specified, using the defaultconfig. In order to specify a config file use src/redis-server/path/to/redis.conf

[11480]26 Jan 10:44:01.022 # Unable to set the max number of files limit to 10032(Operation not permitted), setting the max clients configuration to 3984.

                _._                                                  

           _.-``__ ''-._                                             

      _.-``   `.  `_.  ''-._           Redis 2.8.3 (00000000/0) 64 bit

  .-`` .-```. ```\/    _.,_ ''-._                                   

 (   '      ,       .-` | `,    )     Running in stand alone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379

 |   `-._   `._    /    _.-'    |     PID: 11480

  `-._   `-._  `-./  _.-'   _.-'                                   

 |`-._`-._   `-.__.-'    _.-'_.-'|                                  

 |   `-._`-._        _.-'_.-'    |          http://redis.io        

  `-._   `-._`-.__.-'_.-'    _.-'                                   

 |`-._`-._   `-.__.-'    _.-'_.-'|                                  

 |   `-._`-._        _.-'_.-'    |                                  

  `-._   `-._`-.__.-'_.-'    _.-'                                   

      `-._   `-.__.-'    _.-'                                       

          `-._        _.-'                                           

              `-.__.-'                                               

 

[11480]26 Jan 10:44:01.023 # Server started, Redis version 2.8.3

[11480]26 Jan 10:44:01.023 # WARNING overcommit_memory is set to 0! Background savemay fail under low memory condition. To fix this issue add'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run thecommand 'sysctl vm.overcommit_memory=1' for this to take effect.

[11480]26 Jan 10:44:01.023 * The server is now ready to accept connections on port6379

 

打开新的终端,运行服务的客户端:

 

mnclab@lmn:~$cd redis-2.8.3/

mnclab@lmn:~/redis-2.8.3$src/redis-cli

127.0.0.1:6379>set good bubbu

OK

127.0.0.1:6379>get good

"bubbu"

127.0.0.1:6379>exit


Redis集群安装

安装redis

mnclab@cmy:~$ tar xzvf radis-....

mnclab@cmy:~$ sudo mv redis//usr/local/

[sudo] password for mnclab:

mnclab@cmy:~$ sudo mvredis.conf /usr/local/redis/

mnclab@cmy:~$ cd/usr/local/redis/

mnclab@cmy:/usr/local/redis$make

mnclab@cmy:/usr/local/redis$sudo make install

启动服务

mnclab@cmy:/usr/local/redis$src/redis-server redis.conf

验证服务已启动

mnclab@cmy:/usr/local/redis$cd

mnclab@cmy:~$ netstat -nlpt |grep 6379

(并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户)

tcp        0     0 0.0.0.0:6379            0.0.0.0:*               LISTEN      4542/redis-server*

tcp6       0     0 :::6379                :::*                    LISTEN      4542/redis-server*

启动客户端

mnclab@cmy:~$/usr/local/redis/src/redis-cli

127.0.0.1:6379> get food

"apple"

退出客户端

127.0.0.1:6379> quit

mnclab@cmy:~$

关闭服务

mnclab@cmy:~$/usr/local/redis/src/redis-cli shutdown

mnclab@cmy:~$ kill -9 4542

 

配置文件redis.conf如下:

# Redis configuration fileexample

 

# Note on units: when memorysize is needed, it is possible to specify

# it in the usual form of 1k5GB 4M and so forth:

#

# 1k => 1000 bytes

# 1kb => 1024 bytes

# 1m => 1000000 bytes

# 1mb => 1024*1024 bytes

# 1g => 1000000000 bytes

# 1gb => 1024*1024*1024bytes

#

# units are case insensitiveso 1GB 1Gb 1gB are all the same.

 

# By default Redis does notrun as a daemon. Use 'yes' if you need it.

# Note that Redis will writea pid file in /var/run/redis.pid when daemonized.

daemonize yes

 

# When running daemonized,Redis writes a pid file in /var/run/redis.pid by

# default. You can specify acustom pid file location here.

pidfile /var/run/redis.pid

 

# Accept connections on thespecified port, default is 6379.

# If port 0 is specifiedRedis will not listen on a TCP socket.

port 6379

 

# By default Redis listensfor connections from all the network interfaces

# available on the server. Itis possible to listen to just one or multiple

# interfaces using the"bind" configuration directive, followed by one or

# more IP addresses.

#

# Examples:

#

# bind 192.168.1.100 10.0.0.1

# bind 127.0.0.1

 

# Specify the path for theUnix socket that will be used to listen for

# incoming connections. Thereis no default, so Redis will not listen

# on a unix socket when notspecified.

#

# unixsocket /tmp/redis.sock

# unixsocketperm 755

 

# Close the connection aftera client is idle for N seconds (0 to disable)

timeout 0

 

# TCP keepalive.

#

# If non-zero, useSO_KEEPALIVE to send TCP ACKs to clients in absence

# of communication. This isuseful for two reasons:

#

# 1) Detect dead peers.

# 2) Take the connection alivefrom the point of view of network

#    equipment in the middle.

#

# On Linux, the specifiedvalue (in seconds) is the period used to send ACKs.

# Note that to close theconnection the double of the time is needed.

# On other kernels the perioddepends on the kernel configuration.

#

# A reasonable value for thisoption is 60 seconds.

tcp-keepalive 0

 

# Specify the serververbosity level.

# This can be one of:

# debug (a lot ofinformation, useful for development/testing)

# verbose (many rarely usefulinfo, but not a mess like the debug level)

# notice (moderately verbose,what you want in production probably)

# warning (only veryimportant / critical messages are logged)

loglevel notice

 

# Specify the log file name.Also the empty string can be used to force

# Redis to log on thestandard output. Note that if you use standard

# output for logging butdaemonize, logs will be sent to /dev/null

logfile "/usr/local/redis/redis-logs.log"

 

# To enable logging to thesystem logger, just set 'syslog-enabled' to yes,

# and optionally update theother syslog parameters to suit your needs.

# syslog-enabled no

 

# Specify the syslogidentity.

# syslog-ident redis

 

# Specify the syslogfacility. Must be USER or between LOCAL0-LOCAL7.

# syslog-facility local0

 

# Set the number ofdatabases. The default database is DB 0, you can select

# a different one on aper-connection basis using SELECT <dbid> where

# dbid is a number between 0and 'databases'-1

databases 16

 

################################SNAPSHOTTING  #################################

#

# Save the DB on disk:

#

#   save <seconds> <changes>

#

#   Will save the DB if both the given number ofseconds and the given

#   number of write operations against the DBoccurred.

#

#   In the example below the behaviour will be tosave:

#   after 900 sec (15 min) if at least 1 keychanged

#   after 300 sec (5 min) if at least 10 keyschanged

#   after 60 sec if at least 10000 keys changed

#

#   Note: you can disable saving at allcommenting all the "save" lines.

#

#   It is also possible to remove all thepreviously configured save

#   points by adding a save directive with asingle empty string argument

#   like in the following example:

#

#   save ""

 

save 900 1

save 300 10

save 60 10000

 

# By default Redis will stopaccepting writes if RDB snapshots are enabled

# (at least one save point)and the latest background save failed.

# This will make the useraware (in a hard way) that data is not persisting

# on disk properly, otherwisechances are that no one will notice and some

# disaster will happen.

#

# If the background savingprocess will start working again Redis will

# automatically allow writesagain.

#

# However if you have setupyour proper monitoring of the Redis server

# and persistence, you maywant to disable this feature so that Redis will

# continue to work as usualeven if there are problems with disk,

# permissions, and so forth.

stop-writes-on-bgsave-erroryes

 

# Compress string objectsusing LZF when dump .rdb databases?

# For default that's set to'yes' as it's almost always a win.

# If you want to save someCPU in the saving child set it to 'no' but

# the dataset will likely bebigger if you have compressible values or keys.

rdbcompression yes

 

# Since version 5 of RDB aCRC64 checksum is placed at the end of the file.

# This makes the format moreresistant to corruption but there is a performance

# hit to pay (around 10%)when saving and loading RDB files, so you can disable it

# for maximum performances.

#

# RDB files created withchecksum disabled have a checksum of zero that will

# tell the loading code toskip the check.

rdbchecksum yes

 

# The filename where to dumpthe DB

dbfilename dump.rdb

 

# The working directory.

#

# The DB will be writteninside this directory, with the filename specified

# above using the'dbfilename' configuration directive.

#

# The Append Only File willalso be created inside this directory.

#

# Note that you must specifya directory here, not a file name.

dir /usr/local/redis/data/

 

#################################REPLICATION #################################

 

# Master-Slave replication.Use slaveof to make a Redis instance a copy of

# another Redis server. Notethat the configuration is local to the slave

# so for example it ispossible to configure the slave to save the DB with a

# different interval, or tolisten to another port, and so on.

# master does not have thisparameter.

slaveof 192.168.1.122 6379

#              masterIP     redis port of master

 

# If the master is passwordprotected (using the "requirepass" configuration

# directive below) it ispossible to tell the slave to authenticate before

# starting the replicationsynchronization process, otherwise the master will

# refuse the slave request.

#

# masterauth<master-password>

 

# When a slave loses itsconnection with the master, or when the replication

# is still in progress, theslave can act in two different ways:

#

# 1) ifslave-serve-stale-data is set to 'yes' (the default) the slave will

#    still reply to client requests, possiblywith out of date data, or the

#    data set may just be empty if this is thefirst synchronization.

#

# 2) ifslave-serve-stale-data is set to 'no' the slave will reply with

#    an error "SYNC with master inprogress" to all the kind of commands

#    but to INFO and SLAVEOF.

#

slave-serve-stale-data yes

 

# You can configure a slaveinstance to accept writes or not. Writing against

# a slave instance may beuseful to store some ephemeral data (because data

# written on a slave will beeasily deleted after resync with the master) but

# may also cause problems ifclients are writing to it because of a

# misconfiguration.

#

# Since Redis 2.6 by defaultslaves are read-only.

#

# Note: read only slaves arenot designed to be exposed to untrusted clients

# on the internet. It's justa protection layer against misuse of the instance.

# Still a read only slaveexports by default all the administrative commands

# such as CONFIG, DEBUG, andso forth. To a limited extent you can improve

# security of read onlyslaves using 'rename-command' to shadow all the

# administrative / dangerouscommands.

slave-read-only yes

 

# Slaves send PINGs to serverin a predefined interval. It's possible to change

# this interval with therepl_ping_slave_period option. The default value is 10

# seconds.

#

# repl-ping-slave-period 10

 

# The following option setsthe replication timeout for:

#

# 1) Bulk transfer I/O duringSYNC, from the point of view of slave.

# 2) Master timeout from thepoint of view of sla

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值