程序员潇然 发表于 2022-10-10 09:59:15

ubuntu 安装redis

### 下载

打开官网,进入下载页
`https://redis.io/`

!(data/attachment/forum/202210/10/094756tuznt8c9cumocoi5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")


!(data/attachment/forum/202210/10/094810fweigwtwrlruwywg.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

找到需要的版本,获取到链接地址(点一下下载 或者 右键看下等)

wget直接下载到指定位置

!(data/attachment/forum/202210/10/094937nttf4p004ap0umma.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")


解压缩

!(data/attachment/forum/202210/10/094957hmgvd9gwe8fedz11.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

### 安装

进入到目录(cd)

执行   make   命令

`make PREFIX=/usr/local/redis install`

!(data/attachment/forum/202210/10/095038ub3njzfnyqfq3joo.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

进入安装位置:

!(data/attachment/forum/202210/10/095056txm6axzeqc4hi4ia.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")


复制一个配置文件过来

!(data/attachment/forum/202210/10/095107por7bm4jco7j1a4n.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

创建启动脚本

!(data/attachment/forum/202210/10/095133pymsyyjm6ryjmj5y.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

启动脚本 传入端口号形如
start.sh 6379   查找conf下6379的配置文件启动

start.sh

```bash
#!/bin/sh

if [ $# -ne 1 ]; then
        echo "usage: $0 port"
        exit -1;
fi

PORT=$1

#您可以在此处修改redis-server和conf的所在路径
REDIS_SERVER="./bin/redis-server"
REDIS_CLI="./bin/redis-cli"
REDIS_CONF="./conf/redis_$PORT.conf"

if [ ! -e $REDIS_SERVER ]; then
        echo "$REDIS_SERVER does not exist!"
        exit -1
fi

if [ ! -e $REDIS_CONF ]; then
        echo "$REDIS_CONF does not exist!"
        exit -1
fi

cmd="ps -ef | grep ${REDIS_SERVER} | grep -v grep | grep -v vim | grep -v defunct | grep '$PORT' | awk '{ print \$2 }'"
#echo $cmd

PID=$(eval ${cmd})
#echo $PID

if [ $PID"e" != "e" ]; then
        echo "redis-server(port:$PORT) is running, can't start"
        exit -1
else
        $REDIS_SERVER $REDIS_CONF &
fi


startfail=1
for i in `seq 0 180`
do
        PID=$(eval ${cmd})
        #echo $PID
        if [ $PID"e" != "e" ]; then
                ${REDIS_SERVER} --version
                echo "Redis server(port:$PORT) is stared..."
                startfail=0
                break
        fi
        sleep 1
done

exit $startfail


```

stop.sh

```bash
#!/bin/sh

if [ $# -ne 1 ]; then
        echo "usage: $0 port"
        exit -1;
fi

PORT=$1

#您可以在此处修改redis-server的所在路径
REDIS_SERVER="./bin/redis-server"

cmd="ps -ef | grep ${REDIS_SERVER} | grep -v grep | grep -v vim | grep -v defunct | grep ${PORT} | awk '{ print \$2 }'"
#echo $cmd

PID=$(eval ${cmd})

if [ ${PID}"e" = "e" ]; then
        echo "redis-server(port:$PORT) is not started"
        exit -1
else
        kill $PID
fi

stopfail=1
for i in `seq 0 30`
do
        PID=$(eval ${cmd})
        #echo $PID
        if [ ${PID}"e" != "e" ]; then
                echo "redis-server(port:$PORT) is still running, waiting to stop[${i}]..."
        else
                echo "redis-server(port:$PORT) is stoped"
                stopfail=0
           break
           fi
        sleep 1
done

exit $stopfail

```

restart.sh

```bash
#!/bin/sh

if [ $# -ne 1 ]; then
        echo "usage: $0 port"
        exit -1
fi

PORT=$1

./stop.sh $PORT
./start.sh $PORT

```







本地客户端测试成功

!(data/attachment/forum/202210/10/095207wge5sy5yybz0e6mp.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

重新修改配置文件
去掉只有本机可以访问

!(data/attachment/forum/202210/10/095219k73xeavzx2awdzta.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

默认是yes。不需要密码,修改为no

!(data/attachment/forum/202210/10/095229zid25ulftf24t554.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

设置守护进程修改为yes

!(data/attachment/forum/202210/10/095240al6lewl4zv7ci9rv.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

设置密码
!(data/attachment/forum/202210/10/095251xwcbebhehlken9b9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")

!(data/attachment/forum/202206/16/141330jha7st9soow8772i.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "common_log.png")
`转载务必注明出处:程序员潇然,疯狂的字节X,https://crazybytex.com/thread-198-1-1.html `
页: [1]
查看完整版本: ubuntu 安装redis