文章目录
安装
1.上传安装包进行解压
[root@node01 ~]# mkdir -p /opt/software
[root@node01 ~]# cd /opt/software
[root@node01 software]# rz
z waiting to receive.**B0100000023be50
[root@node01 software]# ls
redis redis-6.2.7 tar.7.2.redis-6.gz
[root@node01 software]# tar zxf tar.7.2.redis-6.gz
2.编译安装
安装需要的C插件
[root@node01 ~]# yum -y install gcc tcl
编译Redis
进入/software/cd /software/redis-6.2.7目录中,编译redis。
[root@node01 ~]# cd /opt/software/redis-6.2.7
[root@node01 redis-6.2.7]# make
创建安装目录安装Redis
#创建安装目录
[root@node01 ~]# mkdir -p /opt/software/redis
#进入redis编译目录,安装redis
[root@node01 ~]# cd /opt/software/redis-6.2.7
[root@node01 redis-6.2.7]# make PREFIX=/opt/software/redis install
注意:现在就可以使用redis了,进入/software/redis/bin下,就可以执行redis命令。
3.开机自启动以及脚本启动
将redis-server链接到/usr/local/bin/目录下,后期加入系统服务时避免报错
[root@node01 ~]# ln -sf /opt/software/redis-6.2.7/src/redis-server /usr/local/bin/
修改服务安装
配置install_server.sh
[root@node01 ~]# cd /opt/software/redis-6.2.7/utils/
[root@node01 ~]# vi install_server.sh
注释掉以下部分
#_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@node01 ~]# ./install_server.sh
配置环境变量
[root@node01 ~]# vim /etc/profile
export REDIS_HOME=/software/redis
export PATH=$PATH:$REDIS_HOME/bin
#使环境变量生效
[root@node01 ~]# source /etc/profile
启动停止redis服务
[root@node01 utils]# systemctl status redisd
● redisd.service - LSB: start and stop redis_6379
Loaded: loaded (/etc/rc.d/init.d/redisd; bad; vendor preset: disabled)
Active: active (running) since Thu 2023-05-11 23:05:22 PDT; 29min ago
Docs: man:systemd-sysv-generator(8)
Process: 6532 ExecStart=/etc/rc.d/init.d/redisd start (code=exited, status=0/SUCCESS)
Tasks: 5
CGroup: /system.slice/redisd.service
└─6634 /usr/local/bin/redis-server 192.168.5.130:6379
May 11 23:05:21 node01 systemd[1]: Starting LSB: start and stop redis_6379...
May 11 23:05:21 node01 redisd[6532]: Starting Redis server...
May 11 23:05:22 node01 systemd[1]: Started LSB: start and stop redis_6379.
4.需要修改配置文件
4.1 配置是否以守护进程运行
By default Redis does not run as a daemon. Use ‘yes’ if you need it.
Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
When Redis is supervised by upstart or systemd, this parameter has no impact.
4.2 修改绑定ip
bind 192.168.5.130 # listens on two specific IPv4 addresses
bind 127.0.0.1 ::1 # listens on loopback IPv4 and IPv6