前言
我们对堡垒机(跳板机)不会陌生,为了保证服务器安全,加个堡垒机,所有ssh连接都通过堡垒机来完成,堡垒机也需要有身份认证、授权、访问控制、审计等功能。
Jumpserver 是全球首款完全开源的堡垒机, 是符合 4A 的专业运维审计系统。
Jumpserver 使用 Python / Django 进行开发, 采纳分布式架构, 支持多机房跨区域部署, 中心节点提供 API, 各机房部署登录节点, 可横向扩展、无并发访问限制。
Jumpserver 现已支持管理 SSH、 Telnet、 RDP、 VNC 协议资产。
架构说明
架构示意图如下:
Jumpserver包含四个组件,各个组件的作用如下:
? Jumpserver 为管理后台, 管理员可以通过 Web 页面进行资产管理、用户管理、资产授权等操作, 用户可以通过 Web 页面进行资产登录, 文件管理等操作
? Coco 为 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 来访问)
端口说明
各个组件的监听端口如下:
? Jumpserver 默认端口为 8080/tcp 配置文件 jumpserver/config.yml
? Coco 默认 SSH 端口为 2222/tcp, 默认 Web Terminal 端口为 5000/tcp 配置文件在 coco/config.yml
? Guacamole 默认端口为 8081/tcp, 配置文件 /config/tomcat8/conf/server.xml
? Nginx 默认端口为 80/tcp
? Redis 默认端口为 6379/tcp
? Mysql 默认端口为 3306/tcp
这篇博文将采用一站式的方式部署Jumpserver,其实更建议取参考官方文档部署Jumpserver。
博文大纲:
一、环境准备
二、配置Python 3环境
三、安装Jumpserver
四、安装MySQL及Redis
五、安装配置coco组件
六、安装guacamole及luna
七、安装Nginx
八、Client访问测试
一、环境准备
? 系统:CentOS 7
? IP:192.168.20.3
? 数据库:mariadb
? 反向代理:nginx
注:若是测试环境,内存最少4G,双核CPU。
在进行下面的操作前,请下载我提供的各个源码包。
首先将环境字体设置成中文,因为jumpserver的日志文件里面的内容会包含中字符,不支持可能会乱码。
[[email protected] ~]# localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8
[[email protected] ~]# export LC_ALL=zh_CN.UTF-8
[[email protected] ~]# echo ‘LC_ALL=zh_CN.UTF-8‘ > /etc/locale.conf
二、配置Python 3环境
[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected] ~]# yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git
[[email protected] ~]# tar xf Python-3.6.1.tar.xz -C /usr/src
[[email protected] ~]# cd /usr/src/Python-3.6.1/
[[email protected] Python-3.6.1]# ./configure && make && make install
[[email protected] Python-3.6.1]# cd /opt
[[email protected] opt]# python3 -m venv py3
[[email protected] opt]# source /opt/py3/bin/activate
#设置自动载入py3虚拟环境(以后只要进入这个目录就是Py3的环境)
(py3) [[email protected] opt]# unzip autoenv.zip
(py3) [[email protected] opt]# echo "source /opt/autoenv/activate.sh" >> /root/.bashrc
(py3) [[email protected] opt]# . ~/.bashrc
三、安装Jumpserver
(py3) [[email protected] opt]# unzip jumpserver.zip
(py3) [[email protected] opt]# echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env
(py3) [[email protected] opt]# cd jumpserver/
autoenv:
autoenv: WARNING:
autoenv: This is the first time you are about to source /opt/jumpserver/.env:
autoenv:
autoenv: --- (begin contents) ---------------------------------------
autoenv: source /opt/py3/bin/activate$
autoenv:
autoenv: --- (end contents) -----------------------------------------
autoenv:
autoenv: Are you sure you want to allow this? (y/N) y #这里输入“y”,以便自动载入py3环境
(py3) [[email protected] jumpserver]# cd requirements/
(py3) [[email protected] requirements]# yum -y install $(cat rpm_requirements.txt)
(py3) [[email protected] requirements]# pip install --upgrade pip
(py3) [[email protected] requirements]# pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
四、安装MySQL及Redis
#安装MySQL
(py3) [[email protected] requirements]# yum -y install mariadb*
(py3) [[email protected] requirements]# systemctl start mariadb
(py3) [[email protected] requirements]# mysqladmin -u root password 123.com
(py3) [[email protected] requirements]# mysql -u root -p123.com
MariaDB [(none)]> create database jumpserver default charset ‘utf8‘ ;
MariaDB [(none)]> grant all on jumpserver.* to [email protected] identified by ‘123.com‘;
#安装Redis
(py3) [[email protected] ~]# yum -y install redis
(py3) [[email protected] ~]# systemctl start redis
(py3) [[email protected] ~]# netstat -anput | grep 6379
#修改jumpserver配置文件
(py3) [[email protected] ~]# cd /opt/jumpserver/
(py3) [[email protected] jumpserver]# cp config_example.yml config.yml
#生成秘钥令牌
(py3) [[email protected] jumpserver]# SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50`
(py3) [[email protected] jumpserver]# echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc
(py3) [[email protected] jumpserver]# BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16`
(py3) [[email protected] jumpserver]# echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc
(py3) [[email protected] jumpserver]# sed -i "s/SECRET_KEY:/SECRET_KEY: $SECRET_KEY/g" /opt/jumpserver/config.yml
(py3) [[email protected] jumpserver]# sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /opt/jumpserver/config.yml
(py3) [[email protected] jumpserver]# sed -i "s/# DEBUG: true/DEBUG: false/g" /opt/jumpserver/config.yml
(py3) [[email protected] jumpserver]# sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" /opt/jumpserver/config.yml
(py3) [[email protected] jumpserver]# sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: False/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" /opt/jumpserver/config.yml
(py3) [[email protected] jumpserver]# sed -i "s/DB_PASSWORD: /DB_PASSWORD: 123.com/g" /opt/jumpserver/config.yml
(py3) [[email protected] jumpserver]# echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m"
你的SECRET_KEY是 Z6bUvXTZRpc73pnRp4qNwn1eMWNYrgzbEWkVJqIVXc6cXfpKDU
(py3) [[email protected] jumpserver]# echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m"
你的BOOTSTRAP_TOKEN是 aGXZtXKnhP3StNA3
(py3) [[email protected] jumpserver]# egrep -v ‘^$|^#‘ config.yml #确定配置文件修改无误
SECRET_KEY: jS1ph0yvliBHdMV7YopAkBrEdIkZ3DjAq6HsftIPpQriNNBO2k
BOOTSTRAP_TOKEN: fUXgq00wg6XCD5lp
DEBUG: false
LOG_LEVEL: ERROR
SESSION_EXPIRE_AT_BROWSER_CLOSE: true
DB_ENGINE: mysql
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_USER: jumpserver
DB_PASSWORD: 123.com
DB_NAME: jumpserver
HTTP_BIND_HOST: 0.0.0.0
HTTP_LISTEN_PORT: 8080
REDIS_HOST: 127.0.0.1
REDIS_PORT: 6379
(py3) [[email protected] jumpserver]# ./jms start all -d #启动jumpserver
(py3) [[email protected]server jumpserver]# netstat -anpt | grep 8080
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 17420/python3
五、安装配置coco组件
(py3) [[email protected] opt]# unzip coco.zip
(py3) [[email protected] opt]# cd coco
(py3) [[email protected] coco]# echo "source /opt/py3/bin/activate" > /opt/coco/.env
(py3) [[email protected] coco]# cd requirements/
autoenv:
autoenv: WARNING:
autoenv: This is the first time you are about to source /opt/coco/.env:
autoenv:
autoenv: --- (begin contents) ---------------------------------------
autoenv: source /opt/py3/bin/activate$
autoenv:
autoenv: --- (end contents) -----------------------------------------
autoenv:
autoenv: Are you sure you want to allow this? (y/N) y #输入“y”
(py3) [[email protected] requirements]# yum -y install $(cat rpm_requirements.txt)
(py3) [[email protected] requirements]# pip install -r requirements.txt
#修改配置文件
(py3) [[email protected] requirements]# cd ..
(py3) [[email protected] coco]# cp config_example.yml config.yml
(py3) [[email protected] coco]# echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m"
#查看BOOTSTRAP_TOKEN的值
你的BOOTSTRAP_TOKEN是 fUXgq00wg6XCD5lp
#注意,执行下面的命令时,需要自行修改为自己查看出来的值:
(py3) [[email protected] coco]# sed -i ‘s/BOOTSTRAP_TOKEN: <PleasgeChangeSameWithJumpserver>/BOOTSTRAP_TOKEN: fUXgq00wg6XCD5lp/g‘ config.yml
(py3) [[email protected] coco]# sed -i ‘s/# LOG_LEVEL: INFO/LOG_LEVEL: ERROR/g‘ config.yml
(py3) [[email protected] coco]# egrep -v ‘^$|^#‘ config.yml #确定修改的配置文件
CORE_HOST: http://127.0.0.1:8080
BOOTSTRAP_TOKEN: fUXgq00wg6XCD5lp
LOG_LEVEL: ERROR
#后台启动coco
(py3) [[email protected] coco]# ./cocod start -d
六、安装guacamole及luna
这里采用docker容器的方式部署。
#部署docker环境
(py3) [[email protected] ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
(py3) [[email protected] ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
(py3) [[email protected] ~]# yum makecache fast
(py3) [[email protected] ~]# yum -y install docker-ce
(py3) [[email protected] ~]# systemctl start docker
(py3) [[email protected] ~]# docker load --input guacamole.tar
#启动容器
(py3) [[email protected] ~]# docker run --name jms_guacamole -d -p 8081:8080 -v /opt/guacamole/key:/config/guacamole/key -e JUMPSERVER_KEY_DIR=/config/guacamole/key -e JUMPSERVER_SERVER=http://192.168.10.8:8080 jumpserver/guacamole:latest
(py3) [[email protected] ~]# netstat -anput | grep 8081 #确定端口在监听
tcp6 0 0 :::8081 :::* LISTEN 19162/docker-proxy
(py3) [[email protected] ~]# tar zxf luna.tar.gz -C /opt/ #将luna解压至/opt
七、安装Nginx
(py3) [[email protected] /]# tar zxf nginx-1.2.4.tar.gz -C /usr/src
(py3) [[email protected] /]# cd /usr/src/nginx-1.2.4/
(py3) [[email protected] nginx-1.2.4]# ./configure --prefix=/usr/local/nginx && make && make install
(py3) [[email protected] nginx-1.2.4]# ln -sf /usr/local/nginx/sbin/nginx /usr/local/bin/
(py3) [[email protected] nginx-1.2.4]# cd /usr/local/nginx/conf/
(py3) [[email protected] conf]# mv nginx.conf nginx.conf.bak
(py3) [[email protected] conf]# rz #上传我提供的Nginx配置文件
(py3) [[email protected] conf]# ls | grep nginx.conf
nginx.conf #在博文开头的网盘链接中有此文件
nginx.conf.bak
nginx.conf.default
(py3) [[email protected] conf]# nginx -t #确定Nginx配置无误
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
(py3) [[email protected] conf]# nginx #启动Nginx
八、Client访问测试
访问Nginx服务器的IP地址,即可看到登录页面(默认用户名及密码都是“admin”):
1、创建用户
2、创建管理用户
3、创建系统用户
用户名尽量为root,选择手动登录,这个用户是用来连接后端资产的。
4、创建资产
我这里启动了一台IP为192.168.20.4的主机来作为后端资产,以便测试。
5、创建授权规则
6、连接后端资产测试
原文地址:https://blog.51cto.com/14306186/2472467