JumpServer,Docker部署
JumpServer,Docker部署

JumpServer,Docker部署

安装docker

[root@ubuntu2004 ~]#apt -y install docker.io
[root@ubuntu2004 ~]#docker version 
Client:
 Version:           20.10.12
 API version:       1.41
 Go version:        go1.16.2
 Git commit:        20.10.12-0ubuntu2~20.04.1
 Built:             Wed Apr  6 02:14:38 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.12
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.2
  Git commit:       20.10.12-0ubuntu2~20.04.1
  Built:            Thu Feb 10 15:03:35 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.9-0ubuntu1~20.04.4
  GitCommit:        
 runc:
  Version:          1.1.0-0ubuntu1~20.04.1
  GitCommit:        
 docker-init:
  Version:          0.19.0
  GitCommit: 

安装MySQL

#安装jumpserver的配置要求准备配置文件
[root@ubuntu2004 ~]#mkdir -p /etc/mysql/mysql.conf.d/
[root@ubuntu2004 ~]#mkdir -p /etc/mysql/conf.d/
[root@ubuntu2004 ~]#vim /etc/mysql/mysql.conf.d/mysqld.cnf
[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
[root@ubuntu2004 ~]#vim /etc/mysql/conf.d/mysql.cnf
[mysql]
default-character-set=utf8

#运行mysql
[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
Unable to find image 'mysql:5.7.30' locally
5.7.30: Pulling from library/mysql
8559a31e96f4: Pull complete 
d51ce1c2e575: Pull complete 
c2344adc4858: Pull complete 
fcf3ceff18fc: Pull complete 
16da0c38dc5b: Pull complete 
b905d1797e97: Pull complete 
4b50d1c6b05c: Pull complete 
d85174a87144: Pull complete 
a4ad33703fa8: Pull complete 
f7a5433ce20d: Pull complete 
3dcd2a278b4a: Pull complete 
Digest: sha256:32f9d9a069f7a735e28fd44ea944d53c61f990ba71460c5c183e610854ca4854
Status: Downloaded newer image for mysql:5.7.30
37e1f6a67818dccb475ccace767bd6eb30cdb00e21993322a4a8954d7e98110c

#验证mysql
[root@ubuntu2004 ~]#docker exec -it mysql sh
# mysql -p123456 -e 'show variables like "character%"'
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
# 

安装Redis

[root@ubuntu2004 ~]#docker run -d -p 6379:6379 --name redis --restart always  redis:6.2.7
Unable to find image 'redis:6.2.7' locally
6.2.7: Pulling from library/redis
31b3f1ad4ce1: Pull complete 
ff29a33e56fb: Pull complete 
b230e0fd0bf5: Pull complete 
72d42747a22c: Pull complete 
22867d4f5465: Pull complete 
ae5fd86f0c58: Pull complete 
Digest: sha256:45a37e30dd2b3eb803b71296dd962bab827558ff017c1baad4d957a030415acf
Status: Downloaded newer image for redis:6.2.7
2072a60de02aebd44375fbfe771c1a5ada9ce18e6a2af75000868c46869aa209

安装jumpserver

[root@ubuntu2004 ~]#vim key.sh 
#!/bin/bash
# 
#********************************************************************
#Author:            shuhong
#QQ:                985347841
#Date:              2022-09-20
#FileName:          key.sh
#URL:               hhhhh
#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 
SECRET_KEY=5IdhwdlRz8Ugmp4USRl3Vo0ZTMywRO62j4uLChjaCumao4jV6U
BOOTSTRAP_TOKEN=JgPfxtc8Cn71pyA1

#配置镜像加速
[root@ubuntu2004 ~]#sudo tee /etc/docker/daemon.json <<-'EOF'
> {
>   "registry-mirrors": ["https://sj00svk9.mirror.aliyuncs.com"]
> }
> EOF
{
  "registry-mirrors": ["https://sj00svk9.mirror.aliyuncs.com"]
}
[root@ubuntu2004 ~]#sudo systemctl daemon-reload
[root@ubuntu2004 ~]#sudo systemctl restart docker


#运行jumpserver
[root@ubuntu2004 ~]#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=5IdhwdlRz8Ugmp4USRl3Vo0ZTMywRO62j4uLChjaCumao4jV6U \
>    -e BOOTSTRAP_TOKEN=JgPfxtc8Cn71pyA1 \
>    -e LOG_LEVEL=ERROR \
>    -e DB_HOST=10.0.0.205 \
>    -e DB_PORT=3306 \
>    -e DB_USER=jumpserver \
>    -e DB_PASSWORD=123456 \
>    -e DB_NAME=jumpserver \
>    -e REDIS_HOST=10.0.0.205 \
>    -e REDIS_PORT=6379 \
>    -e REDIS_PASSWORD='' \
>    --privileged=true \
>    jumpserver/jms_all:v2.25.5
Unable to find image 'jumpserver/jms_all:v2.25.5' locally
v2.25.5: Pulling from jumpserver/jms_all
675920708c8b: Pull complete 
4f4fb700ef54: Pull complete 
afb82be343e8: Pull complete 
4c3af39a3a5c: Pull complete 
f6136b206bef: Pull complete 
e61f0ddc6b98: Pull complete 
7b17c6db26b4: Pull complete 
762961625238: Pull complete 
617c06cf2a55: Pull complete 
Digest: sha256:70e83dd31a676afbb0a33c5561dfd3e2bf50c668d7628ed87faa0d1c8c8f5119
Status: Downloaded newer image for jumpserver/jms_all:v2.25.5
7f9267ee1a8cb8b5b9854521843340e05569e625742cfd7f451165362678fcae


[root@ubuntu2004 ~]#ss -ntlp
State           Recv-Q          Send-Q                   Local Address:Port                    Peer Address:Port         Process                                            
LISTEN          0               4096                         127.0.0.1:34471                        0.0.0.0:*             users:(("containerd",pid=5228,fd=12))             
LISTEN          0               4096                           0.0.0.0:3306                         0.0.0.0:*             users:(("docker-proxy",pid=11309,fd=4))           
LISTEN          0               4096                           0.0.0.0:6379                         0.0.0.0:*             users:(("docker-proxy",pid=11288,fd=4))           
LISTEN          0               4096                           0.0.0.0:2222                         0.0.0.0:*             users:(("docker-proxy",pid=11947,fd=4))           
LISTEN          0               4096                           0.0.0.0:80                           0.0.0.0:*             users:(("docker-proxy",pid=11967,fd=4))           
LISTEN          0               4096                     127.0.0.53%lo:53                           0.0.0.0:*             users:(("systemd-resolve",pid=740,fd=13))         
LISTEN          0               128                            0.0.0.0:22                           0.0.0.0:*             users:(("sshd",pid=770,fd=3))                     
LISTEN          0               4096                              [::]:3306                            [::]:*             users:(("docker-proxy",pid=11315,fd=4))           
LISTEN          0               4096                              [::]:6379                            [::]:*             users:(("docker-proxy",pid=11296,fd=4))           
LISTEN          0               4096                              [::]:2222                            [::]:*             users:(("docker-proxy",pid=11953,fd=4))           
LISTEN          0               4096                              [::]:80                              [::]:*             users:(("docker-proxy",pid=11973,fd=4))           
LISTEN          0               128                               [::]:22                              [::]:*             users:(("sshd",pid=770,fd=4))