单节点部署redis

第一步:下载redis安装包(整个安装流程建议在root用户下完成)

wget http://download.redis.io/releases/redis-5.0.5.tar.gz

[root@hadoop local]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
--2017-12-13 12:35:12-- http://download.redis.io/releases/redis-5.0.5.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1723533 (1.6M) [application/x-gzip]
Saving to: ‘redis-5.0.5.tar.gz’

100%[==========================================================================================================>] 1,723,533 608KB/s in 2.8s

2017-12-13 12:35:15 (608 KB/s) - ‘redis-5.0.5.tar.gz’ saved [1723533/1723533]

第二步:解压压缩包

tar -zxvf redis-5.0.5.tar.gz

[root@hadoop local]# tar -zxvf redis-5.0.5.tar.gz

第三步:yum安装gcc依赖

yum install gcc

[root@hadoop local]# yum install gcc

遇到选择,输入y即可

第四步:跳转到redis解压目录下

cd redis-5.0.5

[root@hadoop local]# cd redis-5.0.5

第五步:编译安装

make MALLOC=libc  

[root@hadoop redis-5.0.5]# make MALLOC=libc

cd src && make install

[root@hadoop redis-5.0.5]# cd src && make install
CC Makefile.dep

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

INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install

第六步:修改配置文件

修改redis.conf

# 关闭保护模式
protected-mode no
# 设置端口号
prot 16379
# 允许后台运行
daemonize yes
# 日志文件保存位置
logfile /home/hadoop/tmp/redis.log

第七步:设置redis服务

1、在/etc目录下新建redis目录

mkdir redis

[root@hadoop etc]# mkdir redis

2、将/home/hadoop/app/redis-5.0.5/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf  

[root@hadoop redis]# cp /home/hadoop/app/redis-5.0.5/redis.conf /etc/redis/6379.conf

3、将redis的启动脚本复制一份放到/etc/init.d目录下

[root@hadoop init.d]# cp /home/hadoop/app/redis-5.0.5/utils/redis_init_script /etc/init.d/redisd

4、设置redis开机自启动

先切换到/etc/init.d目录下

然后执行自启命令

[root@hadoop init.d]# chkconfig redisd on
service redisd does not support chkconfig

看结果是redisd不支持chkconfig

解决方法:

使用vim编辑redisd文件,在第一行加入如下两行注释,保存退出

# chkconfig:   2345 90 10
# description: Redis is a persistent key-value database

注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。

再次执行开机自启命令,成功

[root@hadoop init.d]# chkconfig redisd on

现在可以直接已服务的形式启动和关闭redis了

启动:

service redisd start 

[root@hadoop ~]# service redisd start
Starting Redis server...
2288:C 13 Dec 13:51:38.087 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2288:C 13 Dec 13:51:38.087 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=2288, just started
2288:C 13 Dec 13:51:38.087 # Configuration loaded

关闭:

方法1:service redisd stop

[root@hadoop ~]# service redisd stop
Stopping ...
Redis stopped

方法2:redis-cli SHUTDOWN

如果出现如下问题:

[root@hadoop ~]# service redisd start
/var/run/redis_6379.pid exists, process is already running or crashed

可参考资料:http://blog.csdn.net/luozhonghua2014/article/details/54649295

开启客户端

# 本机启动
./redis-cli
# 指定端口和主机启动
./redis-cli -p 16379 -h hadoop
Author: Tunan
Link: http://yerias.github.io/2020/04/23/redis/1/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.