完成
This commit is contained in:
commit
39c5898cc5
46
README.md
Normal file
46
README.md
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# docker-redis
|
||||||
|
|
||||||
|
基于docker启动的redis服务
|
||||||
|
|
||||||
|
## 用法
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://git.wandoubaba.com/wandoubaba/docker-redis.git
|
||||||
|
cd docker-redis
|
||||||
|
./service start
|
||||||
|
```
|
||||||
|
|
||||||
|
## 服务控制
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# 启动
|
||||||
|
./service start
|
||||||
|
# 停止
|
||||||
|
./service stop
|
||||||
|
# 重启
|
||||||
|
./service restart
|
||||||
|
# 查看状态
|
||||||
|
./service status
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置
|
||||||
|
|
||||||
|
- 容器名称
|
||||||
|
|
||||||
|
在`docker-compose.yml`中设置容器名称,同时在`redis-cli`脚本和`service`脚本中修改对应的容器名称。
|
||||||
|
|
||||||
|
- 服务端口号
|
||||||
|
|
||||||
|
在`redis.conf`中修改`port 6379`一行,修改后需要重启服务生效。
|
||||||
|
|
||||||
|
- 连接密码
|
||||||
|
|
||||||
|
在`redis.conf`中修改`requirepass 123456`一行,修改后需要重启服务生效。
|
||||||
|
|
||||||
|
- 其他配置
|
||||||
|
|
||||||
|
在`redis.conf`中修改其他配置。
|
||||||
|
|
||||||
|
## 客户端
|
||||||
|
|
||||||
|
`redis-cli`脚本就是调用容器内的`redis-cli`工具实现客户端连接的,用法与`redis-cli`工具相同。
|
2
data/.gitignore
vendored
Normal file
2
data/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
version: "3.1"
|
||||||
|
|
||||||
|
services:
|
||||||
|
redis:
|
||||||
|
image: redis:7.2
|
||||||
|
container_name: redis
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- ./data:/data
|
||||||
|
- ./redis.conf:/etc/redis/redis.conf
|
||||||
|
command: redis-server /etc/redis/redis.conf
|
||||||
|
network_mode: host
|
14
redis-cli
Executable file
14
redis-cli
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 获取脚本所在目录的绝对路径
|
||||||
|
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||||
|
|
||||||
|
# 切换工作目录到脚本所在目录
|
||||||
|
cd $SCRIPT_DIR
|
||||||
|
|
||||||
|
container_name="redis"
|
||||||
|
|
||||||
|
export REDIS_PASSWORD="123456"
|
||||||
|
export REDIS_PORT=6379
|
||||||
|
|
||||||
|
docker exec -it $container_name bash -c "redis-cli -p $REDIS_PORT -a $REDIS_PASSWORD $@"
|
2297
redis.conf
Normal file
2297
redis.conf
Normal file
File diff suppressed because it is too large
Load Diff
22
service
Executable file
22
service
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 获取脚本所在目录的绝对路径
|
||||||
|
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||||
|
|
||||||
|
# 切换工作目录到脚本所在目录
|
||||||
|
cd $SCRIPT_DIR
|
||||||
|
|
||||||
|
container_name="redis"
|
||||||
|
|
||||||
|
if [ "$1" = "start" ]; then
|
||||||
|
docker compose up -d
|
||||||
|
elif [ "$1" = "stop" ]; then
|
||||||
|
docker compose down
|
||||||
|
elif [ "$1" = "restart" ]; then
|
||||||
|
docker compose down
|
||||||
|
docker compose up -d
|
||||||
|
elif [ "$1" = "status" ]; then
|
||||||
|
docker ps -a | grep $container_name
|
||||||
|
else
|
||||||
|
echo "Usage: $0 [start|stop|restart|status]"
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user