YouChuKoffee/start.sh

33 lines
1.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 检测 MySQL 容器是否在运行
if [ "$(docker ps -q -f name=mysql-container)" ] && [ "$(docker ps -q -f name=redis-container)" ]; then
echo "MySQL 容器已经在运行,退出脚本。"
exit
fi
# 下载 MySQL 8.0.33 镜像
docker pull mysql:8.0.33
# 下载 Redis Alpine 3.10 镜像
docker pull redis:alpine3.10
# 挂载 Redis 和 MySQL 配置目录以及数据存储目录到 /var/www 目录
mkdir -p /var/www/redis/config
mkdir -p /var/www/mysql/config
mkdir -p /var/www/mysql/data
# 启动 MySQL Docker 容器,并挂载配置目录和数据存储目录,设置 root 密码为 lansexiongdi@666并开启远程连接
# 在容器内部创建新的 MySQL 配置目录
docker run -d --name mysql-container -v /var/www/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=lansexiongdi@666 -e MYSQL_ROOT_HOST='%' -p 3306:3306 mysql:8.0.33
# 等待 MySQL 容器启动
echo "等待 MySQL 容器启动..."
# 给 MySQL 的 root 用户授权远程登录
docker exec -it mysql-container mysql -uroot -p lansexiongdi@666 -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'lansexiongdi@666';SET GLOBAL log_bin = 'mysql-bin'; FLUSH PRIVILEGES;"
# 启动 Redis Docker 容器,并挂载配置目录,设置密码为 lansexiongdi@666
docker run -d --name redis-container -v /var/www/redis/redis.conf:/etc/redis.conf -v /var/www/redis/data:/var/lib/redis -e REDIS_PASSWORD=lansexiongdi@666 -p 6379:6379 redis:alpine3.10
echo "MySQL 和 Redis 容器已启动,并配置目录已挂载到 /var/www 目录。MySQL root 用户已授权远程登录。"