1、下载redis.tar.tz包
2、上传到linux服务器的/usr/local,并解压tar包
解压命令:tar -zxvf redis-6.2.6.tar.tz
结果:
3、安装gcc编译环境
由于redis是有c语言写的。所以需要c语言的编译环境
命令:yum install gcc-c++
结果:
4、进入/usr/local/redis-6.2.6/目录下
//进入到/usr/local/redis-6.2.6/ 文件目录下
[root@localhost mnt]# cd /usr/local/redis-6.2.6/
[root@localhost redis-6.2.6]# make //对解压后的文件进行编译
[root@localhost redis-6.2.6]# cd ./src //进入到 redis-6.2.6/src 文件目录下
[root@localhost src]# make install //进行redis安装
结果:
修改配置文件redis.conf
1、注释掉bind 127.0.0.1
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only on the
# IPv4 and IPv6 (if available) loopback interface addresses (this means Redis
# will only be able to accept client connections from the same host that it is
# running on).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1 -::1
2、修改protected-mode yes为protected-mode no
# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
# "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no
结果截图:
启动redis:
进入/usr/local/bin目录下,执行命令:redis-server /usr/local/redis-6.2.6/redis.conf
[root@hecs-221705 bin]# redis-server /usr/local/redis-6.2.6/redis.conf
java代码远程测试:
public class RedisTest {
public static void main(String[] arg){
Jedis jedis = new Jedis("ip地址",端口(6379));
String eee = jedis.ping();
System.out.println(eee);
}
}
输入结果为PONG则为成功。