CentOS6下 安装Redis

Posted by 老沙
8月 12 2017

一 安装

1) 下载redis安装包
官网http://redis.io

我下载的是redis-4.0.1

解压之

make  完全后会让你动行make test 这时会用到tcl包,如果没有tcl运行make test

会报如下错误:

[root@localhost redis-4.0.1]# make test
cd src && make test
make[1]: Entering directory `/root/redis/redis-4.0.1/src’
CC Makefile.dep
make[1]: Leaving directory `/root/redis/redis-4.0.1/src’
make[1]: Entering directory `/root/redis/redis-4.0.1/src’
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] 错误 1
make[1]: Leaving directory `/root/redis/redis-4.0.1/src’
make: *** [test] 错误 2

那就要安装TCL

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xzvf tcl8.6.1-src.tar.gz
cd tcl8.6.1/unix/
sudo ./configure
sudo make
sudo make install

就完成了,再运行进入redis目录,运行make test,如果没有问题最后会是

54 seconds – unit/aofrw
83 seconds – integration/replication
91 seconds – unit/type/list-3
101 seconds – integration/replication-psync

\o/ All tests passed without errors!

Cleanup: may take some time… OK
make[1]: Leaving directory `/root/redis/redis-4.0.1/src’

然后安装redis命令 make install

redis-server –v (查看版本命令)

[root@localhost redis-4.0.1]# redis-server -v
Redis server v=4.0.1 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=61447d85dd649aab

到此安装就完成了。

1 下面是配置了 创建配置文件目录,dump file 目录,进程pid目录,log目录等

配置文件一般放在/etc/下,创建redis目录

mkdir -p /var/redis/data /var/redis/log /var/redis/run

2 修改配置文件,配置参数

首先拷贝解压包下的redis.conf文件至/etc/redis

mkdir -p /etc/redis;cp redis.conf /etc/redis/

3 打开配置文件

vi /etc/redis/redis.conf

几个重要的地方:

修改端口(默认6379)

port 6379

修改pid目录

pidfile /var/redis/run/redis_6379.pid

修改dump目录

dir /var/redis/data

修改log存储目录

logfile /var/redis/log/redis.log

后台运行

daemonize yes

持久化

默认rdb,可选择是否开启aof,若开启,修改配置文件appendonly

保存退出

:wq

然后可以启动redis看看

redis-server /etc/redis/redis.conf

[root@localhost redis-4.0.1]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 31264/redis-server

[root@localhost redis-4.0.1]# redis-cli
127.0.0.1:6379> help
redis-cli 4.0.1
To get help about Redis commands type:
“help @<group>” to get a list of commands in <group>
“help <command>” for help on <command>
“help <tab>” to get a list of possible help topics
“quit” to exit

To set redis-cli preferences:
“:set hints” enable online hints
“:set nohints” disable online hints
Set your preferences in ~/.redisclirc
127.0.0.1:6379> quit

接下来要配置一下启动脚本

cp utils/redis_init_script /etc/init.d/redisd

 

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/redis/run/redis_${REDISPORT}.pid
CONF=”/etc/redis/redis.conf”

[root@localhost redis-4.0.1]# chmod 755 /etc/init.d/redisd

然后把/etc/init.d/redisd start加入到/etc/rc.local里,开机自启动

一切就都OK了

Trackback URL for this entry