linux下安装redis3.2

这部分来自网络:

http://blog.csdn.net/cuibruce/article/details/53501532

1.下载

下载地址:http://www.redis.io/download

选取当前最新版本3.2.1下载,上传到linux上,进行解压缩:

[[email protected] redis]# ls

redis-3.2.1 redis-3.2.1.tar.gz

2.编译安装

进入redis-3.2.1目录下,运行make进行安装编译:

[[email protected] redis-3.2.1]# ls

00-RELEASENOTES BUGS CONTRIBUTING COPYING deps INSTALL Makefile MANIFESTO README.md redis.conf runtest runtest-cluster runtest-sentinel sentinel.conf src tests utils

make需要安装编译器,默认为gcc.

[[email protected] redis-3.2.1]# make

cd src && make all

make[1]: Entering directory `/root/redis/redis-3.2.1/src‘

CC adlist.o

CC quicklist.o

CC ae.o

In file included from ae.c:53:

ae_epoll.c: In function ‘aeApiAddEvent‘:

ae_epoll.c:75: warning: missing initializer

ae_epoll.c:75: warning: (near initialization for ‘ee.data‘)

ae_epoll.c: In function ‘aeApiDelEvent‘:

ae_epoll.c:92: warning: missing initializer

ae_epoll.c:92: warning: (near initialization for ‘ee.data‘)

CC anet.o

anet.c: In function ‘anetSockName‘:

anet.c:640: warning: dereferencing pointer ‘s‘ does break strict-aliasing rules

anet.c:638: note: initialized from here

anet.c:644: warning: dereferencing pointer ‘s‘ does break strict-aliasing rules

anet.c:642: note: initialized from here

anet.c: In function ‘anetPeerToString‘:

anet.c:584: warning: dereferencing pointer ‘s‘ does break strict-aliasing rules

anet.c:582: note: initialized from here

anet.c:588: warning: dereferencing pointer ‘s‘ does break strict-aliasing rules

anet.c:586: note: initialized from here

anet.c: In function ‘anetTcpAccept‘:

anet.c:555: warning: dereferencing pointer ‘s‘ does break strict-aliasing rules

anet.c:553: note: initialized from here

anet.c:559: warning: dereferencing pointer ‘s‘ does break strict-aliasing rules

anet.c:557: note: initialized from here

CC dict.o

CC server.o

CC sds.o

CC zmalloc.o

CC lzf_c.o

CC lzf_d.o

CC pqsort.o

CC zipmap.o

CC sha1.o

CC ziplist.o

CC release.o

CC networking.o

CC util.o

CC object.o

CC db.o

CC replication.o

CC rdb.o

CC t_string.o

CC t_list.o

CC t_set.o

CC t_zset.o

CC t_hash.o

CC config.o

CC aof.o

CC pubsub.o

CC multi.o

CC debug.o

CC sort.o

CC intset.o

CC syncio.o

CC cluster.o

CC crc16.o

CC endianconv.o

CC slowlog.o

CC scripting.o

CC bio.o

CC rio.o

CC rand.o

CC memtest.o

CC crc64.o

CC bitops.o

CC sentinel.o

CC notify.o

CC setproctitle.o

CC blocked.o

CC hyperloglog.o

CC latency.o

CC sparkline.o

CC redis-check-rdb.o

CC geo.o

LINK redis-server

INSTALL redis-sentinel

CC redis-cli.o

LINK redis-cli

CC redis-benchmark.o

LINK redis-benchmark

INSTALL redis-check-rdb

CC redis-check-aof.o

LINK redis-check-aof

 

Hint: It‘s a good idea to run ‘make test‘ ;)

 

make[1]: Leaving directory `/root/redis/redis-3.2.1/src‘

make完成之后,进行install,默认安装路径为/usr/local/bin下,这里我们把他安装目录放到/usr/local/redis下,使用PREFIX指定目录:

[[email protected] redis-3.2.1]# mkdir /usr/local/redis

[[email protected] redis-3.2.1]# make PREFIX=/usr/local/redis install

cd src && make install

make[1]: Entering directory `/root/redis/redis-3.2.1/src‘

 

Hint: It‘s a good idea to run ‘make test‘ ;)

 

INSTALL install

INSTALL install

INSTALL install

INSTALL install

INSTALL install

make[1]: Leaving directory `/root/redis/redis-3.2.1/src‘

将redis可执行目录添加到环境变量中,编辑~/.bash_profile添加redis环境变量:

[[email protected] bin]# cat ~/.bash_profile

# .bash_profile

 

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

 

# User specific environment and startup programs

 

PATH=/usr/local/redis/bin:/usr/local/mongodb/bin:$PATH:$HOME/bin

3.创建redis服务

此时其实就可以启动redis服务了,例如:

% ./redis-server --port 9999 --slaveof 127.0.0.1 6379

% ./redis-server /etc/redis/6379.conf --loglevel debug

但是我们一般还是把redis做成服务来启动,进入到utils目录,然后运行install_server.sh,运行这个会询问你几个问题,包括

指定redis的端口号

指定redis的配置文件

指定redis的日志文件

指定redis的数据目录文件

指定redis的可执行目录文件.

[[email protected] utils]# ./install_server.sh

Welcome to the redis service installer

This script will help you easily set up a running redis server

 

Please select the redis port for this instance: [6379]

Selecting default: 6379

Please select the redis config file name [/etc/redis/6379.conf]

Selected default - /etc/redis/6379.conf

Please select the redis log file name [/var/log/redis_6379.log] /data/redis/log/redis_6378.log

Please select the data directory for this instance [/var/lib/redis/6379] /data/redis/6379

Please select the redis executable path [/usr/local/redis/bin/redis-server]

Selected config:

Port : 6379

Config file : /etc/redis/6379.conf

Log file : /data/redis/log/redis_6378.log

Data dir : /data/redis/6379

Executable : /usr/local/redis/bin/redis-server

Cli Executable : /usr/local/redis/bin/redis-cli

Is this ok? Then press ENTER to go on or Ctrl-C to abort.

Copied /tmp/6379.conf => /etc/init.d/redis_6379

Installing service...

Successfully added to chkconfig!

Successfully added to runlevels 345!

Starting Redis server...

Installation successful!

完成之后,redis的服务就添加完毕了,服务名为redis_6379:

[[email protected] init.d]# ls -l re*

-rwxr-xr-x 1 root root 1714 Jul 1 11:13 redis_6379

-rwxr-xr-x. 1 root root 1822 Jan 16 2013 restorecond

启动和关闭redis服务:

[[email protected] init.d]# service redis_6379 status

Redis is running (19280)

[[email protected] init.d]# service redis_6379 stop

Stopping ...

Redis stopped

[[email protected] init.d]# service redis_6379 start

Starting Redis server...

使用redis-cli连接redis:

[[email protected] init.d]# redis-cli

127.0.0.1:6379>

4.redis服务解析

其实做完以上几步,我们已经可以正常使用redis了,下面我们来解析一下redis的启动停止过程.我们解析/etc/init.d/redis_6379文件:

#!/bin/sh

#Configurations injected by install_server below....

 

EXEC=/usr/local/redis/bin/redis-server

CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_6379.pid

CONF="/etc/redis/6379.conf"

REDISPORT="6379"

###############

# SysV Init Information

# chkconfig: - 58 74

# description: redis_6379 is the redis daemon.

### BEGIN INIT INFO

# Provides: redis_6379

# Required-Start: $network $local_fs $remote_fs

# Required-Stop: $network $local_fs $remote_fs

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Should-Start: $syslog $named

# Should-Stop: $syslog $named

# Short-Description: start and stop redis_6379

# Description: Redis daemon

### END INIT INFO

 

 

case "$1" in

start)

if [ -f $PIDFILE ]

then

echo "$PIDFILE exists, process is already running or crashed"

else

echo "Starting Redis server..."

$EXEC $CONF

fi

;;

stop)

if [ ! -f $PIDFILE ]

then

echo "$PIDFILE does not exist, process is not running"

else

PID=$(cat $PIDFILE)

echo "Stopping ..."

$CLIEXEC -p $REDISPORT shutdown

while [ -x /proc/${PID} ]

do

echo "Waiting for Redis to shutdown ..."

sleep 1

done

echo "Redis stopped"

fi

;;

status)

PID=$(cat $PIDFILE)

if [ ! -x /proc/${PID} ]

then

echo ‘Redis is not running‘

else

echo "Redis is running ($PID)"

fi

;;

restart)

$0 stop

$0 start

;;

*)

echo "Please use start, stop, restart or status as first argument"

;;

esac

可以发现,其实启动redis的语法就是:

/usr/local/redis/bin/redis-server /etc/redis/6379.conf

关闭redis的语法就是:

/usr/local/redis/bin/redis-server -p 6379 shutdown

检查redis是否运行,就是检查redis的pid文件下的进程是否存在.

查看redis的配置文件/etc/redis/6379.conf,里面有很多注释,去除注释:

[[email protected] utils]# grep -E -v "^#" /etc/redis/6379.conf |sed ‘/^$/d‘

bind 127.0.0.1

protected-mode yes

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize yes

supervised no

pidfile /var/run/redis_6379.pid

loglevel notice

logfile /data/redis/log/redis_6379.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/6379

slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

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

aof-load-truncated yes

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

notify-keyspace-events ""

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-size -2

list-compress-depth 0

set-max-intset-entries 512

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

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

其中主要的参数:

bind:绑定的ip地址

port:监听端口号

pidfile:pid文件名

dir:数据文件目录

logfile:日志文件地址

最后我分享一下我遇到的坑:

第一:我发现别的服务器不可以访问redis

开始以为是iptables  然后各种设置不中

程序连接 connection timetout 本地telnet也不通  原因是 etc/redis/6379.conf  里面bind 127.0.0.1  把所有的bind去掉 这样就可以任意访问了 不用设置具体的ip。

第二:第一步设置完之后 用程序连接发现报如下错误:

redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only

accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no‘ from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to ‘no‘, and then restarting the server. 3) If you started the server manually just for testing, restart it with the ‘--protected-mode no‘ option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
at redis.clients.jedis.Protoc

大致意思是开启了保护模式  访问只能通过backloop地址访问

解决办法依旧是修改7379_conf  把protected-mode 修改为no          然后              daemonize no设置为yes 注册为服务在后台跑

重新启动redis就ok

时间: 2024-08-09 10:34:40

linux下安装redis3.2的相关文章

Linux下安装禅道管理系统7.2

提示:禅道是用PHP开发的,只要安装一个MySQL,找一个能跑PHP的web应用服务器,把禅道源代码放到里面,然后按步骤安装就可以了.不一定要用XAMPP,XAMPP只是把PHP环境和MySQL都集成了而已. 禅道简介 禅道项目管理软件(ZenTaoPMS)是一款国产的,基于ZPL协议,开源免费的项目管理软件,它集产品管理.项目管理.测试管理于一体,同时还包含了事务管理.组织管理等诸多功能,是一款功能完备的项目管理软件,完美地覆盖了项目管理的核心流程,是中小型企业项目管理的首选. 禅道项目管理软

Linux下安装搭建Memcached集群环境

Linux下安装搭建Memcached集群环境

FFmpeg在Linux下安装编译过程

转载请把头部出处链接和尾部二维码一起转载,本文出自:http://blog.csdn.net/hejjunlin/article/details/52402759 今天介绍下FFmpeg在Linux下安装编译过程,用的是CentOS, 总体过程比较顺利,就是在ffmpeg等的时间稍长点.没什么技术难点.仅当记录. 关于FFmpeg FFmpeg是一个开源免费跨平台的视频和音频流方案,属于自由软件,采用LGPL或GPL许可证(依据你选择的组件).它提供了录制.转换以及流化音视频的完整解决方案.它包

Linux下安装配置Apache服务器

Linux下安装配置Apache服务器 1. 安装Apache [[email protected] ~]# yum –y install httpd 2. 启动Apache [[email protected] ~]# systemctl start httpd 3. 查看进程 [[email protected] ~]# systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib

linux 下安装 mysql 并配置 python 开发环境

1.安装 mysql ,安装过程中将提示设置 root 用户的密码,默认可以设置为 rootadmin . $ sudo apt-get install mysql-server 2.安装 mysql 开发工具(不安装时,安装 MySQL-python 提示错误 "mysql_config not found"). $ sudo apt-get install libmysqld-dev 3.安装 python 的 mysql 库 MySQL-python (首先安装 python-d

Linux下安装jdk8步骤详述

作为Java开发人员,在Linux下安装一些开发工具是必备技能,本文以安装jdk为例,详细记录了每一步的操作命令,以供参考. 0.下载jdk8 登录网址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html选择对应jdk版本下载.(可在Windows下下载完成后,通过文件夹共享到Linux上) 1. 登录Linux,切换到root用户 su root 获取root用户权限,当前工作目

linux下安装安装pcre-8.32 configure: error: You need a C++ compiler for C++ support

linux下安装安装pcre-8.32./configure --prefix=/usr/local/pcre 出现以下错误configure: error: You need a C++ compiler for C++ support 正解 yum install -y gcc gcc-c++

Python MySQLdb Linux下安装笔记

本文介绍了Python MySQLdb Linux下安装笔记,本文分别讲解了快速安装和手动编译安装两种方法,并分别讲解了操作步骤,需要的朋友可以参考下 主要针对centos6.5 64位系统 默认python版本为2.6 编码安装python2.7和python3.4      一.yum快速安装 yum install MySQL-python yum install python-setuptools 经常接触Python的同学可能会注意到,当需要安装第三方python包时,可能会用到eas

随笔记:Linux下安装Python

下载Python 在官网上下载安装包,目前地址为:https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz 得到Python-2.7.9.tgz 解压 将Python-2.7.9.tgz解压到当前目录下 tar zxvf ./Python-2.7.9.tgz -C ./ 安装 切换到根目录,开始安装 sudo ./configure sudo make sudo make install 测试 测试下有木有安装成功,如顺利,能看到以下日志