Redis入门与进阶(二):Redis安装配置

目录

一、环境准备

二、Linux下安装

2.1、安装Redis

2.2、配置Redis 

2.3、启动Redis 

2.4、连接Redis 

2.5、关闭Redis 

2.6、卸载Redis


一、环境准备

Linux环境安装Redis必须先具备gcc编译环境

# getconf LONG_BIT
64
#  yum -y install gcc-c++
# gcc -v 

二、Linux下安装

2.1、安装Redis

# tar xzvf redis-7.2.3.tar.gz 
# cd redis-7.2.3
# make && make install
# ll  /usr/local/bin/
-rwxr-xr-x 1 root root  6900144 Jan 24 16:55 redis-benchmark
lrwxrwxrwx 1 root root       12 Jan 24 16:55 redis-check-aof -> redis-server
lrwxrwxrwx 1 root root       12 Jan 24 16:55 redis-check-rdb -> redis-server
-rwxr-xr-x 1 root root  7620392 Jan 24 16:55 redis-cli
lrwxrwxrwx 1 root root       12 Jan 24 16:55 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 15415400 Jan 24 16:55 redis-server

说明:

  • redis-benchmark:性能测试工具,服务启动后运行该命令
  • redis-check-aof:修复有问题的AOF文件,rdb和aof后面讲
  • redis-check-dump:修复有问题的dump.rdb文件
  • redis-cli:客户端,操作入口
  • redis-sentinel:redis集群使用
  • redis-server:Redis服务器启动命令

2.2、配置Redis 

# cp redis.conf  /etc/
# vim /etc/redis.conf 
1 默认daemonize no               改为  daemonize yes
2 默认protected-mode  yes        改为  protected-mode no
3 默认bind 127.0.0.1             改为  直接注释掉(默认bind 127.0.0.1只能本机访问)或改成本机IP地址,否则影响远程IP连接
4 添加redis密码                      改为 requirepass 你自己设置的密码

2.3、启动Redis 

# redis-server   /etc/redis.conf 
# ps -ef |grep redis 
root      98839      1  0 17:17 ?        00:00:00 redis-server *:6379
root      98879   6737  0 17:17 pts/1    00:00:00 grep --color=auto redis
# netstat -lnp |grep 6379
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      98839/redis-server  
tcp6       0      0 :::6379                 :::*                    LISTEN      98839/redis-server  

2.4、连接Redis 

# redis-cli 
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth Zqye@wid6
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> quit

# redis-cli  -a Zqye@wid6
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> ping 
PONG
127.0.0.1:6379> set k1 hellword
OK
127.0.0.1:6379> get k1
"hellword"

2.5、关闭Redis 

(1)单实例关闭

# redis-cli  -a Zqye@wid6  shutdown 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
[root@localhost redis-7.2.3]# ps -ef |grep redis |grep -v grep 

(2)多实例关闭

# redis-cli   -a Zqye@wid6    -p 6379  shutdown
# ps -ef |grep redis |grep -v grep 

2.6、卸载Redis

# redis-cli  -a Zqye@wid6  shutdown
# ls -l /usr/local/bin/redis-*
# rm -rf /usr/local/bin/redis-*

  • 15
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值