JumpServer安装与配置

JumpServer安装与配置

Scroll Down

一、安装步骤

0、环境要求

硬件配置: 2个CPU核心, 4G 内存, 50G 硬盘(最低)

磁盘容量存储空间主要用于存储审计录像,所以容量的选择需要根据用户资产数量及使用程度来评估,以100台Linux虚拟机为例,正常的日常使用,200G可以存储3-5个月的录像

image.png

操作系统: Linux 发行版 x86_64
Python = 3.6.x
Mysql Server ≥ 5.6
Mariadb Server ≥ 5.5.56
Redis

1、环境一览

硬件配置: 2个cpu核心,3G内存,50G存储
操作系统: CentOS Linux release 7.7.1908 
前提软件:

Python = 3.7.0 
Mariadb 5.5.65
Redis 5.0.4

2、编译安装python、安装Mariadb、安装Redis

① 编译安装python

# 安装一些必要依赖
# yum -y install openldap
# yum -y install openldap24-libs
# yum -y install openldap-clients
# yum -y install openldap-devel
# yum -y install openssl openssl-devel
# yum install python-devel

# tar -xzvf  Python-3.7.0.tgz
# cd Python-3.7.0
# 检查编译环境,相关库文件,配置参数,生成Makefile
# ./configure prefix=/usr/local/python3.7 --with-ssl --enable-optimizations

# 对源代码进行编译
# make

# 将生成的可执行文件安装到当前计算机中
# make install

# ln -s /usr/local/python3.7/bin/python3  /usr/local/bin/python3

② 创建Python3虚拟环境
# python3 -m venv /opt/py3

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

# 退出虚拟环境的话,用deactivate
# deactivate

④ 安装mariadb

# yum -y install mariadb mariadb-devel mariadb-server MariaDB-shared
# systemctl enable mariadb
# systemctl start mariadb
# mysql_secure_installation
# mysql -uroot -p密码
MariaDB [(none)]> create database jumpserver default charset 'utf8';
MariaDB [(none)]> grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by '密码';
MariaDB [(none)]> flush privileges;

⑤ 编译安装redis

# wget http://download.redis.io/releases/redis-5.0.4.tar.gz
# yum -y install gcc
# tar -xzvf redis-5.0.4.tar.gz
# cd redis-5.0.4
# make
# make PREFIX=/usr/local/redis install
# mkdir /usr/local/redis/etc
# cp ./redis.conf /usr/local/redis/etc/
# sed -ri 's/daemonize no/daemonize yes/'  /usr/local/redis/etc/redis.conf
# ln -s /usr/local/redis/bin/* /usr/local/bin/
# redis-server /usr/local/redis/etc/redis.conf

3、获取JumpServer代码

# cd /opt
# wget https://github.com/jumpserver/jumpserver/releases/download/v2.1.0/jumpserver-v2.1.0.tar.gz
# tar xf jumpserver-v2.1.0.tar.gz
# mv jumpserver-v2.1.0 jumpserver

4、安装编译环境依赖

# 根据当前系统,安装必要依赖
# yum install -y $(cat rpm_requirements.txt)
# cd /opt/jumpserver/requirements
# 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/

5、修改配置文件

# cd /opt/jumpserver
# cp config_example.yml config.yml
# 生成随机SECRET_KEY
# cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50
# 生成随机BOOTSTRAP_TOKEN
# cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16
# vim config.yml

JumpServer配置文件模板如下:

# 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: QD7DQsmADC9GCN8Sst2eiFJvhIsEq7zPr8YaD2oWLoXYylAQHh

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

# 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
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:
# REDIS_DB_CELERY: 3
# REDIS_DB_CACHE: 4

# Use OpenID Authorization
# 使用 OpenID 进行认证设置
# AUTH_OPENID: False # True or False
# BASE_SITE_URL: None
# AUTH_OPENID_CLIENT_ID: client-id
# AUTH_OPENID_CLIENT_SECRET: client-secret
# AUTH_OPENID_PROVIDER_ENDPOINT: https://op-example.com/
# AUTH_OPENID_PROVIDER_AUTHORIZATION_ENDPOINT: https://op-example.com/authorize
# AUTH_OPENID_PROVIDER_TOKEN_ENDPOINT: https://op-example.com/token
# AUTH_OPENID_PROVIDER_JWKS_ENDPOINT: https://op-example.com/jwks
# AUTH_OPENID_PROVIDER_USERINFO_ENDPOINT: https://op-example.com/userinfo
# AUTH_OPENID_PROVIDER_END_SESSION_ENDPOINT: https://op-example.com/logout
# AUTH_OPENID_PROVIDER_SIGNATURE_ALG: HS256
# AUTH_OPENID_PROVIDER_SIGNATURE_KEY: None
# AUTH_OPENID_SCOPES: "openid profile email"
# AUTH_OPENID_ID_TOKEN_MAX_AGE: 60
# AUTH_OPENID_ID_TOKEN_INCLUDE_CLAIMS: True
# AUTH_OPENID_USE_STATE: True
# AUTH_OPENID_USE_NONCE: True
# AUTH_OPENID_SHARE_SESSION: True
# AUTH_OPENID_IGNORE_SSL_VERIFICATION: True
# AUTH_OPENID_ALWAYS_UPDATE_USER: 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: False

6、启动JumpServer

# 确保正在使用py3虚拟环境
# source /opt/py3/bin/activate

# cd /opt/jumpserver
# -d 选项在后台运行
# ./jms start -d

7、部署KoKo组件

# cd /opt
# wget https://github.com/jumpserver/koko/releases/download/v2.1.0/koko-v2.1.0-linux-amd64.tar.gz
# tar -xf koko-v2.1.0-linux-amd64.tar.gz
# mv koko-v2.1.0-linux-amd64 koko
# chown -R root:root koko
# cd koko
# cp config_example.yml config.yml
# vi config.yml

KoKo配置文件模板如下:

#BOOTSTRAP_TOKEN 需要和 jumpserver/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: iNSDpXH21ko0tgdB

# 启动时绑定的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: '123456'
# REDIS_CLUSTERS:
REDIS_DB_ROOM: 6
# 启动koko,-d在后台运行
# ./koko -d

8、Docker部署Guacamole

# 安装docker
# wget  https://download.docker.com/linux/static/stable/x86_64/docker-19.03.9.tgz

# tar zxvf docker-19.03.9.tgz
# mv docker/* /usr/bin

# cat > /usr/lib/systemd/system/docker.service << EOF
>[Unit]
>Description=Docker Application Container Engine
>Documentation=https://docs.docker.com
>After=network-online.target firewalld.service
>Wants=network-online.target
>[Service]
>Type=notify
>ExecStart=/usr/bin/dockerd
>ExecReload=/bin/kill -s HUP $MAINPID
>LimitNOFILE=infinity
>LimitNPROC=infinity
>LimitCORE=infinity
>TimeoutStartSec=0
>Delegate=yes
>KillMode=process
>Restart=on-failure
>StartLimitBurst=3
>StartLimitInterval=60s
>[Install]
>WantedBy=multi-user.target
>EOF

# mkdir /etc/docker
# cat > /etc/docker/daemon.json << EOF
>{
>  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
>}
>EOF

# systemctl daemon-reload
# systemctl start docker
# systemctl enable docker


# docker run --name jms_guacamole -d \

-p 127.0.0.1:8081:8080 \

-e JUMPSERVER_SERVER=http://192.168.52.10:8080 \

-e BOOTSTRAP_TOKEN=iNSDpXH21ko0tgdB\

-e GUACAMOLE_LOG_LEVEL=ERROR \

jumpserver/jms_guacamole:2.1.0

# <Jumpserver_url> 为 JumpServer 的 url 地址,
# <Jumpserver_BOOTSTRAP_TOKEN> 需要从 jumpserver/config.yml 里面获取, 保证一致,
# <Tag> 是版本

9、安装nginx

# yum install yum-utils

# vim /etc/yum.repos.d/nginx.repo

# yum -y install nginx

10、下载 Lina 组件

>> # cd /opt
>> # wget https://github.com/jumpserver/lina/releases/download/v2.1.0/lina-v2.1.0.tar.gz

>> # tar -xf lina-v2.1.0.tar.gz 
>> # mv lina-v2.1.0 lina
>> # chown -R nginx:nginx lina

11、下载 Luna 组件

# cd /opt 
# wget https://github.com/jumpserver/luna/releases/download/v2.1.0/luna-v2.1.0.tar.gz

# tar -xf luna-v2.1.0.tar.gz mv luna-v2.1.0 luna 
# chown -R nginx:nginx luna


# cd /opt wget https://github.com/jumpserver/luna/releases/download/v2.1.0/luna-v2.1.0.tar.gz

# tar -xf luna-v2.1.0.tar.gz

# mv luna-v2.1.0 luna

# chown -R nginx:nginx luna

12、配置nginx整合各组件

# echo > /etc/nginx/conf.d/default.conf

# vim /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 -t
# nginx -s reload

13、web访问测试

服务全部启动后, 访问 JumpServer 服务器 nginx 代理的 80 端口, 不要通过8080端口访问 默认账号: admin 密码: admin

1

2

二、JumpServer报错解决:

1、python3安装完成,进入python3虚拟环境使用pip报错:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

解决:

① 安装openssl openssl-devel(openssl-dev)

# yum -y install openssl openssl-devel

② 删除之前的python编译目录和已经生成的可执行二进制文件和解压的官方python源码包
③ 重新编译安装

# 检查编译环境,相关库文件,配置参数,生成Makefile

# ./configure --prefix=/usr/local/python3/ --with-ssl --enable-optimizations

# 对源代码进行编译

# make

# 将生成的可执行文件安装到当前计算机中

# make install

④ 激活是source activate

退出python虚拟环境的命令是deactivate

2、使用python3虚拟环境pip install过程报错:

① 报错:OSError: mysql_config not found
yum install mysql-devel gcc gcc-devel python-devel
② ERROR: Failed building wheel for python-ldap
缺少环境依赖:
yum -y install openldap
yum -y install openldap24-libs
yum -y install openldap-clients
yum -y install openldap-devel
yum -y install openssl-devel
yum install python-devel

3、jumpserver连接mariadb的数据库密码要使用 ' ' 包起来

4、redis需要设置一个密码 ‘123456’,koko配置文件密码处同样需要 ‘ ’ 包起来

后期验证redis密码机制有问题,所以删除了redis的密码,jumpserver中和koko组件中注释掉了redis的密码项

5、安装部署完成之后,用nginx代理的80端口访问jumpserver,web界面报错internal error

查看jumpserver的日志:

redis.exceptions.ResponseError: NOAUTH Authentication required.

所以修改了redis的配置文件,删除了requirepass项,不使用密码,重启redis

终止jumpserver进程,然后重启

./koko --help可以看到停止其进程的方法,然后重启

参考来源:
JumpServer官方