Redis安装配置

Redis

下载安装

$ cd /usr/local/
$ mkdir redis
$ cd redis/
$ wget https://download.redis.io/releases/redis-6.2.3.tar.gz $ tar xzf redis-6.2.3.tar.gz $ cd redis-6.2.3 $ make

配置

Redis配置文件

$ vi /usr/local/redis/redis-6.2.3/redis.conf

# 去掉限制本机访问
# bind 127.0.0.1 -::1

# 开启守护线程模式
daemonize yes

# 设置密码为123456
# requirepass 123456

开启6379端口

$ firewall-cmd --zone=public --add-port=6379/tcp --permanent
$ service firewalld restart

添加到系统服务并开机自启

创建脚本文件

$ vim /etc/init.d/redis
#!/bin/bash
#chkconfig: 2345 90 10
#description: Start and Stop redis

REDISPORT=6379
EXEC=/usr/local/redis/redis-6.2.3/src/redis-server
CLIEXEC=/usr/local/redis/redis-6.2.3/src/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/redis-6.2.3/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
        ;;
    restart)
        "$0" stop
        sleep 3
        "$0" start
        ;;
    *)
        echo "Please use start or stop or restart as first argument"
        ;;
esac
View Code

授权

chmod +x /etc/init.d/redis

把脚本添加到系统服务列表并设置自启动

chkconfig --add redis
chkconfig redis on
chkconfig --list

 常见异常

1.make时编译报错cc: command not found

安装 gcc,之后删除redis包再重新解压,再make

yum install gcc

2.server.c:xxxx:xx: error: ‘xxxxxxxx’ has no member named ‘xxxxx’

检查 gcc 版本

#查看gcc的版本是否在 5.3以上,centos7默认是4.8.5.我这里的就是4.8.5
gcc -v

解决方案

#升级到 5.3及以上版本
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash

注意:scl命令启用只是临时的,推出xshell或者重启就会恢复到原来的gcc版本。
如果要长期生效的话,执行如下:

echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

 

posted @ 2021-05-15 14:30  五毒不侵滴bug  阅读(45)  评论(0编辑  收藏  举报