服务器环境
名称 | 版本 | 获取方式 |
---|---|---|
操作系统 | CentOS Linux release 7.9.2009 (Core) | CentOSVersionDownloads 根据需求选择对应版本 |
内存 | 8GB | 硬件基础配置 |
Redis | 6.0.16 | RedisVersionDownloads 根据需求选择对应版本 |
基础信息 | 开启时间同步、关闭selinux、关闭防火墙 | \ |
相关目录规划
redis_server: /etc/init.d/redis_6379
redis_config: /etc/redis/6379.conf
redis_data: /data/Redisdata 用于存放Redis数据库文件
安装过程
# 基本步骤如下
[root@BasicService ~]# yum install gcc
[root@BasicService ~]# mkdir Packages && cd Packages
[root@BasicService ~]# wget http://download.redis.io/releases/redis-6.0.16.tar.gz
[root@BasicService ~]# tar zxvf redis-6.0.16.tar.gz && cd redis-6.0.16
[root@BasicService ~]# make
[root@BasicService ~]# make install PREFIX=/usr/local/redis-6.0.16
# 详情可阅读redis-6.0.16/README.md
[root@BasicService ~]# cd utils
[root@BasicService ~]# ./install_server.sh
安装过程中可能出现的错误
[root@BasicService ~]# make
server.c: In function ‘main’:
server.c:5011:11: error: ‘struct redisServer’ has no member named ‘sentinel_mode’
server.sentinel_mode = checkForSentinelMode(argc,argv);
^
server.c:5028:15: error: ‘struct redisServer’ has no member named ‘sentinel_mode’
if (server.sentinel_mode) {
# 需要升级GCC版本
[root@BasicService ~]# yum -y install centos-release-scl
[root@BasicService ~]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@BasicService ~]# scl enable devtoolset-9 bash
# 注意:scl命令启用只是临时的,退出xshell或者重启就会恢复到原来的gcc版本。
# 如果要长期生效的话,执行如下:
[root@BasicService ~]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
# 清理上次make失败的文件和目录,再次知执行make
[root@BasicService ~]# make distclean
[root@BasicService ~]# make
[root@BasicService ~]# make install PREFIX=/usr/local/redis-6.0.16
将Redis添加到系统服务
# 配置redis的环境变量
[root@BasicService ~]# vi /etc/profile
# 增加如下内容
export REDIS_HOME=/usr/local/redis-6.0.16
export PATH=$PATH:$REDIS_HOME/bin
[root@BasicService ~]# source /etc/profile
# 执行注册服务脚本
[root@BasicService ~]# cd utils
# 首先注释如下信息,否则执行过程中报错
[root@BasicService ~]# vim 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@BasicService ~]# ./install_server.sh
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] /data/Redisdata
Selected default - /data/Redisdata
Please select the redis executable path [/usr/local/redis/bin/redis-server] /usr/local/redis-6.0.16/bin/redis-server
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /data/Redisdata
Executable : /usr/local/redis-6.0.16/bin/redis-server
Cli Executable : /usr/local/redis-6.0.16/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!
# 为了快速关闭redis服务,可以通过修改服务stop模块,执行kill
[root@BasicService ~]# vim /etc/init.d/redis_6379
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
/usr/bin/kill -9 `cat $PIDFILE`
#$CLIEXEC -p $REDISPORT shutdown
...
# 通过systemctl管理redis服务
[root@BasicService ~]# systemctl status redis_6379
[root@BasicService ~]# systemctl start redis_6379
[root@BasicService ~]# systemctl stop redis_6379
redis配置文件
[root@BasicService ~]# vim /etc/redis/6379.conf
# 开启守护进程
daemonize yes
# 去除bing的ip,否则无法使用远程连接
# bind 127.0.0.1
# 关闭保护模式,将protected-mode的yes改为no,也是开启远程连接。
protected-mode no
常用的Redis管理工具
RedisDesktopManager
标签:服务,部署,Redis,redis,server,6379,BasicService,6.0,root
From: https://blog.51cto.com/51inte/6149560