以下配置均在一台ubuntu上實作
# 生成主控端Mysql配置檔案,便于docker内容器使用
[root@ubuntu2004 ~]#mkdir -p /etc/mysql/mysql.conf.d
[root@ubuntu2004 ~]#mkdir -p /etc/mysql/conf.d
#生成伺服器配置檔案,指定字元集
[root@ubuntu2004 ~]#tee /etc/mysql/mysql.conf.d/mysqld.conf <<EOF
[mysqld]
pid-file= /var/run/mysqld/mysqld.pid
socket= /var/run/mysqld/mysqld.sock
datadir= /var/lib/mysql
symbolic-links=0
character-set-server=utf8 #添加此行,指定字元集
EOF
##生成用戶端配置檔案,指定字元集
[root@ubuntu2004 ~]#tee /etc/mysql/conf.d/mysql.cnf <<EOF
[mysql]
default-character-set=utf8 #添加此行,指定字元集
EOF
[root@ubuntu2004 ~]#apt -y install docker.io #安裝docker
# 運作一個docker容器 mysql 版本mysql5.7.30
[root@ubuntu2004 ~]#docker run -d -p 3306:3306 --name mysql --restart always \
-e MYSQL_ROOT_PASSWORD=123456 \
-e MYSQL_DATABASE=jumpserver \
-e MYSQL_USER=jumpserver \
-e MYSQL_PASSWORD=123456 \
-v /data/mysql:/var/lib/mysql \
-v /etc/mysql/mysql.conf.d/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf \
-v /etc/mysql/conf.d/mysql.cnf:/etc/mysql/conf.d/mysql.cnf mysql:5.7.30
[root@ubuntu2004 ~]#docker run -d -p 6379:6379 --name redis --restart always redis:6.2.7 #下載下傳并運作redis容器
[root@ubuntu2004 ~]#vim key.sh #生成 key 和 token的腳本
#!/bin/bash
#
#********************************************************************
#Author: wangdayu
#Date: 2022-09-20
#FileName: key.sh
#URL: https://blog.51cto.com/dayu
#Description: The test script
#Copyright (C): 2022 All rights reserved
#********************************************************************
if [ ! "$SECRET_KEY" ]; then
SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50`;
echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc;
echo SECRET_KEY=$SECRET_KEY;
else
echo SECRET_KEY=$SECRET_KEY;
fi
if [ ! "$BOOTSTRAP_TOKEN" ]; then
BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16`;
echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc;
echo BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN;
else
echo BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN;
fi
[root@ubuntu2004 ~]#bash key.sh #生成 key 和 token
SECRET_KEY=c2ZIUQcgtUIBsakULZzSWrKUBQOGFdlcd1RVqkJutQMvbvAOM4
BOOTSTRAP_TOKEN=K3hnAG43LH31KrMf
docker run --name jms_all -d \
-v /opt/jumpserver/core/data:/opt/jumpserver/data \
-v /opt/jumpserver/koko/data:/opt/koko/data \
-v /opt/jumpserver/lion/data:/opt/lion/data \
-p 80:80 \
-p 2222:2222 \
-e SECRET_KEY=tOI3RfdEcUkDCrs6cSMusMaeiVKoMFWSlrZSFbRyVen73gZbKP \
-e BOOTSTRAP_TOKEN=B7PwH4urvYBUvIHG \
-e LOG_LEVEL=ERROR \
-e DB_HOST=10.0.0.101 \
-e DB_PORT=3306 \
-e DB_USER=jumpserver \
-e DB_PASSWORD=123456 \
-e DB_NAME=jumpserver \
-e REDIS_HOST=10.0.0.101 \
-e REDIS_PORT=6379 \
-e REDIS_PASSWORD='' \
--privileged=true \
--restart always \
jumpserver/jms_all:v2.25.5