Docker持久化部署Mysql & Redis

Docker持久化部署Mysql & Redis

Mysql

bash 复制代码
cd /opt

mkdir mysql

cd mysql

# 创建mysql日志本地目录 作为持久化数据卷
mkdir log
# 创建mysql数据库存放 本地目录 作为持久化数据卷
mkdir data

## 编写运行docker部署mysql脚本
cd ~
vi mysql.sh

## 将以下内容写入mysql.sh文件中
docker run -p 32769:3306 --name mysql \
-v /opt/mysql/log:/var/log/mysql \
-v /opt/mysql/data:/var/lib/mysql \
-e MYSQLQ_ROOT_PASSWORD=12341234 \
-d mysql:5.7.10

## 保存shell脚本
:x

## 设置脚本运行权限
chmod -R 775 ./mysql.sh

## 运行脚本
./mysql.sh

Redis

shell 复制代码
cd /opt

mkdir redis

cd redis

# 创建配置文件本地存放目录
mkdir conf

# 创建数据持久化本地存放目录
mkdir data

# 创建redis服务的配置文件
cd conf
mkdir redis.conf
## 将配置写入
cat > /opt/redis/conf/redis.conf << EOF
appendonly yes

requirepass yourpassword_123

protected-mode no

bind 0.0.0.0

EOF

## 准备启动redis的docker指令(使用shell脚本运行)
cd ~

## 新建一个运行脚本
vi redis.sh

## 写入以下内容
docker run -p 32767:6379 --name redis --restart=always  \
-v /opt/redis/data:/data  \
-v /opt/redis/conf/redis.conf:/etc/redis/redis.conf  \
-d redis:5.0.5 redis-server /etc/redis/redis.conf

## 保存
:x

## 设置文件权限
chmod -R 755 ./redis.sh

## 运行脚本
./redis.sh                
相关推荐
阿巴~阿巴~4 小时前
Redis 核心文件、命令与操作指南
数据库·redis·缓存·客户端·服务端
koping_wu4 小时前
【Redis】用Redis实现分布式锁、乐观锁
数据库·redis·分布式
做运维的阿瑞5 小时前
Docker 从入门到精通:完整通关笔记
笔记·docker·容器
海奥华25 小时前
SQLEXPLAIN 详解
数据库·mysql
huihuihuanhuan.xin6 小时前
后端八股之Redis
数据库·redis·缓存
情深不寿3176 小时前
MySQL————数据库基础
数据库·mysql
程序新视界6 小时前
如何选择合适的数据库?PostgreSQL与MySQL各项对比
数据库·mysql·postgresql
❀͜͡傀儡师6 小时前
使用docker 安装dragonfly带配置文件(x86和arm)版本
运维·docker·容器
dongchen。9 小时前
MySQL第一次作业
数据库·mysql
Mr. Cao code10 小时前
Dockerfile 指令详解与实战指南
linux·运维·ubuntu·docker·容器