您的位置 首页 redis

redis 安装 redis-6.2.10(生产)

redis安装  jenkins上有测试环境- 查看版本

1.2 Redis服务安装部署

1.2.1 缓存服务安装部署

缓存服务下载解压:

cd /usr/local/
 wget https://download.redis.io/releases/redis-6.2.10.tar.gz

tar xf redis-6.2.10.tar.gz
ln -s redis-6.2.10 redis
ll -d redis
 lrwxrwxrwx 1 root root 12 2月  21 01:45 redis -> redis-6.2.10
 
-- 部署redis服务的虚拟主机尽量将内存空间调大,建议调整为4G;

 

缓存服务安装部署:

yum install -y gcc automake autoconf libtool make
cd redis
make

 

配置服务环境变量:

 vim /etc/profile
 export PATH=/usr/local/redis/src:$PATH

-- 在Redis子目录src中存储了缓存服务应用的相关命令信息
source /etc/profile

简单启动服务测试:

redis-server &
netstat -lntup|grep redis

 

缓存服务登录操作:

 [root@master redis]# redis-cli
 127.0.0.1:6379> set a 1
 OK
 127.0.0.1:6379> get a
 "1"
 -- 测试是否正常登录缓存服务,进行简单缓存服务key-values数据类型设置

安全:

1.redis 配置成非任意IP访问,或者要求使用password

2.rename-command CONFIG xxx  将config指令修改,这样黑客就不知道真正的config指令了。

3.redis 不要用root启动,如果root启动的话,我们就看不到这个错误了,黑客会成功入侵服务器。

三、 加载指定缓存服务配置文件,进行服务启动

redis-server /data/6379/redis.conf

 

redis.conf

mkdir -p /data/6379

 

cat >/data/6379/redis.conf<<EOF
daemonize yes

port 6379

logfile /data/6379/redis.log

dir /data/6379

dbfilename dump.rdb

EOF

解释:


daemonize yes
-- 表示定义服务程序在后台以守护进程方式运行
port 6379
-- 表示定义服务的默认端口
logfile /data/6379/redis.log
-- 表示服务运行日志存放路径
dir /data/6379
-- 表示定义数据目录路径,用于持久化应用时存储数据
dbfilename dump.rdb
-- 表示持久化存储的数据文件名称

 

设置密码:

requirepass 123456
-- 设置远程连接认证密码信息

 

redis  查看版本:

终端

redis-cli -p 6479 -a root

输入

INFO server

 

1.3 Redis服务基础管理操作

缓存服务应用配置文件:

 [root@master redis]# redis-cli shutdown
 23667:M 21 Feb 2021 02:21:00.018 # User requested shutdown...
 23667:M 21 Feb 2021 02:21:00.018 * Saving the final RDB snapshot before exiting.
 23667:M 21 Feb 2021 02:21:00.019 * DB saved on disk
 23667:M 21 Feb 2021 02:21:00.019 # Redis is now ready to exit, bye bye...
 [1]+  完成                  redis-server(工作目录:/usr/local/redis/src)
 (当前工作目录:/usr/local/redis)
 -- 关闭原有启动的redis服务程序
 
 [root@master redis]# redis-server /data/6379/redis.conf
 [root@master redis]# netstat -lntup|grep redis
 tcp         0      0 0.0.0.0:6379            0.0.0.0:*          LISTEN      23706/redis-server
 tcp6       0      0 :::6379                     :::*                    LISTEN      23706/redis-server
 -- 加载指定缓存服务配置文件,进行服务启动
 
 [root@master redis]# redis-cli
 127.0.0.1:6379> set name xiaoQ
 OK
 127.0.0.1:6379> get name
 "xiaoQ"
 -- 进行简单缓存服务配置操作测试

1.3.2 缓存服务安全配置应用

Redis默认开启了安全保护模式,只允许本地回环地址登录并访问缓存服务数据库,无法实现远程连接缓存服务数据库;

需要禁用protected-mode模式,才能实现redis服务的远程连接;

 # Redis处于protected-mode默认开启的状态
 [root@master redis]# redis-cli -h 192.168.30.101 -p 6379
 192.168.30.101:6379> set a 1
 (error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 
 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 
 -- 可以执行命令关闭protected-mode,执行的命令为CONFIG SET protected-mode no
 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 
 -- 可以编写配置文件关闭保护模式,并设置protected mode option to 'no'
 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 
 -- 可以在启动服务时,添加protected-mode no参数,实现关闭protected-mode
 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
 -- 可以设置地址绑定或认证密码方式,在不关闭保护模式情况下,实现外网远程连接redis服务;
 -- 进行key-values设置失败,显示redis已经运行了protected-mode,并且处于启用状态
 192.168.30.101:6379> get name
 Error: Connection reset by peer
 -- 查看key-values设置失败,由于redis已经运行了protected-mode,并且处于启用状态
 
 # Redis处于protected-mode手动关闭的状态
 [root@master redis]# vim /data/6379/redis.conf
 .. 省略部分信息 ..
 bind 192.168.30.101 127.0.0.1
 -- 设置监听本地远程连接地址和本地回环地址,实现地址bind绑定
 
 [root@master redis]# vim /data/6379/redis.conf
 .. 省略部分信息 ..
 requirepass 123456
 -- 设置远程连接认证密码信息
 
 [root@master redis]# redis-cli shutdown
 [root@master redis]# redis-server /data/6379/redis.conf
 -- 进行监听地址和密码信息设置后,需要重启redis服务程序
 
 [root@master redis]# redis-cli
 127.0.0.1:6379> set a 1
 (error) NOAUTH Authentication required.
 -- 此时本地登录缓存服务也需要进行密码验证才可以
 
 [root@master redis]# redis-cli -a 123456
 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
 127.0.0.1:6379> set a 1
 OK
 127.0.0.1:6379> get a
 "1"
 或者
 [root@master redis]# redis-cli
 127.0.0.1:6379> auth 123456
 -- 此时本地登录缓存服务器输入密码信息后,既可以进行缓存服务管理操作

1.3.3 缓存服务查看修改配置

对于Redis缓存服务可以进行在线的查看配置和修改配置信息,无需对缓存服务进行重启操作:

 # 在线查看缓存服务所有配置信息
 [root@master redis]# redis-cli -h 192.168.30.101 -p 6379 -a 123456
 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
 192.168.30.101:6379> CONFIG GET *
   1) "rdbchecksum"
   2) "yes"
   3) "daemonize"
   4) "yes"
   5) "io-threads-do-reads"
   6) "no"
   7) "lua-replicate-commands"
 ... 省略部分信息
 291) "notify-keyspace-events"
 292) ""
 293) "bind"
 294) "192.168.30.101 127.0.0.1"
 295) "oom-score-adj-values"
 296) "0 200 800"
 -- 默认redis服务总共有148个配置信息(针对6.2.10版本)
 
 192.168.30.101:6379> CONFIG GET requirepass
 1) "requirepass"
 2) "123456"
 192.168.30.101:6379> CONFIG GET requir*
 1) "requirepass"
 2) "123456"
 -- 单独指定某个配置信息进行查询,针对缓存服务登录密码信息查询
 
 # 在线修改密码信息,避免重启服务
 192.168.30.101:6379> CONFIG SET requirepass 123
 OK
 192.168.30.101:6379> CONFIG GET requirepass
 1) "requirepass"
 2) "123"
 [root@master redis]# redis-cli -h 192.168.30.101 -p 6379 -a 123456
 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
 AUTH failed: WRONGPASS invalid username-password pair or user is disabled.
 -- 在线修改缓存服务配置信息后,最好还要在配置文件中实现永久修改

1.3.4 缓存服务实现数据存储

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章