18張圖帶你入門最新版JumpServer

環境要求

  • docker-ce
  • Python3+
  • mysql5.6+
  • Redis

1 Ubuntu 安裝 docker-ce 環境

參考文檔

//docs.docker.com/engine/install/debian/
//mirrors.tuna.tsinghua.edu.cn/help/docker-ce/

卸載舊版

sudo apt-get remove docker docker-engine docker.io containerd runc

安裝依賴

sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common

信任 Docker 的 GPG 公鑰(發行版不同,下面的內容也有所不同)

curl -fsSL //download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

添加倉庫(發行版不同,下面的內容也有所不同)

sudo add-apt-repository \
   "deb [arch=amd64] //mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

安裝docker-ce

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

檢查是否安裝成功

root@song-VirtualBox:~# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 //hub.docker.com/

For more examples and ideas, visit:
 //docs.docker.com/get-started/

root@song-VirtualBox:~# hostnamectl set-hostname ubuntu20
root@song-VirtualBox:~#
root@ubuntu20:~# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   2 months ago   13.3kB
root@ubuntu20:~#

2 Python 安裝

Ubuntu20 自帶的 Python 版本即可滿足,只需要做一個軟連接即可

ln -s /usr/bin/python3 /usr/bin/python

3 mysql5.7 安裝

root@ubuntu20:~# docker pull mysql:5.7
5.7: Pulling from library/mysql
f7ec5a41d630: Pull complete
9444bb562699: Pull complete
6a4207b96940: Pull complete
181cefd361ce: Pull complete
8a2090759d8a: Pull complete
15f235e0d7ee: Pull complete
d870539cd9db: Pull complete
cb7af63cbefa: Pull complete
151f1721bdbf: Pull complete
fcd19c3dd488: Pull complete
415af2aa5ddc: Pull complete
Digest: sha256:a655529fdfcbaf0ef28984d68a3e21778e061c886ff458b677391924f62fb457
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
root@ubuntu20:~#

# 配置 mysql 服務端
root@ubuntu20:~# mkdir -pv /etc/mysql/mysql.conf.d
root@ubuntu20:~# cat /etc/mysql/mysql.conf.d/mysqld.cnf
pid-file  = /var/run/mysqld/mysqld.pid
socket    = /var/run/mysqld/mysqld.sock
datadir   = /var/lib/mysql
character-set-server=utf8
root@ubuntu20:~#

# 配置 mysql 客戶端
root@ubuntu20:~# cat /etc/mysql/conf.d/mysql.cnf
[mysql]
default-character-set=utf8
root@ubuntu20:~#

# 創建數據存放目錄
root@ubuntu20:~# mkdir -pv /data/mysql
mkdir: created directory '/data/mysql'
root@ubuntu20:~#

# 運行 mysql 鏡像
docker run -it \
--name mysql_jump \
-p 14306:3306 \
-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 \
-v /data/mysql:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD="song123" \
-d mysql:5.7

# 連接mysql
# 注意:需要指定 -h宿主機IP 
root@ubuntu20:/data# mysql -uroot -psong123 -P14306 -h10.0.0.16


# 創建 jumpserver 資料庫
mysql> create database jumpserver default charset 'utf8';
Query OK, 1 row affected (0.00 sec)

# 授權
mysql> grant all privileges on jumpserver.* to 'jumpserver'@'%' identified by 'song123';
Query OK, 0 rows affected, 1 warning (0.01 sec)

# 驗證授權用戶是否可以登錄查看 jumpserver 資料庫
root@ubuntu20:~# mysql -ujumpserver -psong123 -P14306 -h10.0.0.16
# 查看
mysql> show databases;

4. Redis 安裝

# 下載最新版 redis 鏡像
docker pull redis

# 新建 redis 配置和數據目錄
mkdir -pv /data/redis/{conf,data}

# redis 配置
cat /data/redis/conf/redis.conf
protected-mode no  
daemonize no       
databases 16       
dir  ./            
appendonly yes   

# 運行 redis 容器
docker run \
--privileged \
--name redis_jump \
-p 6379:6379 \
-v /data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf \
-v /data/redis/data:/data \
-d redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes

# 在宿主機安裝 reids,主要是使用其客戶端工具 redis-cli
apt -y install redis

# 驗證是否可以登錄 redis
root@ubuntu20:/data/redis/conf# redis-cli -h 10.0.0.16
10.0.0.16:6379> info  # 查看 redis 資訊

# Server

redis_version:6.2.3
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:ff251c3aac5814bc
... 省略部分 ...

5 安裝 jumpserver

# 下載 jumpserver 鏡像
docker pull jumpserver/jms_all:latest

# 生成隨機加密秘鑰和初始化 token
root@ubuntu20:~# if [ "$SECRET_KEY" = "" ];then SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50`; \
echo "SECRET_KEY=$ECRET_KEY" >> ~/.bashrc; echo $SECRET_KEY; else echo $SECRET_KEY; fi
sii4P5BCRfho4kqRIoGMZsvnrkbbNcRMIOFWRl5aN6gGeCFmRQ   # 秘鑰 

root@ubuntu20:~# 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; else echo $BOOTSTRAP_TOKEN; fi
AiElOlVO8Ey9mCBg         # TOKEN

運行 jumpserver

docker run --name pc_jump \
-v /opt/jumpserver:/opt/jumpserver/data/media \
-p 80:80 \
-p 2222:2222 \
-e SECRET_KEY=sii4P5BCRfho4kqRIoGMZsvnrkbbNcRMIOFWRl5aN6gGeCFmRQ \
-e BOOTSTRAP_TOKEN=AiElOlVO8Ey9mCBg \
-e DB_HOST=10.0.0.16 \
-e DB_PORT=14306 \
-e DB_USER='jumpserver' \
-e DB_PASSWORD='song123' \
-e DB_NAME=jumpserver \
-e REDIS_HOST=10.0.0.16 \
-e REDIS_PORT=6379 \
-e REDIS_PASSWORD= \
jumpserver/jms_all:latest

6 詳細圖解

  1. JumpServer 原始的用戶名和密碼都是 admin,最新版的 JumpServer 為了安全考慮在初次登錄時候會要求修改密碼,請自行設置

  1. 為每個組創建一個使用 JumpServer 管理各自組名下機器的帳號

  1. 創建一個可以登錄真實機器的賬戶,此賬戶必須是真實存在的,同時必須擁有 root 許可權

  1. 創建系統用戶,此用戶是一個登錄(被管理端)機器的普通用戶

  1. 添加(被管理端)機器

  1. 添加後測試 JumpServer 到(被管理端)機器是否能通

  1. 測試通過之後,就需要授權什麼帳號可以登錄(被管理端)機器了

  1. 出於安全考慮,可以在(被管理端)的機器上禁止一些命令

  1. 將禁止的命令和系統用戶做一個關聯

  1. 使用給每個組創建的 JumpServer 賬戶登錄

  2. 點擊 「web終端」 登錄機器進行管理

  1. 確認使用 web 賬戶登錄成功

  1. 可以確認禁止的命令已無法使用