cd /opt && tar -xvf redis-6.0.9.tar.gz; cd /opt/redis-6.0.9
3. 安装依赖
yum -y install cmake gcc jemalloc-devel
4. 编译安装
make
# 出现以下报错
···
server.c:***:**: error: 'struct redisServer' has no member named '***'
···
# 参考以下文档 确认是gcc版本问题 https://blog.csdn.net/weixin_45520603/article/details/108020571
yum -y install centos-release-scl && yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils && scl enable devtoolset-9 bash
gcc -v
# 编译完毕后提示以下信息,并按照提示进入./src 执行make test 失败
···
You need tcl 8.5 or newer in order to run the Redis test
# 参考以下文档https://blog.csdn.net/zjh_746140129/article/details/80807393 安装tcl
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz -P /opt
cd /opt && tar -zxvf tcl8.6.1-src.tar.gz
cd ./tcl8.6.1/unix && ./configue; make && make install
# 执行make test 通过
···
\o/ All tests passed without errors!
Cleanup: may take some time... OK
# 启动服务,验证
./redis-server
./redis-cli
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379>
# 拷贝配置文件
cd /usr/local/redis/etc && echo 'redis6380.conf redis6381.conf' | xargs -n 1 cp redis6379.conf
# 修改配置文件参数
···
port 6379
logfile “/data/redis6379/logs/redis.log”
dir /data/redis6379/data/
pidfile /data/redis6379/redis.pid
#启动6380,6381端口,连接测试
redis-server ./redis6380.conf && redis-server ./redis6381.conf
[root@lqy etc]# redis-cli -p 6380 -a 'redis6380'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6380> set k1 v1
OK
127.0.0.1:6380> get k1
"v1"
127.0.0.1:6380> exit
[root@lqy etc]# redis-cli -p 6381 -a 'redis6381'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> set k1 v1
OK
127.0.0.1:6381> get k1
"v1"
7. 编写启动脚本
#!/bin/sh
#实例 ./redis start 6379 ; ./redis stop 6380
#redis服务器监听的端口
REDISPORT=$2
#服务端所处位置
EXEC=/usr/local/redis/bin/redis-server
#客户端位置
CLIEXEC=/usr/local/redis/bin/redis-cli
#redis的PID文件位置,需要修改
PIDFILE=/data/redis$2/redis.pid
#redis的配置文件位置,需将${REDISPORT}修改为文件名
CONF="/usr/local/redis/etc/redis${REDISPORT}.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "PID: {$PID}Stopping ..."
$CLIEXEC -p $REDISPORT -a redis shutdown 2> /dev/null
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac