redis安装
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了redis安装,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含7524字,纯文字阅读大概需要11分钟。
内容图文
![redis安装](/upload/InfoBanner/zyjiaocheng/1257/c7c6bba7a8fd4068a3a9a32c3627cde5.jpg)
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上测试通过
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‘151617function install_redis() { 18 test -f /etc/redhat-release && PKGM=yum || PKG=zypper 19 ${PKGM} installgccwget20 ### create base dir ### 21mkdir -p ${datadir} 22mkdir -p ${installbindir} 23mkdir -p ${installetcdir} 24### down and copy bin ### 25mkdir -p ~root/Downloads/ && cd ~root/Downloads/ 26 test -f ${pkgfilename} || wget http://download.redis.io/releases/${pkgfilename} && tar -zxvf ${pkgfilename} && cd ${pkgname}27make MALLOC=libc && find ./src -perm 755 -exec cp {} ${installbindir}/ \; 28 #for i in ${binfile};do29 # cp ${i} ${installbindir}/ && echo"Install $i OK"30 #done31 ### config file ### 32cp ./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} 363738function config_instance(){ 39if [ $# -eq 1 ];then40 port=$141else42echo‘Please give instance port!‘43 exit 144fi4546grep -vE ‘^$|^#‘ ${installetcdir}/redis.conf > ${installetcdir}/${port}.conf 47#set port number 48sed -i /port/s/6379/${port}/ ${installetcdir}/${port}.conf 49#enable daemonize 50sed -i /daemonize/s/no/yes/ ${installetcdir}/${port}.conf 51#set pid with port number 52sed -i /pidfile/s/redis.pid/redis-${port}.pid/ ${installetcdir}/${port}.conf 53#data 54mkdir -p ${datadir}/${port} 55sed -i "/dir/s/\.\//\/data\/redis\/${port}/" ${installetcdir}/${port}.conf 56#set logfile with port number 57#LOG非绝对路径,则放在数目录下 58sed -i "/logfile/s/\"\"/${port}\.log/" ${installetcdir}/${port}.conf 59##start intance 60 cd ${installdir} && ${installbindir}/redis-server ${installetcdir}/${port}.conf 61} 6263function uninstall_redis() { 64rm -rf ${datadir} && echo"Clean ${datadir} OK"65rm -rf ${installdir} && echo"Clean ${installdir} OK"66} 6768#main 69if [ $# -ge 1 ];then70if [ $1 = ‘install‘ ];then71echo‘Install‘72 install_redis 73elif [ $1 = ‘uninstall‘ ];then74 uninstall_redis 75elif [ $1 = ‘confinstance‘ ];then76if [ $# -eq 2 ];then77 port=$278 config_instance $port 79else80echo"Please give a instance port!"81fi82else83echo"Usage: ${0} {install|uninstall|confinstance [portnumber]}"84fi85else86echo"Usage: ${0} {install|uninstall|confinstance [portnumber]}"87fi
二、包管理系统安装
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
原文:http://www.cnblogs.com/diege/p/3739183.html
内容总结
以上是互联网集市为您收集整理的redis安装全部内容,希望文章能够帮你解决redis安装所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。