[工作随笔]JumpServer排坑安装及二次开发

2022-10-31 17:51:33 浏览数 (1)


环境要求

代码语言:javascript复制
硬件配置: 2个CPU核心, 4G 内存, 50G 硬盘(最低)
操作系统: Linux 发行版 x86_64

Python = 3.6.x
Mysql Server ≥ 5.6
Mariadb Server ≥ 5.5.56
Redis

安装并配置MySQL

1.安装MySQL

代码语言:javascript复制
## 方法一:
yum install -y mariadb-server

## 方法二:二进制安装MySQL请看博客的MySQL第一章
## 本人选择的是二进制安装MySQL

2.修改配置

代码语言:javascript复制
[mysqld]
datadir = /application/mysql/data
basedir = /application/mysql
log-bin = mysql-bin
server-id = 1
skip_name_resolve
binlog_format = row
character_set_server = utf8
[client]
user = root
password = 123

3.创建jumpserver数据库以及用户

代码语言:javascript复制
## 创建jumpserver库
mysql> create database jumpserver default charset 'utf8' collate 'utf8_bin';

## 创建jumpserver用户
mysql> grant all on jumpserver.* to jumpserver@'127.0.0.1' identified by 'jumpserver';

安装配置Redis

代码语言:javascript复制
## 安装redis
yum install -y redis

## 配置redis,将监听ip原来:127.0.0.1修改成0.0.0.0
bind 0.0.0.0

安装Python环境

代码语言:javascript复制
## 下载epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

## 安装python环境
yum install -y python36-devel

python虚拟环境

代码语言:javascript复制
## 创建虚拟环境
python3.6 -m venv /opt/py3

## 载入虚拟环境
source /opt/py3/bin/activate

获取jumpserver代码

代码语言:javascript复制
## 进入opt目录
cd /opt

## 下载jumpserver源码,可以从我的下载站点下,比github快,想要下载的可以联系微信:z133411023
wget -O jumpserver.tar.gz https://github.com/jumpserver/jumpserver/archive/2.0.1.tar.gz

## 解压
tar xf jumpserver.tar.gz

## 改名
mv jumpserver-2.0.1 jumpserver

安装编译依赖

代码语言:javascript复制
## 进入目录
cd /opt/jumpserver/requirements

## Linux安装依赖包
yum install -y $(cat rpm_requirements.txt)

## Python安装模块
pip3.6 install wheel
pip3.6 install --upgrade pip setuptools
pip3.6 install -r requirements.txt


##### 建议使用阿里云的pypi源,国外源,太特么的慢了
pip install wheel -i https://mirrors.aliyun.com/pypi/simple/
pip install --upgrade pip setuptools -i https://mirrors.aliyun.com/pypi/simple/
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

修改配置文件

代码语言:javascript复制
## 进入目录
cd /opt/jumpserver

## 拷贝配置文件并改名
cp config_example.yml config.yml

## 生成随机码
cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 49;echo
W5Ic3fMXNZ0p5RIy5DhJYJllppTfcfkW8Yuf94VBMfpcssbfu

## 修改配置文件
vim config.yml
# SECURITY WARNING: keep the secret key used in production secret!
# 加密秘钥 生产环境中请修改为随机字符串,请勿外泄, 可使用命令生成
# cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 49;echo
SECRET_KEY: W5Ic3fMXNZ0p5RIy5DhJYJllppTfcfkW8Yuf94VBMfpcssbfu

# SECURITY WARNING: keep the bootstrap token used in production secret!
# 预共享Token coco和guacamole用来注册服务账号,不在使用原来的注册接受机制
BOOTSTRAP_TOKEN: zxffNymGjP79j6BN

# 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: jumpserver
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
WS_LISTEN_PORT: 8070

# Use Redis as broker for celery and web socket
# Redis配置
REDIS_HOST: 127.0.0.1
REDIS_PORT: 6379
REDIS_PASSWORD: ZhYnLrodpmPncovxJTnRyiBs
# 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
# AUTH_OPENID_IGNORE_SSL_VERIFICATION: True
# AUTH_OPENID_SHARE_SESSION: True

# Use Radius authorization
# 使用Radius来认证
# AUTH_RADIUS: false
# RADIUS_SERVER: localhost
# RADIUS_PORT: 1812
# RADIUS_SECRET:

# CAS 配置
# AUTH_CAS': False,
# CAS_SERVER_URL': "http://host/cas/",
# CAS_ROOT_PROXIED_AS': 'http://jumpserver-host:port',  
# CAS_LOGOUT_COMPLETELY': True,
# CAS_VERSION': 3,

# LDAP/AD settings
# LDAP 搜索分页数量
# AUTH_LDAP_SEARCH_PAGED_SIZE: 1000
#
# 定时同步用户
# 启用 / 禁用
# AUTH_LDAP_SYNC_IS_PERIODIC: True
# 同步间隔 (单位: 时) (优先)
# AUTH_LDAP_SYNC_INTERVAL: 12
# Crontab 表达式
# AUTH_LDAP_SYNC_CRONTAB: * 6 * * *
#
# LDAP 用户登录时仅允许在用户列表中的用户执行 LDAP Server 认证
# AUTH_LDAP_USER_LOGIN_ONLY_IN_USERS: False
#
# LDAP 认证时如果日志中出现以下信息将参数设置为 0 (详情参见:https://www.python-ldap.org/en/latest/faq.html)
# In order to perform this operation a successful bind must be completed on the connection
# AUTH_LDAP_OPTIONS_OPT_REFERRALS: -1

# OTP settings
# OTP/MFA 配置
# OTP_VALID_WINDOW: 0
# OTP_ISSUER_NAME: Jumpserver

# Perm show single asset to ungrouped node
# 是否把未授权节点资产放入到 未分组 节点中
# PERM_SINGLE_ASSET_TO_UNGROUP_NODE: false
#
# 启用定时任务
# PERIOD_TASK_ENABLE: True
#
# 启用二次复合认证配置
# LOGIN_CONFIRM_ENABLE: False
#
# Windows 登录跳过手动输入密码
WINDOWS_SKIP_ALL_MANUAL_PASSWORD: True

启动jumpserver

代码语言:javascript复制
## 进入目录
cd /opt/jumpserver

## 放入后台启动
./jms start -d

部署koko

koko是用来连接Linux服务器的跳板机,原来用python写的,现在用go重写的

代码语言:javascript复制
## 进入opt
cd /opt

## 下载koko源码,可以从我的下载站点下,比github快,想要下载的可以联系微信:z133411023
wget https://github.com/jumpserver/koko/releases/download/2.0.1/koko-master-linux-amd64.tar.gz

## 解压koko
tar -xf koko-master-linux-amd64.tar.gz

## 给解压出来的目录授权
chown -R root:root kokodir

## 进入目录
cd kokodir

## 拷贝配置文件并改名
cp config_example.yml config.yml

## 编辑配置文件(下面全都是配置文件内容)
vi 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: zxffNymGjP79j6BN

# 启动时绑定的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_FILE: data/keys/.access_key

# 设置日志级别 [DEBUG, INFO, WARN, ERROR, FATAL, CRITICAL]
LOG_LEVEL: ERROR

# SSH连接超时时间 (default 15 seconds)
# SSH_TIMEOUT: 15

# 语言 [en,zh]
# LANG: zh

# SFTP的根目录, 可选 /tmp, Home其他自定义目录
# SFTP_ROOT: /tmp

# SFTP是否显示隐藏文件
# SFTP_SHOW_HIDDEN_FILE: false

# 是否复用和用户后端资产已建立的连接(用户不会复用其他用户的连接)
# REUSE_CONNECTION: true

# 资产加载策略, 可根据资产规模自行调整. 默认异步加载资产, 异步搜索分页; 如果为all, 则资产全部加载, 本地搜索分页.
# ASSET_LOAD_POLICY:

# zip压缩的最大额度 (单位: M)
# ZIP_MAX_SIZE: 1024M

# zip压缩存放的临时目录 /tmp
# ZIP_TMP_PATH: /tmp

# 向 SSH Client 连接发送心跳的时间间隔 (单位: 秒),默认为30, 0则表示不发送
# CLIENT_ALIVE_INTERVAL: 30

# 向资产发送心跳包的重试次数,默认为3
# RETRY_ALIVE_COUNT_MAX: 3

# 会话共享使用的类型 [local, redis], 默认local
SHARE_ROOM_TYPE: redis

# Redis配置
REDIS_HOST: 127.0.0.1
REDIS_PORT: 6379
# REDIS_PASSWORD: ZhYnLrodpmPncovxJTnRyiBs
# REDIS_CLUSTERS:
REDIS_DB_ROOM: 6

启动koko

代码语言:javascript复制
./koko -d

部署Guacamole

Guacamole是用来连接windows的,是apache的软件,官方文档:TP

代码语言:javascript复制
## 进入opt
cd /opt

## 下载Guacamole源码,可以从我的下载站点下,比github快,想要下载的可以联系微信:z133411023
wget -O /opt/guacamole.tar.gz https://github.com/jumpserver/docker-guacamole/archive/2.0.1.tar.gz

## 解压
tar -xf guacamole.tar.gz

## 改名
mv docker-guacamole-2.0.1 guacamole

## 进入目录
cd /opt/guacamole

## 解压guacamole-server
tar -xf guacamole-server-1.0.0.tar.gz

## 解压ssh-forward命令到/bin/目录下
tar -xf ssh-forward.tar.gz -C /bin/

## 添加执行权限
chmod  x /bin/ssh-forward

## 进入guacamole-server目录
cd /opt/guacamole/guacamole-server-1.0.0

## 安装依赖
yum -y localinstall --nogpgcheck https://mirrors.aliyun.com/rpmfusion/free/el/rpmfusion-free-release-7.noarch.rpm https://mirrors.aliyun.com/rpmfusion/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm


yum install -y cairo-devel libjpeg-turbo-devel libpng-devel uuid-devel ffmpeg-devel freerdp1.2-devel pango-devel libssh2-devel libtelnet-devel libvncserver-devel pulseaudio-libs-devel openssl-devel libvorbis-devel libwebp-devel cairo cairo-devel automake libtool uuid uuid-devel

## 做软连接
ln -s /usr/lib64/freerdp /usr/local/lib/freerdp

## 编译安装
autoreconf -fi

## 生成
./configure --with-init-dir=/etc/init.d

## 编译 && 安装
make && make install

安装Java环境

代码语言:javascript复制
## 安装jdk
yum install -y java-1.8.0-openjdk

## 创建目录
mkdir -p /config/guacamole{extensions,record,drive} 

## 授权
chown daemon:daemon /config/guacamole/{record,drive}

## 进入目录
cd /config

## 下载tomcat9,如果没有就去清华源,自己找http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/

wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.35/bin/apache-tomcat-9.0.35.tar.gz

## 解压
tar -xf apache-tomcat-9.0.35.tar.gz

## 改名
mv apache-tomcat-9.0.35 tomcat9

## 删除站点目录下的所有东西
rm -rf /config/tomcat9/webapps/* 

## 修改server.xml文件
sed -i 's/Connector port="8080"/Connector port="8081"/g' /config/tomcat9/conf/server.xml

## 添加字符集
echo "java.util.logging.ConsoleHandler.encoding = UTF-8" >> /config/tomcat9/conf/logging.properties

## 软连接
ln -sf /opt/guacamole/guacamole-1.0.0.war /config/tomcat9/webapps/ROOT.war

ln -sf /opt/guacamole/guacamole-auth-jumpserver-1.0.0.jar /config/guacamole/extensions/guacamole-auth-jumpserver-1.0.0.jar

ln -sf /opt/guacamole/root/app/guacamole/guacamole.properties /config/guacamole/guacamole.properties

## 设置环境变量
# JUMPSERVER_SERVER 指 core 访问地址
export JUMPSERVER_SERVER=http://127.0.0.1:8080
echo "export JUMPSERVER_SERVER=http://127.0.0.1:8080" >> ~/.bashrc

# BOOTSTRAP_TOKEN 为 Jumpserver/config.yml 里面的 BOOTSTRAP_TOKEN 值
export BOOTSTRAP_TOKEN=zxffNymGjP79j6BN
echo "export BOOTSTRAP_TOKEN=zxffNymGjP79j6BN" >> ~/.bashrc

# JUMPSERVER_KEY_DIR 认证成功后 key 存放目录
export JUMPSERVER_KEY_DIR=/config/guacamole/keys
echo "export JUMPSERVER_KEY_DIR=/config/guacamole/keys" >> ~/.bashrc

# GUACAMOLE_HOME 为 guacamole.properties 配置文件所在目录
export GUACAMOLE_HOME=/config/guacamole
echo "export GUACAMOLE_HOME=/config/guacamole" >> ~/.bashrc

# GUACAMOLE_LOG_LEVEL 为生成日志的等级
export GUACAMOLE_LOG_LEVEL=ERROR
echo "export GUACAMOLE_LOG_LEVEL=ERROR" >> ~/.bashrc

# JUMPSERVER_ENABLE_DRIVE 为 rdp 协议挂载共享盘
export JUMPSERVER_ENABLE_DRIVE=true
echo "export JUMPSERVER_ENABLE_DRIVE=true" >> ~/.bashrc

## 启动guacamole
/etc/init.d/guacd start

## 启动tomcat
sh /config/tomcat9/bin/startup.sh

下载lina组件

代码语言:javascript复制
## 进入opt
cd /opt

## 下载lina源码,可以从我的下载站点下,比github快,想要下载的可以联系微信:z133411023
wget https://github.com/jumpserver/lina/releases/download/2.0.1/lina.tar.gz

## 解压
tar -xf lina.tar.gz

## 授权(注意,此处授权要跟nginx服务用户一致,如果nginx使用的是www用户就授权www:www)
chown -R nginx:nginx lina

下载luna组件

代码语言:javascript复制
## 进入opt
cd /opt

## 下载luna源码,可以从我的下载站点下,比github快,想要下载的可以联系微信:z133411023
wget https://github.com/jumpserver/luna/releases/download/2.0.1/luna.tar.gz

nginx安装及配置

此处直接yum安装,如果想源码安装,或者安装官方源,请看博客中web标签下的nginx文档

代码语言:javascript复制
## 安装nginx
yum install -y nginx

## 编辑配置文件
vi /etc/nginx/conf.d/jumpserver.conf
server {
    listen 80;

    client_max_body_size 100m;  # 录像及文件上传大小限制

    location /ui/ {
        try_files $uri / /index.html;
        alias /opt/lina/;
    }

    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_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:8070;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    location /api/ {
        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;
    }

    location /core/ {
        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;
    }

    location / {
        rewrite ^/(.*)$ /ui/$1 last;
    }
}


## 检测nginx语法
nginx -t

## 启动nginx
C6:
/etc/init.d/nginx start

C7:
systemctl start nginx

emmm... 我知道你们进来,看的并不是安装,主要是二次开发,想学么?

0 人点赞