容器(22)--Docker下jumpserver跳板机 /堡垒
关于跳板机/堡垒机的介绍:
跳板机可以使开发或运维人员在维护过程中首先要统一登录到这台服务器,然后再登录到目标设备进行维护和操作
跳板机使用场景
![](https://img.haomeiwen.com/i17333398/67113cdc5a8915f1.png)
jumpserver概述
Jumpserver是一款开源的开源的堡垒机,可使系统的管理员和开发人员安全的连接到企业内部服务器上执行操作,并且支持大部分操作系统,是一款非常安全的远程连接工具
常见支持的系统:
CentOS, RedHat, Fedora, Amazon Linux
Debian
SUSE, Ubuntu
FreeBSD
其他ssh协议硬件设备
部署步骤
实验环境
关闭selinux
[root@centos7 ~]#setenforce 0
关闭防火墙
[root@centos7 ~]#systemctl stop firewalld
[root@centos7 ~]#iptables -F
安装docker的源
[root@centos7 ~]#yum -y install wget
[root@centos7 ~]#cd /etc/yum.repos.d/
[root@centos7 ~]#wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@centos7 ~]#wget http://mirrors.aliyun.com/repo/Centos-7.repo
[root@centos7 ~]#yum -y install centos-release-openstack-ocata
配置mariadb
安装mariadb
[root@centos7 ~]#yum -y install mariadb-server
修改配置文件
[root@centos7 ~]#vim /etc/my.cnf
[client-server]
[mysqld]
symbolic-links=0
#禁止主机名解析
skip_name_resolve
!includedir /etc/my.cnf.d
启动服务
[root@centos7 ~]#systemctl start mariadb
[root@centos7 ~]#systemctl enable mariadb
创建jumpserver数据库并授权
MariaDB [(none)]> create database jumpserver default charset 'utf8';
#创建管理账号,密码必须是数字加字母
MariaDB [(none)]> grant all on jumpserver.* to 'jumpserver'@'%' identified by 'linux123';
配置Redis
安装Redis
[root@centos7 ~]#yum -y install redis
编辑配置文件
[root@centos7 ~]#vim /etc/redis.conf
61:bind 0.0.0.0
480:requirepass 123
启动服务
[root@centos7 ~]#systemctl start redis
[root@centos7 ~]#systemctl enable redis
配置docker
安装docker
[root@centos7 ~]#yum -y install docker-ce
启动docker
[root@centos7 ~]#systemctl start docker
[root@centos7 ~]#systemctl enable docker
[root@centos7 ~]#mkdir /opt/jumpserver/data/media -pv
[root@centos7 ~]#mkdir /opt/jumpserver
下载jumpserver镜像,并运行
[root@centos7 ~]#docker run --name jms_all -d \
-v /opt/mysql:/var/lib/mysql \
-v /opt/jumpserver:/opt/jumpserver/data/media \
-p 80:80 \
-p 2222:2222 \
-e SECRET_KEY=PEHVdLzvZFtDQT733ntHDH1hglXQ9OQKoI1xxAfdDhpRGx3tg7 \
-e BOOTSTRAP_TOKEN=YDzl55tZPTdclbUh \
-e DB_HOST=173.22.90.13 \ #当前主机IP
-e DB_PORT=3306 \
-e DB_USER=jumpserver \ #数据库用户
-e DB_PASSWORD=linux123 \ #数据库密码
-e DB_NAME=jumpserver \ #数据库名称
-e REDIS_HOST=173.22.90.13 \
-e REDIS_PORT=6379 \
-e REDIS_PASSWORD=123 \ #Redis密码
jumpserver/jms_all:1.4.8
查看状态
[root@centos7 ~]#docker logs -f jms_all
#看到如下几行即可
gunicorn is running: 57
celery is running: 73
beat is running: 75
guacd[98]: INFO: Guacamole proxy daemon (guacd) version 0.9.14 started
Starting guacd: SUCCESS
Tomcat started.
Use eventlet dispatch
Start coco process
Use eventlet dispatch
Start coco process
Use eventlet dispatch
Start coco process
Jumpserver ALL 1.4.8
官网 http://www.jumpserver.org
文档 http://docs.jumpserver.org
有问题请参考 http://docs.jumpserver.org/zh/docs/faq.html
进入容器命令 docker exec -it jms_all /bin/bash
访问测试
登入web界面,初始密码账号均为admin
![](https://img.haomeiwen.com/i17333398/fd10ee8cb896e00c.png)
登录jumpserver服务web端进行虚拟机管理操作
1)登录admin管理界面
![](https://img.haomeiwen.com/i17333398/3ed769a3c6093095.png)
创建一个develop组
![](https://img.haomeiwen.com/i17333398/9dff123eaf733f31.png)
3)创建一个用户curry,将curry添加到develop组里面,角色为普通用户,然后提交
![](https://img.haomeiwen.com/i17333398/98455c8d8b4adfbf.png)
4)点击更新,给curry用户添加登录密码
![](https://img.haomeiwen.com/i17333398/1124a3232e74ce71.png)
填写curry用户密码然后提交
![](https://img.haomeiwen.com/i17333398/52dc7d06e8e6ee5b.png)
5)用curry账号登录
![](https://img.haomeiwen.com/i17333398/573c90e3962408fa.png)
进入curry用户界面
![](https://img.haomeiwen.com/i17333398/06e1a500be2e8e4b.png)
6)创建一个管理用户(用来管理资产虚拟主机,此用户必须要有资产虚拟主机的root身份,其中的密码为ssh登录虚拟主机的密码)
![](https://img.haomeiwen.com/i17333398/12460b4c3976c55d.png)
7)创建资产(指的是被管理的虚拟主机)
![](https://img.haomeiwen.com/i17333398/425c62abc62be003.png)
填入虚拟主机名、ip地址及管理用户
![](https://img.haomeiwen.com/i17333398/477148d8cb8c89d1.png)
点击主机名,进入资产详情页面
![](https://img.haomeiwen.com/i17333398/6d194a25afb1bc55.png)
点击测试,检测被管理的虚拟主机是否能ping通,如下结果表明测试成功
![](https://img.haomeiwen.com/i17333398/c3b9d53031011e80.png)
8)创建一个过滤器
![](https://img.haomeiwen.com/i17333398/7fd38718bb966afd.png)
9)创建一个系统用户(此用户名在登录虚拟主机后会被自动创建,为虚拟主机登录的默认普通用户,非管理员用户,权限比较小)
![](https://img.haomeiwen.com/i17333398/14a2e9eb876040a6.png)
10)创建授权规则,将资产添加到develop组中,是的此组中的用户可以访问此资产虚拟主机
![](https://img.haomeiwen.com/i17333398/2079c043bed55c49.png)
11)登录curry用户界面,点击web终端
![](https://img.haomeiwen.com/i17333398/cdfc468ddbfdb9c6.png)
可以看到被授权的终端虚拟机,点击虚拟终端即可在命令窗口操作终端
![](https://img.haomeiwen.com/i17333398/d41f110255c5e464.png)
12)再设置过滤器
![](https://img.haomeiwen.com/i17333398/d3d13d4d53d4c724.png)
点击规则
![](https://img.haomeiwen.com/i17333398/b324c5c26d4c16bc.png)
设置命令过滤禁止规则
![](https://img.haomeiwen.com/i17333398/c925a58f4472a2ef.png)
13)此时再一次登录curry页面登录虚拟主机时,执行这些命令将会被禁止,如下所示
![](https://img.haomeiwen.com/i17333398/89591ae0bcf8b38b.png)
14)回到admin的web端,在会话管理下的历史会话可以打开录像回放列表,记录虚拟主机的所有操作过程的录像
![](https://img.haomeiwen.com/i17333398/0218fb386b13e72e.png)
15)录像回放
![](https://img.haomeiwen.com/i17333398/bc66c865cdab8437.png)
16)再创建一个资产
![](https://img.haomeiwen.com/i17333398/a7b61985bddcd709.png)
17)在资产授权中将此资产也添加到develop组中
![](https://img.haomeiwen.com/i17333398/0adbf401e87d77ac.png)
18)登录curry界面并打开web终端可以看到操作两台虚拟主机
![](https://img.haomeiwen.com/i17333398/283f99d026e4993d.png)
。