声明:

以下部署参照官方说明进行。由于docker部署简单,但实际不推荐用于生产环境,因此参照官方文档进行部署。

Jumpserver 为管理后台,管理员可以通过Web页面进行资产管理、用户管理、资产授权等操作

Coco 为 SSH Server 和 Web Terminal Server 。用户可以通过使用自己的账户登录 SSH 或者 Web Terminal 直接访问被授权的资产。不需要知道服务器的账户密码

Luna 为 Web Terminal Server 前端页面,用户使用 Web Terminal 方式登录所需要的组件

Guacamole 为 Windows 组件,用户可以通过 Web Terminal 来连接 Windows 资产 (暂时只能通过 Web Terminal 来访问)

端口说明

Jumpserver 默认端口为 8080/tcp 配置文件在 jumpserver/config.py

Coco 默认 SSH 端口为 2222/tcp ,默认 Web Terminal 端口为 5000/tcp 配置文件在 coco/conf.py

Guacamole 默认端口为 8081/tcp 在 docker run 时指定

Nginx 默认端口为 80/tcp

Redis 默认端口为 6379/tcp

Mysql 默认端口为 3306/tcp

 

关闭防火墙和selinux

$ firewall-cmd --zone=public --add-port=80/tcp --permanent # nginx 端口

$ firewall-cmd --zone=public --add-port=2222/tcp --permanent # 用户SSH登录端口 coco

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

$ setenforce 0 $ sed -i "s/enforcing/disabled/g" `grep enforcing -rl /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/sysconfig/i18n

一、准备python3和python虚拟环境

1.安装依赖包

执行命令yum -y install wget gcc epel-release git

2.安装Python3.6

yum -y install python36 python36-devel

3.建立Python虚拟环境

因为 CentOS 6/7 自带的是 Python2,而 Yum 等工具依赖原来的 Python,为了不扰乱原来的环境我们来使用 Python 虚拟环境

[root@lc001 ~]# cd /opt

[root@lc001 opt]# python3.6 -m venv py3

[root@lc001 opt]# source /opt/py3/bin/activate

# 看到下面的提示符代表成功,以后运行 Jumpserver 都要先运行以上 source 命令,以下所有命令均在该虚拟环境中运行

(py3) [root@lc001 opt]#

4.自动载入Python虚拟环境配置

此项仅为懒人使用,防止运行 Jumpserver 时忘记载入 Python 虚拟环境导致程序无法运行。使用autoenv

二、 安装 Jumpserver

1.下载或Clone项目

项目提交较多 git clone 时较大(如果网络速度慢会自动中断),你可以选择去 Github 项目页面直接下载zip包。

git clone https://github.com/jumpserver/jumpserver.git

echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env # 进入 jumpserver 目录时将自动载入 python 虚拟环境

# 首次进入 jumpserver 文件夹会有提示,按 y 即可

# Are you sure you want to allow this? (y/N) y

2.安装依赖 RPM 包

cd /opt/jumpserver/requirements

yum -y install $(cat rpm_requirements.txt) # 如果没有任何报错请继续

.......................................................................................

3.安装 Python 库依赖

pip install --upgrade pip setuptools

pip install -r requirements.txt

4.安装 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke

yum -y install redis

设置redis自动启动,并启动redis

5.安装mariadb

yum -y install mariadb mariadb-devel mariadb-server

systemctl enable mariadb

systemctl start mariadb

6.创建数据库 Jumpserver 并授权

create database jumpserver default charset 'utf8';

grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by 'jumps1@db';

flush privileges;

同时为mariadb设置root密码

set password for 'root'@localhost = password('gdsz@dba');

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;

FLUSH PRIVILEGES;

7.修改 Jumpserver 配置文件

(py3) [root@lc001 jumpserver]# vi config.py #修改配置文件中数据库密码

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

"""

jumpserver.config

~~~~~~~~~~~~~~~~~

Jumpserver project setting file

:copyright: (c) 2014-2017 by Jumpserver Team

:license: GPL v2, see LICENSE for more details.

"""

import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

 

class Config:

"""

Jumpserver Config File

Jumpserver 配置文件

 

Jumpserver use this config for drive django framework running,

You can set is value or set the same envirment value,

Jumpserver look for config order: file => env => default

 

Jumpserver使用配置来驱动Django框架的运行,

你可以在该文件中设置,或者设置同样名称的环境变量,

Jumpserver使用配置的顺序: 文件 => 环境变量 => 默认值

"""

# SECURITY WARNING: keep the secret key used in production secret!

# 加密秘钥 生产环境中请修改为随机字符串,请勿外泄

SECRET_KEY = '2vym+ky!997d5kkcc64mnz06y1mmui3lut#(^wd=%s_qj$1%x'

# Django security setting, if your disable debug model, you should setting that

ALLOWED_HOSTS = ['*']

 

# SECURITY WARNING: keep the bootstrap token used in production secret!

# 预共享Token coco和guacamole用来注册服务账号,不在使用原来的注册接受机制

#BOOTSTRAP_TOKEN = 'PleaseChangeMe'

BOOTSTRAP_TOKEN = 'nwv4RdXpM82LtSvmV'

 

# Development env open this, when error occur display the full process track, Production disable it

# DEBUG 模式 开启DEBUG后遇到错误时可以看到更多日志

# DEBUG = True

DEBUG = False

# DEBUG, INFO, WARNING, ERROR, CRITICAL can set. See https://docs.djangoproject.com/en/1.10/topics/logging/

# 日志级别

# LOG_LEVEL = 'DEBUG'

# LOG_DIR = os.path.join(BASE_DIR, 'logs')

LOG_LEVEL = 'ERROR'

LOG_DIR = os.path.join(BASE_DIR, 'logs')

# Session expiration setting, Default 24 hour, Also set expired on on browser close

# 浏览器Session过期时间,默认24小时, 也可以设置浏览器关闭则过期

# SESSION_COOKIE_AGE = 3600 * 24

# SESSION_EXPIRE_AT_BROWSER_CLOSE = False

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 = os.path.join(BASE_DIR, 'data', 'db.sqlite3')

 

# MySQL or postgres setting like:

# 使用Mysql作为数据库

DB_ENGINE = 'mysql'

DB_HOST = '127.0.0.1'

DB_PORT = 3306

DB_USER = 'jumpserver'

DB_PASSWORD = 'jumps1@db'

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_BROKER = 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'

 

def __init__(self):

pass

 

def __getattr__(self, item):

return None

 

 

class DevelopmentConfig(Config):

pass

 

 

class TestConfig(Config):

pass

 

 

class ProductionConfig(Config):

pass

 

 

# Default using Config settings, you can write if/else for different env

config = DevelopmentConfig()

 

"config.py" 121L, 3748C written

8.生成数据库表结构和初始化数据

9.运行jumpserver

cd /opt/jumpserver

./jms start all # 后台运行使用 -d 参数./jms start all -d

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

三、安装SSH Server和WebSocket Server:Coco

1.下载或Clone项目

新开一个终端,别忘了 source /opt/py3/bin/activate

cd /opt

source /opt/py3/bin/activate

git clone https://github.com/jumpserver/coco.git

echo "source /opt/py3/bin/activate" > /opt/coco/.env # 进入 coco 目录时将自动载入 python 虚拟环境

2.安装依赖

注意:# 首次进入 coco 文件夹会有提示,按 y 即可

# Are you sure you want to allow this? (y/N) y

cd /opt/coco/requirements

yum -y install $(cat rpm_requirements.txt)

pip install -r requirements.txt

3.修改配置文件并运行

cd /opt/coco

mkdir keys logs

cp conf_example.py conf.py # 如果 coco 与 jumpserver 分开部署,请手动修改 conf.py

vi conf.py

 

# 注意对齐,不要直接复制本文档的内容

(py3) [root@lc001 coco]# vi conf.py

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

#

 

import os

 

BASE_DIR = os.path.dirname(__file__)

 

 

class Config:

"""

Coco config file, coco also load config from server update setting below

"""

# 项目名称, 会用来向Jumpserver注册, 识别而已, 不能重复

# NAME = "localhost"

NAME = "Coco"

 

# Jumpserver项目的url, api请求注册会使用

# CORE_HOST = os.environ.get("CORE_HOST") or 'http://127.0.0.1:8080'

CORE_HOST = 'http://127.0.0.1:8080'

 

# Bootstrap Token, 预共享秘钥, 用来注册coco使用的service account和terminal

# 请和jumpserver 配置文件中保持一致,注册完成后可以删除

# BOOTSTRAP_TOKEN = "PleaseChangeMe"

BOOTSTRAP_TOKEN = "nwv4RdXpM82LtSvmV"

# 启动时绑定的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 = None

 

# ACCESS KEY 保存的地址, 默认注册后会保存到该文件中

# ACCESS_KEY_STORE = os.path.join(BASE_DIR, 'keys', '.access_key')

 

# 加密密钥

# SECRET_KEY = None

 

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

# LOG_LEVEL = 'INFO'

LOG_LEVEL = 'ERROR'

 

# 日志存放的目录

# LOG_DIR = os.path.join(BASE_DIR, 'logs')

 

# Session录像存放目录

# SESSION_DIR = os.path.join(BASE_DIR, 'sessions')

 

# 资产显示排序方式, ['ip', 'hostname']

# ASSET_LIST_SORT_BY = 'ip'

 

# 登录是否支持密码认证

# PASSWORD_AUTH = True

 

# 登录是否支持秘钥认证

# PUBLIC_KEY_AUTH = True

 

# SSH白名单

# ALLOW_SSH_USER = 'all' # ['test', 'test2']

 

# SSH黑名单, 如果用户同时在白名单和黑名单,黑名单优先生效

# BLOCK_SSH_USER = []

 

# 和Jumpserver 保持心跳时间间隔

# HEARTBEAT_INTERVAL = 5

 

# Admin的名字,出问题会提示给用户

# ADMINS = ''

COMMAND_STORAGE = {

"TYPE": "server"

}

REPLAY_STORAGE = {

"TYPE": "server"

}

 

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

# SSH_TIMEOUT = 15

 

# 语言 = en

LANGUAGE_CODE = 'zh'

 

 

config = Config()

"conf.py" 90L, 2442C written

(py3) [root@lc001 coco]#

./cocod start # 后台运行使用 -d 参数./cocod start -d

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

备注:声明,前期服务器名为lc001,是因前期中途工作忙,因而中断,后期改服务器名改为lc009,过程一样,OS都是Centos7.4,因此在阅读此文时勿见怪。

四、安装Web Terminal前端:Luna

Luna已改为纯前端,需要Nginx来运行访问

访问(https://github.com/jumpserver/luna/releases)下载对应版本的 release 包,直接解压,不需要编译

cd /opt

wget https://github.com/jumpserver/luna/releases/download/1.4.5/luna.tar.gz

tar xf luna.tar.gz

chown -R root:root luna

五、安装Windows支持组件

Guacamole需要tomcat来运行

1.安装依赖包

mkdir /usr/local/lib/freerdp/

ln -s /usr/local/lib/freerdp /usr/lib64/freerdp

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

2.编译安装guacamole服务

cd /opt

git clone 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

cd ..

rm -rf guacamole-server-0.9.14

ldconfig

3.配置tomcat

mkdir -p /config/guacamole /config/guacamole/lib /config/guacamole/extensions # 创建 guacamole 目录

cp /opt/docker-guacamole/guacamole-auth-jumpserver-0.9.14.jar /config/guacamole/extensions/guacamole-auth-jumpserver-0.9.14.jar

cp /opt/docker-guacamole/root/app/guacamole/guacamole.properties /config/guacamole/ # guacamole 配置文件

cd /config

wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz

tar xf apache-tomcat-8.5.35.tar.gz

rm -rf apache-tomcat-8.5.35.tar.gz

mv apache-tomcat-8.5.35 tomcat8

rm -rf /config/tomcat8/webapps/*

cp /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' `grep 'Connector port="8080"' -rl /config/tomcat8/conf/server.xml` # 修改默认端口为 8081

sed -i 's/FINE/WARNING/g' `grep 'FINE' -rl /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

tar xf linux-amd64.tar.gz -C /bin/

chmod +x /bin/ssh-forward

4.配置环境变量

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

export BOOTSTRAP_TOKEN=nwv4RdXpM82LtSvmV

echo "export BOOTSTRAP_TOKEN=nwv4RdXpM82LtSvmV" >> ~/.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

5.启动Guacamole

/etc/init.d/guacd start

sh /config/tomcat8/bin/startup.sh

六、配置Nginx整合各组件

1.安装Nginx

vi /etc/yum.repos.d/nginx.repo

 

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=0

enabled=1

yum -y install nginx

rm -rf /etc/nginx/conf.d/default.conf

2.准备配置文件,修改/etc/nginx/conf.d/jumpserver.conf

vi /etc/nginx/conf.d/jumpserver.conf

server { listen 80; # 代理端口,以后将通过此端口进行访问,不再通过8080端口

# server_name demo.jumpserver.org; # 修改成你的域名或者注释掉

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/; # 如果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: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; } }

3.运行Nginx

nginx -t # 确保配置没有问题, 有问题请先解决

systemctl start nginx

systemctl enable nginx

4.开始使用Jumpserver

检查应用是否已经正常运行

服务全部启动后,访问 http://192.168.19.139,访问nginx代理的端口,不要再通过8080端口访问

默认账号: admin 密码: admin

到Jumpserver 会话管理-终端管理 检查 Coco Guacamole 等应用的注册。

备注:由于第一次部署时因其他工作耽搁了,因此机器名前后在本文中有变化,但是步骤都是一样。

配置LDAP(前提得有AD域环境,部署AD域环境本文省略)

解决部分CPU和内存高占用问题(以下摘字官网)

$ cd /opt/jumpserver

$ vi config.py

 

# 调整 debug 模式和 log_level

...

DEBUG = os.environ.get("DEBUG") or False

...

LOG_LEVEL = os.environ.get("LOG_LEVEL") or 'ERROR'

...

 

$ cd /opt/coco

$ vi conf.py

 

# 调整 log_level

...

LOG_LEVEL = 'ERROR'

...

 

# 设置好后重启 jumpserver 和 coco

Systemd 管理启动 Jumpserver

# 适合按照一步一步文档进行安装的用户, Centos 7

 

# Jumpserver

$ cat << EOF > /usr/lib/systemd/system/jms.service

[Unit]

Description=jms

After=network.target mariadb.service redis.service

Wants=mariadb.service redis.service

 

[Service]

Type=forking

Environment="PATH=/opt/py3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"

ExecStart=/opt/jumpserver/jms start all -d

ExecReload=

ExecStop=/opt/jumpserver/jms stop

 

[Install]

WantedBy=multi-user.target

 

EOF

 

# Coco

$ cat << EOF > /usr/lib/systemd/system/coco.service

[Unit]

Description=coco

After=network.target jms.service

 

[Service]

Type=forking

PIDFile=/opt/coco/coco.pid

Environment="PATH=/opt/py3/bin"

ExecStart=/opt/coco/cocod start -d

ExecReload=

ExecStop=/opt/coco/cocod stop

 

[Install]

WantedBy=multi-user.target

 

EOF

 

# Guacamole

$ chkconfig guacd on

$ sed -i '143i CATALINA_PID="$CATALINA_BASE/tomcat.pid"' /config/tomcat8/bin/catalina.sh

$ cat << EOF > /usr/lib/systemd/system/guacamole.service

[Unit]

Description=guacamole

After=network.target jms.service

Wants=jms.service

 

[Service]

Type=forking

PIDFile=/config/tomcat8/tomcat.pid

Environment="JUMPSERVER_SERVER=http://127.0.0.1:8080" "JUMPSERVER_KEY_DIR=/config/guacamole/keys" "GUACAMOLE_HOME=/config/guacamole" "BOOTSTRAP_TOKEN=nwv4RdXpM82LtSvmV"

ExecStart=/config/tomcat8/bin/startup.sh

ExecReload=

ExecStop=/config/tomcat8/bin/shutdown.sh

 

[Install]

WantedBy=multi-user.target

 

EOF

 

# 开机自启设置

$ systemctl enable jms

$ systemctl enable coco

$ systemctl enable guacamole

 

# 启动

$ systemctl start jms

$ systemctl start coco

$ systemctl start guacamole

 

# 停止

$ systemctl stop jms

$ systemctl stop coco

$ systemctl stop guacamole

 

 

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐