编译安装redis

# 安装gcc套装
 yum -y install gcc glibc glibc-kernheaders  glibc-common glibc-devel make 
 
# 升级gcc
 yum -y install centos-release-scl
 yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
 
 #开启开发工具包,并在bash环境中生效,临时的
 scl enable devtoolset-9 bash
 
 #永久开启开发工具包
 echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile 

bash环境变量加载顺序:/etc/profile开机的时候加载;用户登录加载.bash——profile;每执行一次bash加载一次.bashrc(这个影响范围小,优先级最高)

#安装redis
  25  wget http://download.redis.io/releases/redis-6.0.5.tar.gz
  26  tar -zxvf redis-6.0.5.tar.gz -C /usr/local
  27  cd /usr/local/redis-6.0.5
  28  make
  29   make all
  
  #启动redis,出现下面这个图案表示成功
  30  cd /usr/local/redis-6.0.5
  31  ./src/redis-server #用这个命令表示在前台执行,不能退出,退出之后,这个服务就会关掉
               _._                                                  
          _.-``__ ''-._                                             
     _.-``    `.  `_.  ''-._           Redis 6.0.5 (00000000/0) 64 bit
 .-`` .-```.  ```\/    _.,_ ''-._                                   
(    '      ,       .-`  | `,    )     Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
|    `-._   `._    /     _.-'    |     PID: 5525
 `-._    `-._  `-./  _.-'    _.-'                                   
|`-._`-._    `-.__.-'    _.-'_.-'|                                  
|    `-._`-._        _.-'_.-'    |           http://redis.io        
 `-._    `-._`-.__.-'_.-'    _.-'                                   
|`-._`-._    `-.__.-'    _.-'_.-'|                                  
|    `-._`-._        _.-'_.-'    |                                  
 `-._    `-._`-.__.-'_.-'    _.-'                                   
     `-._    `-.__.-'    _.-'                                       
         `-._        _.-'                                           
             `-.__.-'                  

#ctrl+c结束上面的命令之后,redis服务关闭,端口6379没有启动
  32  ss -tnlp
 State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128          *:22                       *:*                   users:(("sshd",pid=891,fd=3))
LISTEN     0      100    127.0.0.1:25                       *:*                   users:(("master",pid=989,fd=13))
LISTEN     0      128         :::22                      :::*                   users:(("sshd",pid=891,fd=4))
LISTEN     0      100        ::1:25                      :::*                   users:(("master",pid=989,fd=14))

  
  33   ./src/redis-cli --version
  redis-cli 6.0.5

  34  ./src/redis-cli --version
  Redis server v=6.0.5 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=a7396f36430dde21

#以守护进程运行 即可解决以上问题



36  vim redis.conf    
daemonize no 改为 daemonize yes

#启动服务并指定一下配置文件
37  ./src/redis-server /usr/local/redis-6.0.5/redis.conf
5540:C 14 Sep 2020 20:09:24.641 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5540:C 14 Sep 2020 20:09:24.641 # Redis version=6.0.5, bits=64, commit=00000000, modified=0, pid=5540, just started
5540:C 14 Sep 2020 20:09:24.641 # Configuration loaded

#6379端口启动成功
38  ss -tnlp
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128    127.0.0.1:6379                     *:*                   users:(("redis-server",pid=5541,fd=6))
LISTEN     0      128          *:22                       *:*                   users:(("sshd",pid=891,fd=3))
LISTEN     0      100    127.0.0.1:25                       *:*                   users:(("master",pid=989,fd=13))
LISTEN     0      128         :::22                      :::*                   users:(("sshd",pid=891,fd=4))
LISTEN     0      100        ::1:25                      :::*                   users:(("master",pid=989,fd=14)

#测试

   45  ./src/redis-cli
 127.0.0.1:6379> set name aaa
OK
127.0.0.1:6379> get name
"aaa"
127.0.0.1:6379> exit

#打开注释,设置密码为123

  46  vim redis.conf 
  requirepass 123        

#关闭redis必须kill掉

   53  ps -ef |grep redis
   root      5557     1  0 20:10 ?        00:00:01 ./src/redis-server 127.0.0.1:6379
root      5576  1272  0 20:20 pts/0    00:00:00 grep --color=auto redis
   54  kill -9 5557
   55  ps -ef |grep redis
    root      5578  1272  0 20:21 pts/0    00:00:00 grep --color=auto redis
   56  ss -tnlp
   State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128          *:22                       *:*                   users:(("sshd",pid=891,fd=3))
LISTEN     0      100    127.0.0.1:25                       *:*                   users:(("master",pid=989,fd=13))
LISTEN     0      128         :::22                      :::*                   users:(("sshd",pid=891,fd=4))
LISTEN     0      100        ::1:25                      :::*                   users:(("master",pid=989,fd=14))

#设置完密码,重启服务之后可以发现进行操作时会报错,需要auth 123进行一下身份认证,才可以进行操作


   59  ./src/redis-server /usr/local/redis-6.0.5/redis.conf
   60  ./src/redis-cli
127.0.0.1:6379> get name
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123
OK

1、修改配置文件将bind 127.0.0.1注释掉,否则数据库只有本机能够使用 或者 修改为 0.0.0.0
2、protected-mode no # 把保护模式的yes改为no,否则会阻止远程访问 但是必须满足两个条件

  • 1.监听地址必须是0.0.0.0 ;
  • 2.没有密码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值