# 安装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.没有密码