您的位置:首页 > 数据库 > Redis

简化版Linux安装redis默认配置

2016-08-17 15:35 429 查看
$ wget http://download.redis.io/releases/redis-2.8.17.tar.gz
$ tar xzf redis-2.8.17.tar.gz

$ cd redis-2.8.17

$ make

报错:

[root@localhost redis-2.8.17]# make


cd src && make all

make[1]: Entering directory `/usr/local/redis-2.8.17/src'

rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-dump redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html

(cd ../deps && make distclean)

make[2]: Entering directory `/usr/local/redis-2.8.17/deps'

(cd hiredis && make clean) > /dev/null || true

(cd linenoise && make clean) > /dev/null || true

(cd lua && make clean) > /dev/null || true

(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true

(rm -f .make-*)

make[2]: Leaving directory `/usr/local/redis-2.8.17/deps'

(rm -f .make-*)

echo STD=-std=c99 -pedantic >> .make-settings

echo WARN=-Wall -W >> .make-settings

echo OPT=-O2 >> .make-settings

echo MALLOC=jemalloc >> .make-settings

echo CFLAGS= >> .make-settings

echo LDFLAGS= >> .make-settings

echo REDIS_CFLAGS= >> .make-settings

echo REDIS_LDFLAGS= >> .make-settings

echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -Wall -W -O2 -g -ggdb -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings

echo PREV_FINAL_LDFLAGS= -g -ggdb -rdynamic >> .make-settings

(cd ../deps && make hiredis linenoise lua jemalloc)

make[2]: Entering directory `/usr/local/redis-2.8.17/deps'

(cd hiredis && make clean) > /dev/null || true

(cd linenoise && make clean) > /dev/null || true

(cd lua && make clean) > /dev/null || true

(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true

(rm -f .make-*)

(echo "" > .make-ldflags)

(echo "" > .make-cflags)

MAKE hiredis

cd hiredis && make static

make[3]: Entering directory `/usr/local/redis-2.8.17/deps/hiredis'

gcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c

make[3]: gcc:命令未找到

make[3]: *** [net.o] 错误 127

make[3]: Leaving directory `/usr/local/redis-2.8.17/deps/hiredis'

make[2]: *** [hiredis] 错误 2

make[2]: Leaving directory `/usr/local/redis-2.8.17/deps'

make[1]: [persist-settings] 错误 2 (忽略)

CC adlist.o

/bin/sh: cc: command not found

make[1]: *** [adlist.o] 错误 127

make[1]: Leaving directory `/usr/local/redis-2.8.17/src'

make: *** [all] 错误 2



[root@localhost /]# yum install gcc


已加载插件:fastestmirror, product-id, subscription-manager

Updating certificate-based repositories.

Unable to read consumer identity

设置安装进程

Determining fastest mirrors

base | 3.7 kB 00:00

extras | 3.4 kB 00:00

extras/primary_db

...........................................

已安装:

gcc.x86_64 0:4.4.7-17.el6

作为依赖被安装:

cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-17.el6 glibc-devel.x86_64 0:2.12-1.192.el6 glibc-headers.x86_64 0:2.12-1.192.el6 kernel-headers.x86_64 0:2.6.32-642.3.1.el6

mpfr.x86_64 0:2.4.1-6.el6 ppl.x86_64 0:0.10.2-11.el6

作为依赖被升级:

glibc.x86_64 0:2.12-1.192.el6 glibc-common.x86_64 0:2.12-1.192.el6 libgcc.x86_64 0:4.4.7-17.el6 libgomp.x86_64 0:4.4.7-17.el6 tzdata.noarch 0:2016f-1.el6

完毕!

[root@localhost redis-2.8.17]# make

cd src && make all

make[1]: Entering directory `/usr/local/redis-2.8.17/src'

CC adlist.o

在包含自 adlist.c:34 的文件中:

zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录

zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"

make[1]: *** [adlist.o] 错误 1

make[1]: Leaving directory `/usr/local/redis-2.8.17/src'

make: *** [all] 错误 2

改成

[root@localhost redis-2.8.17]# make MALLOC=libc


cd src && make all

make[1]: Entering directory `/usr/local/redis-2.8.17/src'

rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-dump redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html

(cd ../deps && make distclean)

make[2]: Entering directory `/usr/local/redis-2.8.17/deps'

(cd hiredis && make clean) > /dev/null || true

(cd linenoise && make clean) > /dev/null || true

(cd lua && make clean) > /dev/null || true

(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true

(rm -f .make-*)

make[2]: Leaving directory `/usr/local/redis-2.8.17/deps'

(rm -f .make-*)

...........................................省略

CC redis-check-dump.o

LINK redis-check-dump

CC redis-check-aof.o

LINK redis-check-aof

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

make[1]: Leaving directory `/usr/local/redis-2.8.17/src'

[root@localhost redis-2.8.17]# ./src/redis-server &

[1] 2458

[root@localhost redis-2.8.17]# [2458] 17 Aug 15:18:10.509 # Warning: no config file specified, using the default config. In order to specify a config file use ./src/redis-server /path/to/redis.conf

[2458] 17 Aug 15:18:10.509 * Increased maximum number of open files to 10032 (it was originally set to 1024).

_._

_.-``__ ''-._

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

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

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

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

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

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

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

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

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

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

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

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

`-._ _.-'

`-.__.-'

[2458] 17 Aug 15:18:10.542 # Server started, Redis version 2.8.17

[2458] 17 Aug 15:18:10.543 # 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.

[2458] 17 Aug 15:18:10.543 * The server is now ready to accept connections on port 6379

[root@localhost redis-2.8.17]#

[root@localhost redis-2.8.17]# ./src/redis-cli

127.0.0.1:6379> set mysql biao

OK

127.0.0.1:6379> get mysql

"biao"

127.0.0.1:6379>

127.0.0.1:6379>

127.0.0.1:6379>

127.0.0.1:6379> exit

做成服务:

参考: 原创:http://www.myexception.cn/linux-unix/1963259.html

2、将一个程序添加到服务:

复制脚本redis_init_script到/etc/rc.d/init.d目录,并将其改名为redis(说明:/etc/rc.d/init.d/目录下的脚本在系统启动的时候某些指定脚本将被执行)

[root@localhost /]# cd /usr/local/redis-2.8.17/utils

[root@localhost utils]# cp redis_init_script /etc/rc.d/init.d/redis

将redis添加到注册服务:

[root@localhost utils]# chkconfig --add redis

redis 服务不支持 chkconfig

//报错:service redis does not support chkconfig

遇到这样情况需要修改脚本redis:

[root@localhost utils]# vim /etc/init.d/redis

#chkconfig: 2345 80 90 //新加内容

EXEC=/usr/local/redis-2.8.17/src/redis-server //修改后的内容

CLIEXEC=/usr/local/redis-2.8.17/src/redis-cli //修改后的内容

$EXEC $CONF & //redis开启的命令,以后台运行的方式执行,那个“&”,即是将服务

//转到后面运行的意思,否则启动服务时,redis服务将占据在前台,占用了主用户界面,导致其它//的命令执行不了

修改后执行如下命令:

[root@localhost utils]# $EXEC $CONF &

[1] 5461

[root@localhost utils]# chkconfig --add redis

[1]+ Done $EXEC $CONF

[root@localhost utils]# chkconfig --list redis

redis 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@localhost utils]# service redis restart

Please use start or stop as first argument

[root@localhost utils]# service redis start

Starting Redis server...

[5478] 17 Aug 15:52:26.808 # Fatal error, can't open config file '/etc/redis/6379.conf'

[root@localhost utils]#

[root@localhost utils]#

[root@localhost utils]# mkdir /etc/redis

[root@localhost utils]# cp /usr/local/redis-2.8.17/redis.conf /etc/re


readahead.conf redhat-lsb/ redhat-release redis/ request-key.conf request-key.d/ resolv.conf

[root@localhost utils]# cp /usr/local/redis-2.8.17/redis.conf /etc/red

redhat-lsb/ redhat-release redis/

[root@localhost utils]# cp /usr/local/redis-2.8.17/redis.conf /etc/redis/6379.conf

解决方法:

将redis配置文件拷贝到/etc/redis/${REDISPORT}.conf

[root@localhost utils]# mkdir /etc/redis

[root@localhost utils]# cp /usr/local/redis-2.8.17/redis.conf /etc/redis/6379.conf


这样,redis服务脚本指定的conf就存在了;在默认情况下,redis未启用认证,可以通过开启6379.conf的requirepass 指定一个验证密码;

修改/etc/redis/6379.conf,设置redis进程为后台守护进程,并指定一个密码:

[root@localhost /]# vim /etc/redis/6379.conf

daemonize yes //daemonize:是否以后台daemon方式运行

requirepass 20082009 //设置密码为20082009

设置完成后,可以添加注册服务:

[root@localhost /]# chkconfig --add redis

[root@localhost /]# service redis start


Starting Redis server...

查看是否启动成功:

[root@localhost /]# ps -aux|grep redis

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

root 5501 0.1 0.1 30908 1848 ? Ssl 15:58 0:00 /usr/local/redis-2.8.17/src/redis-server *:6379

root 5508 0.0 0.0 103260 824 pts/0 S+ 15:59 0:00 grep redis

3、调用redis-cli的命令进行简单操作(注意是否启动密码验证):

root@localhost /]# cd /usr/local/redis-2.8.17/src/

[root@localhost src]# ./redis-cli


127.0.0.1:6379> ping

(error) NOAUTH Authentication required.

127.0.0.1:6379> auth 12345678

OK

127.0.0.1:6379> ping

PONG

127.0.0.1:6379> get dubbo

(nil)

127.0.0.1:6379> set dubbo "alibb......"

OK

127.0.0.1:6379> get dubbo

"alibb......"

我是在虚拟机中装额在主机不能访问,网上说是防火墙:修改如下: 参考文章:http://blog.csdn.net/java1234321/article/details/47253969

[root@localhost /]# iptables -I INPUT -p tcp --dport 6379 -j ACCEPT

[root@localhost /]# service iptables save


iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]

用可视化工具访问Ok
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  redis安装 redis启动