jumpserver开源堡垒机部署安装

0x01.前言

Jumpserver 是全球首款完全开源的堡垒机,使用 GNU GPL v2.0 开源协议,是符合 4A 的专业运维审计系统。

Jumpserver 使用 Python / Django 进行开发,遵循 Web 2.0 规范,配备了业界领先的 Web Terminal 解决方案,交互界面美观、用户体验好。

Jumpserver 采纳分布式架构,支持多机房跨区域部署,中心节点提供 API,各机房部署登录节点,可横向扩展、无并发访问限制。

改变世界,从一点点开始。

 

0x02.部署安装

 

#!/bin/bash

# 防火墙 与 selinux 设置说明,如果已经关闭了 防火墙 和 Selinux 的用户请跳过设置
systemctl start firewalld
# nginx 端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 用户SSH登录端口 coco  
firewall-cmd --zone=public --add-port=2222/tcp --permanent  

# 重新载入规则
firewall-cmd --reload  

# 设置 selinux 允许 http 访问
setsebool -P httpd_can_network_connect 1  
mkdir -p /opt/guacamole/key
# 设置 selinux 允许容器对目录读写
chcon -Rt svirt_sandbox_file_t /opt/guacamole/key  

# 修改字符集,否则可能报 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

# 安装依赖包
yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git

# 安装 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke
yum -y install redis
systemctl enable redis
systemctl start redis

# 安装 MySQL,如果不使用 Mysql 可以跳过相关 Mysql 安装和配置,支持sqlite3, mysql, postgres等
# centos7下叫mariadb,用法与mysql一致
yum -y install mariadb mariadb-devel mariadb-server 
systemctl enable mariadb
systemctl start mariadb
# 创建数据库 Jumpserver 并授权
mysql -uroot
> create database jumpserver default charset 'utf8';
> grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by 'weakPassword';
> flush privileges;

# 安装 Nginx ,用作代理服务器整合 Jumpserver 与各个组件
yum -y install nginx
systemctl enable nginx

# 下载编译 Python3.6.1
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
tar xvf Python-3.6.1.tar.xz  && cd Python-3.6.1
./configure && make && make install

# 配置并载入 Python3 虚拟环境
cd /opt
python3 -m venv py3  # py3 为虚拟环境名称,可自定义
source /opt/py3/bin/activate  # 退出虚拟环境可以使用 deactivate 命令

# 看到下面的提示符代表成功,以后运行 Jumpserver 都要先运行以上 source 命令,载入环境后默认以下所有命令均在该虚拟环境中运行
(py3) [root@localhost py3]

# 自动载入 Python3 虚拟环境
cd /opt
git clone https://github.com/kennethreitz/autoenv.git
echo 'source /opt/autoenv/activate.sh' >> ~/.bashrc
source ~/.bashrc

# 下载 Jumpserver 与 Coco
cd /opt/
git clone https://github.com/jumpserver/jumpserver.git && cd jumpserver && git checkout master && git pull
echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env  # 进入 jumpserver 目录时将自动载入 python 虚拟环境

cd /opt/
git clone https://github.com/jumpserver/coco.git && cd coco && git checkout master && git pull
echo "source /opt/py3/bin/activate" > /opt/coco/.env  # 进入 coco 目录时将自动载入 python 虚拟环境

# 安装依赖 RPM 包
yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt)
yum -y install $(cat /opt/coco/requirements/rpm_requirements.txt)

# 安装 Python 库依赖
pip install --upgrade pip
pip install -r /opt/jumpserver/requirements/requirements.txt
pip install -r /opt/coco/requirements/requirements.txt

# 安装 Web Terminal 前端: Luna  需要 Nginx 来运行访问 访问(https://github.com/jumpserver/luna/releases)下载对应版本的 release 包,直接解压,不需要编译
cd /opt
wget https://github.com/jumpserver/luna/releases/download/1.4.3/luna.tar.gz
tar xvf luna.tar.gz
chown -R root:root luna

# 安装 Windows 支持组件(如果不需要管理 windows 资产,可以直接跳过这一步)
yum remove docker-latest-logrotate docker-logrotate docker-selinux dockdocker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache fast
yum install docker-ce
systemctl start docker
docker pull jumpserver/guacamole:latest

 

# 修改 Jumpserver 配置文件
cd /opt/jumpserver
cp config_example.py config.py
vi config.py

修改数据库连接方式:

DB_ENGINE = os.environ.get("DB_ENGINE") or 'mysql'
DB_HOST = os.environ.get("DB_HOST") or '127.0.0.1'
DB_PORT = os.environ.get("DB_PORT") or 3306
DB_USER = os.environ.get("DB_USER") or 'jumpserver'
DB_PASSWORD = os.environ.get("DB_PASSWORD") or 'weakPassword'
DB_NAME = os.environ.get("DB_NAME") or 'jumpserver'


# 修改 Coco 配置文件
cd /opt/coco
mkdir keys logs
cp conf_example.py conf.py
vi conf.py


修改其中两项:

NAME = "coco"
CORE_HOST = 'http://127.0.0.1:8080'

  

# 配置 Nginx 整合各组件
$ vim /etc/nginx/conf.d/jumpserver.conf

server {
    listen 80;

    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 /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/;
        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/;  # 如果docker安装在别的服务器, 请填写它的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:8080;  # 如果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;
    }
}

  

# 生成数据库表结构和初始化数据
$ cd /opt/jumpserver/utils
$ bash make_migrations.sh

# 运行 Jumpserver
$ cd /opt/jumpserver
$ ./jms start all  # 后台运行使用 -d 参数./jms start all -d
# 新版本更新了运行脚本,使用方式./jms start|stop|status|restart all  后台运行请添加 -d 参数

# 运行 Coco
$ cd /opt/coco
$ ./cocod start  # 后台运行使用 -d 参数./cocod start -d
# 新版本更新了运行脚本,使用方式./cocod start|stop|status|restart  后台运行请添加 -d 参数

# 运行 Guacamole
# 注意:这里需要修改下 http://<填写jumpserver的url地址> 例: http://192.168.244.144:8080 或 http://192.168.244.144 不能使用 127.0.0.1
$ 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://<填写jumpserver的url地址> \
    jumpserver/guacamole:latest
# docker 重启容器的方法docker restart jms_guacamole

# 运行 Nginx
$ nginx -t   # 确保配置没有问题, 有问题请先解决
$ systemctl start nginx

# 访问 http://192.168.244.144 (注意,没有 :8080,通过 nginx 代理端口进行访问)
# 默认账号: admin 密码: admin  到会话管理-终端管理 接受 Coco Guacamole 等应用的注册
# 测试连接
$ 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 目录下

# 其他的ssh及sftp客户端这里就不多做说明,自行搜索使用

 

# 生成数据库表结构和初始化数据
cd /opt/jumpserver/utils
bash make_migrations.sh

# 运行 Jumpserver
cd /opt/jumpserver
./jms start all  # 后台运行使用 -d 参数./jms start all -d
# 新版本更新了运行脚本,使用方式./jms start|stop|status|restart all  后台运行请添加 -d 参数

# 运行 Coco
cd /opt/coco
./cocod start  # 后台运行使用 -d 参数./cocod start -d
# 新版本更新了运行脚本,使用方式./cocod start|stop|status|restart  后台运行请添加 -d 参数

# 运行 Guacamole
# 注意:这里需要修改下 http://<填写jumpserver的url地址> 例: http://192.168.244.144:8080 或 http://192.168.244.144 不能使用 127.0.0.1
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://<填写jumpserver的url地址> \
    jumpserver/guacamole:latest
# docker 重启容器的方法docker restart jms_guacamole

# 运行 Nginx
nginx -t   # 确保配置没有问题, 有问题请先解决
systemctl start nginx

# 访问 http://192.168.244.144 (注意,没有 :8080,通过 nginx 代理端口进行访问)
# 默认账号: admin 密码: admin  到会话管理-终端管理 接受 Coco Guacamole 等应用的注册
# 测试连接
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 目录下

# 其他的ssh及sftp客户端这里就不多做说明,自行搜索使用

 

0x03界面操作

 

 

 

 

 

 

 

 

 

  

posted @ 2018-10-26 10:29  轻落语  阅读(471)  评论(0编辑  收藏  举报