cd /root //进入用户目录
mkdir downfiles // 创建目录downfiles
cd downfiles // 进入目录
wget http://download.redis.io/releases/redis-6.0.6.tar.gz //下载redis
tar xzf redis-6.0.6.tar.gz //解压
cd redis-6.0.6 // 进入目录
make PREFIX=/usr/software/redis install // 编译到指定目录
cd /usr/software/redis // 进入目录
./bin/redis-server // 启动测试 安装成功
cd bin //进入bin
mkdir conf //创建文件
mv /root/downfiles/redis-6.0.6/redis.conf /usr/software/redis/bin/conf/redis.conf //创建redis.config
vi redis.conf //修改redis.conf文件 按住esc 输入i 回车 //进入编辑 修改ip 0.0.0.0 //外部能访问 按esc 输入:wq 回车 //保存
按配置文件启动
./redis-server ./conf/redis/conf
设置成服务
firewall-cmd --add-port=6379/tcp --permanent //防火墙添加出入站规则 外部访问
service firewalld restart //重启防火墙
cd /etc/init.d //进入目录
touch autostart.sh //新建文件
编辑脚本 vim autostart.sh
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO
REDISPORT=6379
EXEC=/usr/software/redis/bin/redis-server
CLIEXEC=/usr/software/redis/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/software/redis/bin/conf/redis.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 "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
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
注意
1 service autostart.sh start //测试 2 找不到 /etc/init.d/ autostart.sh 3 需要 cd /etc/init.d/ 4 touch auyostart.sh
自启
chmod +x auotstart.sh //赋予执行权限
chkconfig --add autostart.sh //添加服务
chkconfig autostart.sh on //自启

浙公网安备 33010602011771号