码迷,mamicode.com
首页 > 其他好文 > 详细

redis安装

时间:2014-05-21 21:54:30      阅读:700      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   c   code   java   

Auth: jin
Date: 20140520
参考:
http://www.redis.cn/article.html
官网:http://redis.io/

一、源码安装
1.create basedir
mkdir -p /data/redis
mkdir -p /usr/local/redis/bin
mkdir -p /usr/local/redis/etc
mkdir -p /var/log/redis/

2.down and unzip
cd ~root/Downloads/
redisversion=redis-2.8.7 && wget http://download.redis.io/releases/${redisversion}.tar.gz && tar -zxvf ${redisversion}.tar.gz && cd ${redisversion}

3、make and install
make命令执行完成后,会在当前目录下生成本个可执行文件,分别是redis-server、redis-cli、redis-benchmark、redis-stat,它们的作用如下:
redis-server:Redis服务器的daemon启动程序
redis-cli:Redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作
redis-benchmark:Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
redis-stat:Redis状态检测工具,可以检测Redis当前状态参数及延迟状况

make报错
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
解决办法:make MALLOC=libc

make后这些文件编译到src目录下了
# find ./ -perm 755
./redis-server
./redis-cli
./redis-check-aof
./redis-check-dump
./redis-benchmark
./redis-sentinel

find ./src -perm 755 -exec cp {} /usr/local/redis/bin \;
#find /usr/local/redis/ -perm 755 -a -type f -exec rm -f {} \;

4、config
cp redis.conf /usr/local/redis/etc/
cp /usr/local/redis/etc/redis.conf /usr/local/redis/etc/6380.conf
vim /usr/local/redis/etc/6380.conf
daemonize yes
pidfile /var/run/redis-6380.pid
port 6380
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile 6380.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis/6380
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

5、系统修改
#/etc/sysctl.conf
vm.overcommit_memory=1
sysctl vm.overcommit_memory=1

补充介绍:
**如果内存情况比较紧张的话,需要设定内核参数:
echo 1 > /proc/sys/vm/overcommit_memory
没设置启动后LOG提示
[20681] 09 May 13:53:09.249 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1‘ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1‘ for this to take effect.

6、启动
cd /usr/local/redis
./bin/redis-server ./etc/6380.conf
# netstat -anltp|grep 6380
./bin/redis-cli -p 6380 ping
PONG
# redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>

Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --slaveof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel
7、测试
MyOpenSUSE:/usr/local/redis # ./bin/redis-cli -p 6380 set name jin
OK
MyOpenSUSE:/usr/local/redis # ./bin/redis-cli -p 6380 get name
"jin"
客户端也可以使用telnet形式连接。
# telnet 127.0.0.1 6380
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is ‘^]‘.
set name jin
+OK
get name
$3
jin
quit
+OK
Connection closed by foreign host.

8、关闭服务
$ redis-cli shutdown
#关闭指定端口的redis-server
$redis-cli -p 6380 shutdown

MyOpenSUSE:/usr/local/redis # ./bin/redis-cli -p 6380 shutdown
MyOpenSUSE:/usr/local/redis # ./bin/redis-cli -p 6380 ping
Could not connect to Redis at 127.0.0.1:6380: Connection refused

redis-cli命令总结
http://hi.baidu.com/274084093/item/afe738d19338f1bb32db906f

9.自己写的快速安装配置脚本

在opensuse13.1,centos6.5上测试通过

bubuko.com,布布扣
bubuko.com,布布扣
 1 #!/bin/bash -
 2 #Date: 2014-05-20
 3 #Auth: Jin
 4 
 5 version=2.8.7
 6 progname=redis
 7 pkgname="${progname}-${version}"
 8 pkgfilename="${pkgname}.tar.gz"
 9 installdir="/usr/local/${progname}"
10 logdir="/var/log/${progname}"
11 installbindir="${installdir}/bin"
12 installetcdir="${installdir}/etc"
13 datadir=/data/redis
14 binfile=redis-server redis-cli redis-check-aof redis-check-dump redis-benchmark redis-sentinel
15 
16 
17 function install_redis() {
18 test -f /etc/redhat-release &&  PKGM=yum || PKG=zypper
19 ${PKGM} install gcc wget
20 ### create base dir ###
21 mkdir -p ${datadir}
22 mkdir -p ${installbindir}
23 mkdir -p ${installetcdir}
24 ### down and copy bin ###
25 mkdir -p ~root/Downloads/ && cd ~root/Downloads/
26 test -f ${pkgfilename} || wget http://download.redis.io/releases/${pkgfilename} && tar -zxvf ${pkgfilename} && cd ${pkgname}
27 make MALLOC=libc && find ./src -perm 755 -exec cp {} ${installbindir}/  \;  
28 #for i in ${binfile};do
29 #    cp ${i} ${installbindir}/ && echo "Install $i OK"
30 #done
31 ###  config file ###
32 cp ./redis.conf ${installetcdir}/ &&  echo "Install redis.conf OK"
33 ### kernel option of ram is low ###a
34 #echo vm.overcommit_memory=1 >> /etc/sysctl.conf && sysctl -p /etc/sysctl.conf
35 }
36 
37 
38 function config_instance(){
39 if [ $# -eq 1 ];then
40         port=$1
41 else
42    echo Please give instance port!
43    exit 1
44 fi
45 
46 grep -vE ^$|^# ${installetcdir}/redis.conf > ${installetcdir}/${port}.conf
47 #set port number
48 sed -i /port/s/6379/${port}/ ${installetcdir}/${port}.conf
49 #enable daemonize
50 sed -i /daemonize/s/no/yes/ ${installetcdir}/${port}.conf
51 #set pid with port number
52 sed -i /pidfile/s/redis.pid/redis-${port}.pid/ ${installetcdir}/${port}.conf
53 #data
54 mkdir -p ${datadir}/${port}
55 sed -i "/dir/s/\.\//\/data\/redis\/${port}/" ${installetcdir}/${port}.conf
56 #set logfile with port number
57 #LOG非绝对路径,则放在数目录下
58 sed -i "/logfile/s/\"\"/${port}\.log/" ${installetcdir}/${port}.conf
59 ##start intance 
60 cd ${installdir} &&  ${installbindir}/redis-server ${installetcdir}/${port}.conf
61 }
62 
63 function uninstall_redis() {
64 rm -rf ${datadir} && echo "Clean ${datadir} OK"
65 rm -rf ${installdir} && echo "Clean ${installdir} OK"
66 }
67 
68 #main
69 if [ $# -ge 1 ];then
70         if [ $1 = install ];then
71                 echo Install
72                 install_redis
73         elif [ $1 = uninstall ];then
74                 uninstall_redis
75         elif [ $1 = confinstance ];then
76                 if [ $# -eq 2 ];then
77                         port=$2
78                         config_instance $port
79                 else
80                         echo "Please give a instance port!"
81                 fi
82         else
83                 echo "Usage: ${0} {install|uninstall|confinstance [portnumber]}"
84         fi
85 else
86         echo "Usage: ${0} {install|uninstall|confinstance [portnumber]}"
87 fi
View Code
bubuko.com,布布扣

 

二、包管理系统安装
1.RHEL/CentOS
rpm -ivh ftp://195.220.108.108/linux/epel/6/i386/epel-release-6-8.noarch.rpm
yum -y install redis
2.OpenSuse
zypper install redis
# rpm -ql redis
/etc/logrotate.d/redis
/etc/rc.d/init.d/redis
/etc/redis.conf
/usr/bin/redis-benchmark
/usr/bin/redis-check-aof
/usr/bin/redis-check-dump
/usr/bin/redis-cli
/usr/sbin/redis-server
/usr/share/doc/redis-2.4.10
/usr/share/doc/redis-2.4.10/00-RELEASENOTES
/usr/share/doc/redis-2.4.10/BUGS
/usr/share/doc/redis-2.4.10/CONTRIBUTING
/usr/share/doc/redis-2.4.10/COPYING
/usr/share/doc/redis-2.4.10/README
/usr/share/doc/redis-2.4.10/TODO
/var/lib/redis
/var/log/redis
/var/run/redis
2.配置
3.启动
# /etc/init.d/redis start
Starting redis-server: [ OK ]
# systemctl status redis.service
# netstat -antlp |grep redis
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 20763/redis-server

redis安装,布布扣,bubuko.com

redis安装

标签:style   blog   class   c   code   java   

原文地址:http://www.cnblogs.com/diege/p/3739183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!