一、Jumpserver简介
1.什么是跳板机(堡垒机)
堡垒机,即在一个特定的网络环境下,为了保障网络和数据不受来自外部和内部用户的入侵和破坏,而运用各种技术手段监控和记录运维人员对网络内的服务器、网络设备、安全设备、数据库等设备的操作行为,以便集中报警、及时处理及审计定责。
简单总结一句话:堡垒机是用来控制哪些人可以登录哪些资产(事先防范和事中控制),以及录像记录登录资产后做了什么事情(事后溯源.)。
集中控制、集中审计 提升运维的管理水平。
2.为什么要使用跳板机
为了高效和安全的进行管理每个服务器。
解决方案:搭建堡垒机环境作为线上服务器的登录入口。
就是为了监控运维人员、开发人员等对服务器有操作权限的,防止他们做坏事,出了事故能够快速的找到具体责任人。
3.跳板机的特性
精细化的管理,让操作人员各司其职。
体系化的指令审计 让操作更安全可控
支持多重身份验证 禁止非法登录和访问
主机账号统一管理,SSH密钥对一键批量分发
4.核心功能
身份验证 Authentication
账号管理 Account
授权控制 Authorization
安全审计 Audit
5.jumpserver环境要求
硬件配置: 2个CPU核心, 4G 内存, 50G 硬盘(最低)
操作系统: Linux 发行版 x86_64
Python = 3.6.x
Mysql Server ≥ 5.6
Mariadb Server ≥ 5.5.56
Redis
6.jumpserver组件说明
JumpServer 为管理后台, 管理员可以通过 Web 页面进行资产管理、用户管理、资产授权等操作, 用户可以通过 Web 页面进行资产登录, 文件管理等操作
koko 为 SSH Server 和 Web Terminal Server 。用户可以使用自己的账户通过 SSH 或者 Web Terminal 访问 SSH 协议和 Telnet 协议资产
Luna 为 Web Terminal Server 前端页面, 用户使用 Web Terminal 方式登录所需要的组件
Guacamole 为 RDP 协议和 VNC 协议资产组件, 用户可以通过 Web Terminal 来连接 RDP 协议和 VNC 协议资产 (暂时只能通过 Web Terminal 来访问)
7.端口说明
JumpServer 默认 Web 端口为 8080/tcp, 默认 WS 端口为 8070/tcp, 配置文件 jumpserver/config.yml
koko 默认 SSH 端口为 2222/tcp, 默认 Web Terminal 端口为 5000/tcp 配置文件在 koko/config.yml
Guacamole 默认端口为 8081/tcp, 配置文件 /config/tomcat9/conf/server.xml
Nginx 默认端口为 80/tcp
Redis 默认端口为 6379/tcp
Mysql 默认端口为 3306/tcp
TCP JumpServer 8080
TCP koko 2222, 5000
TCP Guacamole 8081
TCP Db 3306
TCP Redis 6379
TCP Nginx 80
二、环境准备
系统:Centos7.6
内存:4G(>=2G即可)
软件包:
jms_guacamole.tar.gz
jms_koko.tar.gz
jumpserver.tar.gz
luna.tar.gz
nginx-rpm包:nginx-1.16.1-1.el7.ngx.x86_64.rpm
关闭防火墙、关闭selinux。
(做一个勤劳的CV工程师吧!)
三、部署缓存,数据库及nginx
1.安装依赖包
[root@jump ~]# yum -y install wget gcc epel-release git
2.安装Redis
JumpServer 使用 Redis 做 cache 和 celery broke
[root@jump ~]# yum -y install redis [root@jump ~]# systemctl enable redis [root@jump ~]# systemctl restart redis
3.安装MySQL数据库
[root@jump ~]# yum -y install mariadb mariadb-devel mariadb-server MariaDB-shared [root@jump ~]# systemctl enable mariadb [root@jump ~]# systemctl restart mariadb [root@jump ~]# mysql -uroot -e "create database jumpserver default charset 'utf8' collate 'utf8_bin'; grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by '123'; flush privileges;"
4.安装Nginx
用作代理服务器整合 JumpServer 与各个组件
这里我上传的是nginx的1.16.1版本的rpm安装包,也可以yum安装,这里不作过多要求。
[root@jump ~]# yum localinstall -y nginx-1.16.1-1.el7.ngx.x86_64.rpm [root@jump ~]# systemctl enable nginx [root@jump ~]# systemctl restart nginx
四、安装Python环境
1.安装Python3.6
[root@jump ~]# yum -y install python36 python36-devel
2.配置并载入 Python3 虚拟环境
py3 为虚拟环境名称, 可自定义,看到下面的提示符(py3)代表成功, 以后运行 JumpServer 都要先运行以上 source 命令, 载入环境后默认以下所有命令均在该虚拟环境中运行
[root@jump ~]# cd /opt/ [root@jump /opt]# python3.6 -m venv py3 [root@jump /opt]# source /opt/py3/bin/activate (py3) [root@jump /opt]#
五、部署JumpServer
1.下载JumpServer软件包
两种方法下载JumpServer,第一种是在线下载,执行下面的一条命令即可在线下载。
(py3) [root@jump /opt]# git clone --depth=1 https://github.com/jumpserver/jumpserver.git
第二种是本地上传JumpServer,解压即可,这里软件包就不给了,感兴趣的可以找显哥哥私要。
(py3) [root@jump /opt]# ls -l total 14592 -rw-r--r-- 1 root root 13400118 Apr 16 16:13 jumpserver.tar.gz (py3) [root@jump /opt]# tar xf jumpserver.tar.gz (py3) [root@jump /opt]# ls -l total 14596 drwxr-xr-x 11 root root 4096 Apr 16 10:40 jumpserver -rw-r--r-- 1 root root 13400118 Apr 16 16:13 jumpserver.tar.gz
2.安装依赖RPM包
(py3) [root@jump /opt]# yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt)
3.安装 Python 库依赖
如果pip执行命令失败,出现红色报错,多重复安装几次即可。
(py3) [root@jump /opt]# pip install wheel (py3) [root@jump /opt]# pip install --upgrade pip setuptools -i https://pypi.tuna.tsinghua.edu.cn/simple (py3) [root@jump /opt]# pip install -r /opt/jumpserver/requirements/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
安装完之后大概如下图所示即可安装成功。
4.修改 JumpServer 配置文件
最后一条修改数据库密码123为刚才数据库授权的密码,密码要一致。
(py3) [root@jump /opt]# cd /opt/jumpserver (py3) [root@jump /opt/jumpserver]# cp config_example.yml config.yml (py3) [root@jump /opt/jumpserver]# SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50` (py3) [root@jump /opt/jumpserver]# echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc (py3) [root@jump /opt/jumpserver]# BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16` (py3) [root@jump /opt/jumpserver]# echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc (py3) [root@jump /opt/jumpserver]# sed -i "s/SECRET_KEY:/SECRET_KEY: $SECRET_KEY/g" /opt/jumpserver/config.yml (py3) [root@jump /opt/jumpserver]# sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /opt/jumpserver/config.yml (py3) [root@jump /opt/jumpserver]# sed -i "s/# DEBUG: true/DEBUG: false/g" /opt/jumpserver/config.yml (py3) [root@jump /opt/jumpserver]# sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" /opt/jumpserver/config.yml (py3) [root@jump /opt/jumpserver]# sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: false/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" /opt/jumpserver/config.yml (py3) [root@jump /opt/jumpserver]# sed -i "s/DB_PASSWORD: /DB_PASSWORD: '123'/g" /opt/jumpserver/config.yml
(py3) [root@jump /opt/jumpserver]# vim config.yml
5.运行JumpServer
新版本更新了运行脚本, 使用方式./jms start|stop|status all 后台运行请添加 -d 参数
(py3) [root@jump /opt/jumpserver]# ./jms start -d 2020-04-18 23:55:12 Sat Apr 18 23:55:12 2020 2020-04-18 23:55:12 Jumpserver version 1.5.7, more see https://www.jumpserver.org ...... 此处省略多行输出结果 ...... - Start Daphne ASGI WS Server gunicorn is running: 21483 celery_ansible is running: 21494 celery_default is running: 21498 beat is running: 21502 flower is running: 21506 daphne is running: 21510
6.使用systemd管理JumpServer
下载systemd的service文件,授权755权限,然后使用systemctl查看状态,如有running则运行JumpServer成功。
(py3) [root@jump /opt/jumpserver]# wget -O /usr/lib/systemd/system/jms.service https://demo.jumpserver.org/download/shell/centos/jms.service (py3) [root@jump /opt/jumpserver]# chmod 755 /usr/lib/systemd/system/jms.service (py3) [root@jump /opt/jumpserver]# systemctl enable jms (py3) [root@jump /opt/jumpserver]# systemctl restart jms (py3) [root@jump /opt/jumpserver]# systemctl status jms ● jms.service - jms Loaded: loaded (/usr/lib/systemd/system/jms.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2020-04-19 00:00:31 CST; 4s ago Process: 21615 ExecStart=/opt/jumpserver/jms start -d (code=exited, status=0/SUCCESS) Main PID: 21512 (python3) CGroup: /system.slice/jms.service ‣ 21512 python3 ./jms start -d Apr 19 00:00:30 jump systemd[1]: Starting jms... Apr 19 00:00:31 jump jms[21615]: 2020-04-19 00:00:31 Sun Apr 19 00:00:31 2020 Apr 19 00:00:31 jump jms[21615]: 2020-04-19 00:00:31 Jumpserver version 1.5.7, more se...org Apr 19 00:00:31 jump systemd[1]: Started jms. Hint: Some lines were ellipsized, use -l to show in full.
六、安装Docker
(py3) [root@jump /opt/jumpserver]# yum install -y yum-utils device-mapper-persistent-data lvm2 (py3) [root@jump /opt/jumpserver]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo Loaded plugins: fastestmirror adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo (py3) [root@jump /opt/jumpserver]# yum makecache fast (py3) [root@jump /opt/jumpserver]# rpm --import https://mirrors.aliyun.com/docker-ce/linux/centos/gpg (py3) [root@jump /opt/jumpserver]# yum -y install docker-ce (py3) [root@jump /opt/jumpserver]# systemctl enable docker (py3) [root@jump /opt/jumpserver]# mkdir /etc/docker (py3) [root@jump /opt/jumpserver]# wget -O /etc/docker/daemon.json http://demo.jumpserver.org/download/docker/daemon.json (py3) [root@jump /opt/jumpserver]# systemctl restart docker
七、部署 koko 与 guacamole
1.导入本地镜像文件并docker运行
(py3) [root@jump ~]# ls -l total 1020624 -rw-r--r-- 1 root root 677898240 Apr 16 17:54 jms_guacamole.tar.gz -rw-r--r-- 1 root root 367215104 Apr 16 16:29 jms_koko.tar.gz (py3) [root@jump ~]# docker load -i jms_guacamole.tar.gz 77b174a6a187: Loading layer 211.2MB/211.2MB 4497d361ff2b: Loading layer 466.7MB/466.7MB dd48b03de76a: Loading layer 3.072kB/3.072kB a871ecb85b92: Loading layer 3.072kB/3.072kB Loaded image: jumpserver/jms_guacamole:1.5.7 (py3) [root@jump ~]# docker load -i jms_koko.tar.gz c5b8cecd9e70: Loading layer 156MB/156MB abcd3841e432: Loading layer 3.072kB/3.072kB 7051797ec5fe: Loading layer 3.072kB/3.072kB Loaded image: jumpserver/jms_koko:1.5.7
2.运行docker容器
http://
BOOTSTRAP_TOKEN 为 Jumpserver/config.yml 里面的 BOOTSTRAP_TOKEN
(py3) [root@jump ~]# docker run --name jms_koko -d -p 2222:2222 -p 127.0.0.1:5000:5000 -e CORE_HOST=http://10.0.0.111:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN -e LOG_LEVEL=ERROR --restart=always jumpserver/jms_koko:1.5.7 (py3) [root@jump ~]# docker run --name jms_guacamole -d -p 127.0.0.1:8081:8080 -e JUMPSERVER_SERVER=http://10.0.0.111:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN -e GUACAMOLE_LOG_LEVEL=ERROR --restart=always jumpserver/jms_guacamole:1.5.7
3.查看运行的docker容器
(py3) [root@jump ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 287e4712a284 jumpserver/jms_guacamole:1.5.7 "./entrypoint.sh" 7 seconds ago Up 6 seconds 127.0.0.1:8081->8080/tcp jms_guacamole 7aebb605711b jumpserver/jms_koko:1.5.7 "./entrypoint.sh" 14 seconds ago Up 12 seconds 0.0.0.0:2222->2222/tcp, 127.0.0.1:5000->5000/tcp jms_koko
八、安装web前端Luna
安装 Web Terminal 前端: Luna 需要 Nginx 来运行访问 访问(https://github.com/jumpserver/luna/releases)下载对应版本的 release 包, 直接解压, 不需要编译
(py3) [root@jump /opt]# wget https://demo.jumpserver.org/download/luna/1.5.8/luna.tar.gz (py3) [root@jump /opt]# tar xf luna.tar.gz (py3) [root@jump /opt]# chown -R root:root luna
九、配置Nginx整合各组件
1.删除默认的conf文件并编写个配置文件
(py3) [root@jump /opt]# rm -rf /etc/nginx/conf.d/default.conf (py3) [root@jump /opt]# vi /etc/nginx/conf.d/jumpserver.conf
将下面的server内容写入到jumpserver.conf文件
server { listen 80; # server_name _; client_max_body_size 100m; # 录像及文件上传大小限制 location /luna/ { try_files $uri / /index.html; alias /opt/luna/; # luna 路径, 如果修改安装目录, 此处需要修改 } location /media/ { add_header Content-Encoding gzip; root /opt/jumpserver/data/; # 录像位置, 如果修改安装目录, 此处需要修改 } location /static/ { root /opt/jumpserver/data/; # 静态资源, 如果修改安装目录, 此处需要修改 } location /koko/ { proxy_pass http://localhost:5000; proxy_buffering off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; } location /guacamole/ { proxy_pass http://localhost:8081/; proxy_buffering off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; } location /ws/ { proxy_pass http://localhost:8070; proxy_http_version 1.1; proxy_buffering off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; } location / { proxy_pass http://localhost:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; } }
2.检查并重启nginx服务
(py3) [root@jump /opt]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful (py3) [root@jump /opt]# systemctl restart nginx
十、测试连接JumpServer
1.shell终端连接JumpServer
(py3) [root@jump /opt]# ssh -p2222 admin@10.0.0.111 密码:admin
2.浏览器访问JumpServer
访问 http://10.0.0.111 (注意 没有 :8080 通过 nginx 代理端口进行访问)
默认账号: admin 密码: admin