开源堡垒机jumpserver的安装
开源跳板机jumpserver安装
简介
Jumpserver 是全球首款完全开源的堡垒机, 使用GNU GPL v2.0 开源协议, 是符合4A 的专业运维审计系统
Jumpserver 使用Python / Django 进行开发, 遵循Web 2.0 规范, 配备了业界领先的Web Terminal 解决方案, 交互界面美观、用户体验好。
Jumpserver 采纳分布式架构, 支持多机房跨区域部署, 中心节点提供API, 各机房部署登录节点, 可横向扩展、无并发访问限制。
Jumpserver 现已支持管理SSH、Telnet、RDP、VNC 协议资产。
github https://github.com/jumpserver/jumpserver
官方安装 http://docs.jumpserver.org/zh/docs/setup_by_centos.html
特点:
完全开源,GPL授权
Python编写,容易再次开发
实现了跳板机基本功能,认证、授权、审计
集成了Ansible,批量命令等
支持WebTerminal
Bootstrap编写,界面美观
自动收集硬件信息
录像回放
命令搜索
实时监控
批量上传下载
环境配置
服务器环境
- CPU: 4核
- 内存: 8G
- 数据库:mysql 5.6
- 系统:centos 7
- 内核:3.10.0-123.el7.x86_64
-
设置防火墙和selinux
-
设置字符集
setenforce 0 sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config # 修改字符集, 否则可能报input/output error的问题, 因为日志里打印了中文 localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 export LC_ALL=zh_CN.UTF-8 echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf
[admin@pe-jira ~]$ getenforce
Disabled
[admin@pe-jira ~]$ echo $LANG
zh_CN.UTF-8
[admin@pe-jira ~]$
依赖包
sudo yum -y install wget gcc epel-release git
安装 Python3.6
[admin@pe-jira ~]$ python -V
Python 3.6.0
[admin@pe-jira ~]$
yum -y install python36 python36-devel # 如果下载速度很慢, 可以换国内源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum -y install python36 python36-devel
建立 Python 虚拟环境
因为 CentOS 7 自带的是Python2, 而Yum 等工具依赖原来的Python, 为了不扰乱原来的环境我们来使用Python 虚拟环境
mkdir /home/admin/jumpserver cd /home/admin/jumpserver python3.6 -m venv py3 source /home/admin/jumpserver/py3/bin/activate # 看到下面的提示符代表成功, 以后运行 Jumpserver 都要先运行以上 source 命令, 以下所有命令均在该虚拟环境中运行(py3)
安装基础服务
下载或 Clone 项目
项目提交较多 git clone 时较大, 你可以选择去Github 项目页面直接下载zip包。
cd /home/admin/jumpserver/
git clone --depth=1 https://github.com/jumpserver/jumpserver.git
(py3) [admin@pe-jira py3]$ cd /home/admin/jumpserver/ (py3) [admin@pe-jira jumpserver]$ git clone --depth=1 https://github.com/jumpserver/jumpserver.git 正克隆到 'jumpserver'... remote: Enumerating objects: 1065, done. remote: Counting objects: 100% (1065/1065), done. remote: Compressing objects: 100% (928/928), done. remote: Total 1065 (delta 182), reused 610 (delta 80), pack-reused 0 接收对象中: 100% (1065/1065), 6.88 MiB | 530.00 KiB/s, done. 处理 delta 中: 100% (182/182), done. (py3) [admin@pe-jira jumpserver]$ (py3) [admin@pe-jira jumpserver]$ ls jumpserver py3 (py3) [admin@pe-jira jumpserver]$ cd jumpserver/ (py3) [admin@pe-jira jumpserver]$ ls apps config_example.yml Dockerfile entrypoint.sh LICENSE README_EN.md requirements tmp build.sh data docs jms logs README.md run_server.py utils
安装依赖 RPM 包
cd /home/admin/jumpserver/jumpserver/requirements/ sudo yum -y install $(cat rpm_requirements.txt)
安装 Python 库依赖
pip install --upgrade pip setuptools pip install -r requirements.txt # 如果下载速度很慢, 可以换国内源 $ pip install --upgrade pip setuptools -i https://mirrors.aliyun.com/pypi/simple/ $ pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
安装 Redis
Jumpserver 使用 Redis 做cache 和celery broke
我是编译安装的跳过啦
yum -y install redis
systemctl enable redis
systemctl start redis
安装 MySQL
我是编译安装的跳过啦
yum -y install mariadb mariadb-devel mariadb-server # centos7下安装的是mariadb systemctl enable mariadb systemctl start mariadb
创建数据库 Jumpserver 并授权
mysql> create database jumpserver default charset 'utf8'; grant all on jumpserver.* to 'jumpserver'@'10.6.76.27' identified by 'cGFrhxIA29ClqaTwrwhy5QqY'; flush privileges; Query OK, 1 row affected (0.08 sec) Query OK, 0 rows affected (0.07 sec) Query OK, 0 rows affected (0.01 sec) mysql> [admin@pe-jira redis]$ mysql -ujumpserver -pcGFrhxIA29ClqaTwrwhy5QqY -hpe-db Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 149213 Server version: 5.6.27-log Source distribution Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | jumpserver | +--------------------+ 2 rows in set (0.00 sec) mysql>
修改Jumpserver配置文件
SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50` # 生成随机SECRET_KEY echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16` # 生成随机BOOTSTRAP_TOKEN echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc sed -i "s/SECRET_KEY:/SECRET_KEY: $SECRET_KEY/g" /home/admin/jumpserver/jumpserver/config.yml sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /home/admin/jumpserver/jumpserver/config.yml sed -i "s/# DEBUG: true/DEBUG: false/g" /home/admin/jumpserver/jumpserver/config.yml sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" /home/admin/jumpserver/jumpserver/config.yml sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: false/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" /home/admin/jumpserver/jumpserver/config.yml sed -i "s/DB_PASSWORD: /DB_PASSWORD: $DB_PASSWORD/g" /home/admin/jumpserver/jumpserver/config.yml echo -e "\033[31m 你的SECRET_KEY是$SECRET_KEY \033[0m" echo -e "\033[31m 你的BOOTSTRAP_TOKEN是$BOOTSTRAP_TOKEN \033[0m"
#基于本文环境 /home/admin/jumpserver环境 (py3) [admin@pe-jira jumpserver]$ echo -e "\033[31m 你的SECRET_KEY是$SECRET_KEY \033[0m" 你的SECRET_KEY是Jhso2W3xhXdAVztxLNYileY8LyH5HSKLpweHFkcQeHqZ5RaImY (py3) [admin@pe-jira jumpserver]$ echo -e "\033[31m 你的BOOTSTRAP_TOKEN是$BOOTSTRAP_TOKEN \033[0m" 你的BOOTSTRAP_TOKEN是9vCcIq067Ir0Ay84 (py3) [admin@pe-jira jumpserver]$ (py3) [admin@pe-jira jumpserver]$ grep -v -E "^#|^$" config.yml SECRET_KEY: Jhso2W3xhXdAVztxLNYileY8LyH5HSKLpweHFkcQeHqZ5RaImY BOOTSTRAP_TOKEN: 9vCcIq067Ir0Ay84 DEBUG: false LOG_LEVEL: ERROR SESSION_EXPIRE_AT_BROWSER_CLOSE: true DB_ENGINE: mysql DB_HOST: pe-db DB_PORT: 3306 DB_USER: jumpserver DB_PASSWORD: cGFrhxIA29ClqaTwrwhy5QqY DB_NAME: jumpserver HTTP_BIND_HOST: 0.0.0.0 HTTP_LISTEN_PORT: 8082 REDIS_HOST: 127.0.0.1 REDIS_PORT: 6379 (py3) [admin@pe-jira jumpserver]$
config.yml文件说明
# SECURITY WARNING: keep the secret key used in production secret! # 加密秘钥生产环境中请修改为随机字符串, 请勿外泄 SECRET_KEY: # SECURITY WARNING: keep the bootstrap token used in production secret! # 预共享Token coco和guacamole用来注册服务账号, 不在使用原来的注册接受机制 BOOTSTRAP_TOKEN: # Development env open this, when error occur display the full process track, Production disable it # DEBUG 模式开启DEBUG后遇到错误时可以看到更多日志 DEBUG: false # DEBUG, INFO, WARNING, ERROR, CRITICAL can set. See https://docs.djangoproject.com/en/1.10/topics/logging/ # 日志级别 LOG_LEVEL: ERROR # LOG_DIR: # Session expiration setting, Default 24 hour, Also set expired on on browser close # 浏览器Session过期时间, 默认24小时, 也可以设置浏览器关闭则过期 # SESSION_COOKIE_AGE: 86400 SESSION_EXPIRE_AT_BROWSER_CLOSE: true # Database setting, Support sqlite3, mysql, postgres .... # 数据库设置 # See https://docs.djangoproject.com/en/1.10/ref/settings/#databases # SQLite setting: # 使用单文件sqlite数据库 # DB_ENGINE: sqlite3 # DB_NAME: # MySQL or postgres setting like: # 使用Mysql作为数据库 DB_ENGINE: mysql DB_HOST: 127.0.0.1 DB_PORT: 3306 DB_USER: jumpserver DB_PASSWORD: DB_NAME: jumpserver # When Django start it will bind this host and port # ./manage.py runserver 127.0.0.1:8080 # 运行时绑定端口 HTTP_BIND_HOST: 0.0.0.0 HTTP_LISTEN_PORT: 8080 # Use Redis as broker for celery and web socket # Redis配置 REDIS_HOST: 127.0.0.1 REDIS_PORT: 6379 # REDIS_PASSWORD: # REDIS_DB_CELERY: 3 # REDIS_DB_CACHE: 4 # Use OpenID authorization # 使用OpenID 来进行认证设置 # BASE_SITE_URL: http://localhost:8080 # AUTH_OPENID: false # True or False # AUTH_OPENID_SERVER_URL: https://openid-auth-server.com/ # AUTH_OPENID_REALM_NAME: realm-name # AUTH_OPENID_CLIENT_ID: client-id # AUTH_OPENID_CLIENT_SECRET: client-secret # OTP settings # OTP/MFA 配置 # OTP_VALID_WINDOW: 0 # OTP_ISSUER_NAME: Jumpserver
运行
cd /home/admin/jumpserver/jumpserver $ ./jms start all -d # 后台运行使用 -d 参数./jms start all -d # 新版本更新了运行脚本, 使用方式./jms start|stop|status all 后台运行请添加 -d 参数
安装 SSH Server 和 WebSocket Server: Coco
下载或 Clone 项目
cd /home/admin/jumpserver source /home/admin/jumpserver/py3/bin/activate git clone --depth=1 https://github.com/jumpserver/coco.git
安装依赖
cd /home/admin/jumpserver/coco/requirements sudo yum -y install $(cat rpm_requirements.txt) pip install -r requirements.txt # 如果下载速度很慢, 可以换国内源 #pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
修改配置文件并运行
cd /home/admin/jumpserver/coco cp config_example.yml config.yml sed -i "s/BOOTSTRAP_TOKEN: <PleasgeChangeSameWithJumpserver>/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /home/admin/jumpserver/coco/config.yml sed -i "s/# LOG_LEVEL: INFO/LOG_LEVEL: ERROR/g" /home/admin/jumpserver/coco/config.yml ./cocod start -d # 后台运行使用 -d 参数./cocod start -d # 新版本更新了运行脚本, 使用方式./cocod start|stop|status 后台运行请添加 -d 参数
(py3) [admin@pe-jira coco]$ grep -v -E "^#|^$" config.yml CORE_HOST: http://127.0.0.1:8082 BOOTSTRAP_TOKEN: 9vCcIq067Ir0Ay84 LOG_LEVEL: ERROR (py3) [admin@pe-jira coco]$ (py3) [admin@pe-jira coco]$ ./cocod start -d Use eventlet dispatch Start coco process (py3) [admin@pe-jira coco]$ ./cocod status Use eventlet dispatch Coco is running: 17595 (py3) [admin@pe-jira coco]$
config.yml文件说明
# 项目名称, 会用来向Jumpserver注册, 识别而已, 不能重复 # NAME: {{ Hostname }} # Jumpserver项目的url, api请求注册会使用 CORE_HOST: http://127.0.0.1:8080 # Bootstrap Token, 预共享秘钥, 用来注册coco使用的service account和terminal # 请和jumpserver 配置文件中保持一致, 注册完成后可以删除 BOOTSTRAP_TOKEN: <PleasgeChangeSameWithJumpserver> # 启动时绑定的ip, 默认 0.0.0.0 # BIND_HOST: 0.0.0.0 # 监听的SSH端口号, 默认2222 # SSHD_PORT: 2222 # 监听的HTTP/WS端口号, 默认5000 # HTTPD_PORT: 5000 # 项目使用的ACCESS KEY, 默认会注册, 并保存到 ACCESS_KEY_STORE中, # 如果有需求, 可以写到配置文件中, 格式 access_key_id:access_key_secret # ACCESS_KEY: null # ACCESS KEY 保存的地址, 默认注册后会保存到该文件中 # ACCESS_KEY_STORE: data/keys/.access_key # 加密密钥 # SECRET_KEY: null # 设置日志级别 [DEBUG, INFO, WARN, ERROR, FATAL, CRITICAL] LOG_LEVEL: ERROR # 日志存放的目录 # LOG_DIR: logs # SSH白名单 # ALLOW_SSH_USER: all # SSH黑名单, 如果用户同时在白名单和黑名单, 黑名单优先生效 # BLOCK_SSH_USER: # - # 和Jumpserver 保持心跳时间间隔 # HEARTBEAT_INTERVAL: 5 # Admin的名字, 出问题会提示给用户 # ADMINS: '' # SSH连接超时时间 (default 15 seconds) # SSH_TIMEOUT: 15 # 语言 [en, zh] # LANGUAGE_CODE: zh # SFTP的根目录, 可选 /tmp, Home其他自定义目录 # SFTP_ROOT: /tmp # SFTP是否显示隐藏文件 # SFTP_SHOW_HIDDEN_FILE: false
安装 Web Terminal 前端: Luna
Luna 已改为纯前端, 需要Nginx 来运行访问
访问(https://github.com/jumpserver/luna/releases)下载对应版本的release 包, 直接解压不需要编译
cd /home/admin/jumpserver wget https://github.com/jumpserver/luna/releases/download/1.4.10/luna.tar.gz tar xf luna.tar.gz rm –f luna.tar.gz # 如果网络有问题导致下载无法完成可以使用下面地址 #wget https://demo.jumpserver.org/download/luna/1.4.10/luna.tar.gz #tar xf luna.tar.gz #chown -R root:root luna
安装Windows 支持组件(我跳过了,只是记录)
(如果不需要管理 windows 资产, 可以直接跳过这一步)
安装依赖
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm yum -y localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm yum install -y java-1.8.0-openjdk libtool yum install -y cairo-devel libjpeg-turbo-devel libpng-devel uuid-devel yum install -y ffmpeg-devel freerdp-devel freerdp-plugins pango-devel libssh2-devel libtelnet-devel libvncserver-devel pulseaudio-libs-devel openssl-devel libvorbis-devel libwebp-devel ghostscript
编译安装guacamole服务
$ cd /opt $ git clone --depth=1 https://github.com/jumpserver/docker-guacamole.git $ cd /opt/docker-guacamole/ $ tar -xf guacamole-server-0.9.14.tar.gz $ cd guacamole-server-0.9.14 $ autoreconf -fi $ ./configure --with-init-dir=/etc/init.d $ make && make install $ ln -s /usr/local/lib/freerdp/*.so /usr/lib64/freerdp/ $ cd .. $ rm -rf guacamole-server-0.9.14 $ ldconfig
配置 Tomcat
$ mkdir -p /config/guacamole /config/guacamole/lib /config/guacamole/extensions # 创建 guacamole 目录 $ ln -sf /opt/docker-guacamole/guacamole-auth-jumpserver-0.9.14.jar /config/guacamole/extensions/guacamole-auth-jumpserver-0.9.14.jar $ ln -sf /opt/docker-guacamole/root/app/guacamole/guacamole.properties /config/guacamole/guacamole.properties # guacamole 配置文件 $ cd /config $ wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.40/bin/apache-tomcat-8.5.40.tar.gz $ tar xf apache-tomcat-8.5.40.tar.gz $ rm -rf apache-tomcat-8.5.40.tar.gz $ mv apache-tomcat-8.5.40 tomcat8 $ rm -rf /config/tomcat8/webapps/* $ ln -sf /opt/docker-guacamole/guacamole-0.9.14.war /config/tomcat8/webapps/ROOT.war # guacamole client $ sed -i 's/Connector port="8080"/Connector port="8081"/g' /config/tomcat8/conf/server.xml # 修改默认端口为 8081 $ sed -i 's/FINE/WARNING/g' /config/tomcat8/conf/logging.properties # 修改 log 等级为 WARNING $ cd /config $ wget https://github.com/ibuler/ssh-forward/releases/download/v0.0.5/linux-amd64.tar.gz # 如果网络有问题导致下载无法完成可以使用下面地址 $ wget https://demo.jumpserver.org/download/ssh-forward/v0.0.5/linux-amd64.tar.gz $ tar xf linux-amd64.tar.gz -C /bin/ $ chmod +x /bin/ssh-forward
配置环境变量
# 勿多次执行以下环境设置 $ export JUMPSERVER_SERVER=http://127.0.0.1:8080 # http://127.0.0.1:8080 指 jumpserver 访问地址 $ echo "export JUMPSERVER_SERVER=http://127.0.0.1:8080" >> ~/.bashrc # BOOTSTRAP_TOKEN 为 Jumpserver/config.yml 里面的 BOOTSTRAP_TOKEN $ export BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN $ echo "export BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc $ export JUMPSERVER_KEY_DIR=/config/guacamole/keys $ echo "export JUMPSERVER_KEY_DIR=/config/guacamole/keys" >> ~/.bashrc $ export GUACAMOLE_HOME=/config/guacamole $ echo "export GUACAMOLE_HOME=/config/guacamole" >> ~/.bashrc
启动 Guacamole
/etc/init.d/guacd start
sh /config/tomcat8/bin/startup.sh
配置 Nginx 整合各组件
安装Nginx
我是编译安装的tengine 跳过
$ yum install yum-utils $ vi /etc/yum.repos.d/nginx.repo [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key $ yum makecache fast $ yum install -y nginx $ rm -rf /etc/nginx/conf.d/default.conf $ systemctl enable nginx
准备配置文件
server { listen 80; # 代理端口, 以后将通过此端口进行访问, 不再通过8080端口 server_name jumpserver.corp.*****.com; # 修改成你的域名或者注释掉 client_max_body_size 100m; # 录像及文件上传大小限制 location /luna/ { try_files $uri / /index.html; alias /home/admin/jumpserver/luna/; # luna 路径, 如果修改安装目录, 此处需要修改 } location /media/ { add_header Content-Encoding gzip; root /home/admin/jumpserver/jumpserver/data/; # 录像位置, 如果修改安装目录, 此处需要修改 } location /static/ { root /home/admin/jumpserver/jumpserver/data/; # 静态资源, 如果修改安装目录, 此处需要修改 } location /socket.io/ { proxy_pass http://localhost:5000/socket.io/; # 如果coco安装在别的服务器, 请填写它的ip 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 /coco/ { proxy_pass http://localhost:5000/coco/; # 如果coco安装在别的服务器, 请填写它的ip 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/; # 如果guacamole安装在别的服务器, 请填写它的ip # 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 / { proxy_pass http://localhost:8082; # 如果jumpserver安装在别的服务器, 请填写它的ip proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
运行/重启Nginx
打开页面
默认账号: admin 密码: admin
到Jumpserver 会话管理-终端管理检查Coco Guacamole 等应用的注册。
测试连接
如果登录客户端是 macOS 或 Linux, 登录语法如下
$ ssh -p2222 admin@192.168.244.144
$ sftp -P2222 admin@192.168.244.144
密码: admin
如果登录客户端是 Windows, Xshell Terminal 登录语法如下
$ ssh admin@192.168.244.144 2222
$ sftp admin@192.168.244.144 2222
密码: admin
如果能登陆代表部署成功
# sftp默认上传的位置在资产的 /tmp 目录下
# windows拖拽上传的位置在资产的 Guacamole RDP上的 G 目录下