linux线上搭建redis并解决无法连接redis的问题

一、引言

    在某次线上回归测试中,突然发现一台服务器过期【奇葩吧】,该服务器上面的redis服务不可用,于是临时搭建一个redis服务。

二、redis搭建

    环境:CentOS7.0 和 redis-4.0.2

1、安装前准备

    redis 编译依赖 gcc 环境

[root@******* ~]# yum install gcc-c++

2、安装过程

    依次对应:获取安装文件、解压文件、进入目录、编译安装、进入启动目录

[root@****** ~]# wget http://download.redis.io/releases/redis-4.0.2.tar.gz
[root@******~]# tar -zxvf redis-4.0.2.tar.gz
[root@******~]# cd redis-4.0.2
[root@****** redis-4.0.2]# make
[root@****** redis-4.0.2]# make install PREFIX=/usr/local/redis-4
[root@****** redis-4.0.2]# cd /usr/local/redis-4/bin/

3、需要注意事件(以下步骤紧接第二步骤)

[root@****** bin]# cp /root/redis-4.0.2/redis.conf ./

    说明:为了方便管理,将解压后的redis.conf 拷贝一份到 /usr/local/redis-4/bin/ 目录下,切勿直接操作原文件,避免修改失败可以还原配置

[root@****** bin]# vim redis.conf

    说明:修改 redis.conf 文件,将 daemonize no 改成 daemonize yes ,表示开启守护进程。 # requirepass foobared 然后去掉注释,这个foobared改为自己的密码,表示设置密码。bind 127.0.0.1 这个是默认只有本机访问,把这个注释掉,否则部署到其它服务器的服务将无法访问该redis服务。

[root@****** bin]# ./redis-server redis.conf

    说明:启动 redis 服务。

[root@****** bin]# ps -ef|grep redis
root     12233     1  0 12:21 ?        00:00:09 ./redis-server *:6379
root     16701  8233  0 17:25 pts/7    00:00:00 grep --color=auto redis

    说明:查看redis服务启动状态。

三、结束语

    此次搭建过程中,采坑主要是没有把bind 127.0.0.1 这个注释掉,比较坑。

原创文章 55 获赞 76 访问量 17万+

猜你喜欢

转载自blog.csdn.net/cool_summer_moon/article/details/86692150