centos 7 redis单机版安装部署(安装版本6.2.7)
1.下载redis安装包,并将其上传到服务器中
2.将 Redis 安装包解压到 /usr/local中
tar zxvf /root/redis-6.2.7.tar.gz -C /usr/local/
3.将redis-6.2.7重命名为redis
mv redis-6.2.7/ redis
4.编译并安装
cd redis/
make && make install
5.进入/usr/local/redis目录下utils目录下。执行安装脚本,安装redis并设置为系统服务并后台启动(使用默认配置,有需要按需更改)
[root@VM-12-12-centos utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
如安装出现上述提示,需要将install_server.sh中几行注释掉。具体如下
#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
# echo "This systems seems to use systemd."
# echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
# exit 1
#fi
注释完成后继续执行安装脚本(使用默认配置直接全部回车即可)
[root@VM-12-12-centos utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
6.查看redis启动情况
[root@VM-12-12-centos redis]# systemctl status redis_6379.service
● redis_6379.service - LSB: start and stop redis_6379
Loaded: loaded (/etc/rc.d/init.d/redis_6379; bad; vendor preset: disabled)
Active: active (running) since Wed 2022-07-27 10:16:11 CST; 9s ago
Docs: man:systemd-sysv-generator(8)
Process: 11866 ExecStop=/etc/rc.d/init.d/redis_6379 stop (code=exited, status=0/SUCCESS)
Process: 11870 ExecStart=/etc/rc.d/init.d/redis_6379 start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/redis_6379.service
└─11872 /usr/local/bin/redis-server 0.0.0.0:6379
Jul 27 10:16:11 VM-12-12-centos systemd[1]: Starting LSB: start and stop redis_6379...
Jul 27 10:16:11 VM-12-12-centos redis_6379[11870]: Starting Redis server...
Jul 27 10:16:11 VM-12-12-centos systemd[1]: Started LSB: start and stop redis_6379.
7.当前只能本地访问,无法远程访问。需要修改redis配置文件(配置文件路径为执行./install_server.sh脚本时,提示的文件路径)
vi /etc/redis/6379.conf
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0
# 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
systemctl restart redis_6379.service
###如需设置密码访问,修改配置文件中requirepass部分。如requirepass 123设置密码为123
8.通过客户端命令测试
[root@VM-12-12-centos redis]# redis-cli
127.0.0.1:6379> set test 456
OK
127.0.0.1:6379> get test
"456"
127.0.0.1:6379>