1. 下载压缩包
wget https://download.redis.io/releases/redis-6.2.14.tar.gz
2. 解压缩并且编译安装
tar -zxvf ./redis-6.2.14.tar.gz
#加入参数 -j 4 ->表示用4个核心编译,加快编译速度
make
#将编译完成的可执行文件添加到启动目录里 /usr/local/bin/目录下有redis可执行文件了
make install
3. 修改Redis配置
打开redis.conf配置文件--建议通读文件
修改1. bind 127.0.0.1 -> bind 0.0.0.0或将其注释 (允许所有IP访问)
修改2. daemonize no -> daemonize yes (允许后台运行)
修改3. #requirepass foobared -> requirepass 123456 (修改密码)
4. 安装服务
[root@iZ2ze2kc6y950jcv42sw18Z 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!
#出错了,有两种解决办法,一种是把redis安装成服务,一种是注释校验代码
#这里直接注释校验代码
vi ./install_server.sh
#使用pwd命令查看路径信息
#提前准备好以下路径
/000/redis/redis.conf
/000/redis/redis.log
/000/redis/data
执行安装文件
[root@iZ2ze2kc6y950jcv42sw18Z 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] /000/redis/redis.conf
Please select the redis log file name [/var/log/redis_6379.log] /000/redis/redis.log
Please select the data directory for this instance [/var/lib/redis/6379] /000/redis/data
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /000/redis/redis.conf
Log file : /000/redis/redis.log
Data dir : /000/redis/data
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!
5. 启动服务
[root@iZ2ze2kc6y950jcv42sw18Z utils]# systemctl status redis
Unit redis.service could not be found.
[root@iZ2ze2kc6y950jcv42sw18Z utils]# systemctl status redis_6379
● redis_6379.service - LSB: start and stop redis_6379
Loaded: loaded (/etc/rc.d/init.d/redis_6379; bad; vendor preset: disabled)
Active: inactive (dead)
Docs: man:systemd-sysv-generator(8)
[root@iZ2ze2kc6y950jcv42sw18Z utils]# systemctl start redis
Failed to start redis.service: Unit not found.
[root@iZ2ze2kc6y950jcv42sw18Z utils]# systemctl start redis_6379
[root@iZ2ze2kc6y950jcv42sw18Z utils]# systemctl status redis_6379
● redis_6379.service - LSB: start and stop redis_6379
Loaded: loaded (/etc/rc.d/init.d/redis_6379; bad; vendor preset: disabled)
Active: active (exited) since Thu 2024-06-20 18:10:50 CST; 3s ago
Docs: man:systemd-sysv-generator(8)
Process: 15374 ExecStart=/etc/rc.d/init.d/redis_6379 start (code=exited, status=0/SUCCESS)
Jun 20 18:10:50 iZ2ze2kc6y950jcv42sw18Z systemd[1]: Starting LSB: start and stop redis_6379...
Jun 20 18:10:50 iZ2ze2kc6y950jcv42sw18Z redis_6379[15374]: /var/run/redis_6379.pid exists, process is already running or crashed
Jun 20 18:10:50 iZ2ze2kc6y950jcv42sw18Z systemd[1]: Started LSB: start and stop redis_6379.
7. 查看系统服务配置
[root@iZ2ze2kc6y950jcv42sw18Z utils]# vi /etc/init.d/redis_6379
#!/bin/sh
#Configurations injected by install_server below....
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/000/redis/redis.conf"
REDISPORT="6379"