说明

1
2
3
# 开头的行表示注释
> 开头的行表示需要在 mysql 中执行
$ 开头的行表示需要执行的命令

环境信息

系统: CentOS 7.6.181

IP: 192.168.99.5

jms安装目录:/opt/jumpserver

jms配置文件名称:/opt/jumpserver/config.yml

数据库安装目录: /usr/local/mysql 版本:mysql5.7(解压安装)

数据库连接信息:

  • 连接主机:192.168.99.5 —> 127.0.0.1
  • 数据库名称:jumpserver
  • 数据库用户名:jumpserver
  • 数据库密码:cndsdis

前端代理: Nginx(yum安装) 配置文件路径:/etc/nginx/conf.d/jumpserver.conf

系统信息

IP 配置信息 操作系统 Firewalld开放端口
192.168.99.5 2核4G内存 CentOS 7.5.1804 8080、22、3306 2222

安装服务信息

服务名称 版本 安装目录 使用端口
Mysql 5.7.27 /usr/local/mysql/ 3306

开始安装服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 安装前置步骤
$ yum update -y


// 防火墙 与 selinux 设置说明, 如果已经关闭了 防火墙 和 Selinux 的用户请跳过设置
$ systemctl start firewalld
$ 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 // 临时关闭selinux
$ sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config // 永久关闭selinux
$ yum -y install wget gcc epel-release git // 安装依赖包


// 安装redis
$ cd /usr/local/src/
$ wget http://download.redis.io/releases/redis-5.0.5.tar.gz
$ tar xzvf redis-5.0.5.tar.gz && cd redis-5.0.5
$ make && make install
$ mkdir /usr/local/redis/
$ cp ./redis.conf /usr/local/redis/


//修改redis配置文件
$ egrep -v "^#|^$" /usr/local/redis/redis.conf // 修改配置文件以下几项
bind 127.0.0.1
protected-mode no
port 6379
daemonize yes
logfile "/var/log/redis.log"


// 注册redis到系统服务
$ egrep -v "^#|^$" /lib/systemd/system/redis.service // 注册redis到系统服务
[Unit]
Description=Redis
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target


// 启动redis服务
$ systemctl daemon-reload
$ systemctl enable redis
$ systemctl start redis


// 安装Mysql5.7

安装步骤省略......

// 设置Mysql开机自启动,启动mysql服务程序并创建jumpserver数据库
$ chkconfig mysqld on
$ systemctl start mysqld
sql> create database jumpserver default charset 'utf8';
sql> grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by 'jumpserver';
sql> flush privileges;"

安装Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//  安装 Nginx, 用作代理服务器整合 Jumpserver 与各个组件
$ 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 // yum安装nginx
$ systemctl enable nginx // nginx加入到开机自启
$ systemctl start nginx // 启动nginx服务
````

## **安装Python3.6**

```less
$ yum -y install python36 python36-devel //使用yum安装python3.6

// 配置并载入 Python3 虚拟环境
$ cd /opt
$ python3.6 -m venv py3 // py3 为虚拟环境名称, 可自定义
$ source /opt/py3/bin/activate // 退出虚拟环境可以使用 deactivate 命令
// 看到下面的提示符代表成功, 以后运行 Jumpserver 都要先运行以上 source 命令, 载入环境后默认以下所有命令均在该虚拟环境中运行
(py3) [root@jumpserver /]# //看到此界面代表虚拟环境载入成功

部署Jumpserver

  1. 下载 Jumpserver
1
2
3
4
5
$ cd /opt/
$ git clone https://github.com/jumpserver/jumpserver.git

$ cd /opt/jumpserver
$ git checkout 1.4.8
  1. 安装依赖 RPM 包
1
$ yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt)
  1. 安装 Python 库依赖
1
2
3
4
5
6
7
8
$ pip install --upgrade pip setuptools
$ pip install -r /opt/jumpserver/requirements/requirements.txt

// 如果pip安装特别慢使用下列方法切换pip使用清华镜像源下载
$ vim ~/.pip/pip.conf
--------------------------------------------------------------------
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  1. 修改 Jumpserver 配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$ cd /opt/jumpserver
$ cp config_example.yml config.yml // 从示例配置文件拷贝一份正式配置文件

// 完整配置文件内容
$ cat /opt/jumpserver/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: 7eO6W2KDpJofvyxZ9xxpQCpqTeDdxEdS31u1YfJXRtZ1OOLSVw // 随机生成字符串

# SECURITY WARNING: keep the bootstrap token used in production secret!
# 预共享Token cocoguacamole用来注册服务账号,不在使用原来的注册接受机制
# $ cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16
BOOTSTRAP_TOKEN: K3k3NssvhGKnmokB // token记住后面会用到

# 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_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 // 使用mysql作为存储数据库
DB_HOST: 127.0.0.1 // mysql数据库的IP地址
DB_PORT: 3306 // Mysql数据库使用的端口号
DB_USER: jumpserver // jumpserver使用用户
DB_PASSWORD: putianhui // jumpserver用户的密码
DB_NAME: jumpserver // 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 // 默认绑定的主机ip地址
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
  1. 添加Jumpserver到系统服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ vim /lib/systemd/system/jms.service
----------------------------------------------------------
[Unit]
Description=jms
After=network.target mysql.service redis-server.service
Wants=mysqld.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
  1. 运行启动Jumpserver服务
1
2
$ systemctl daemon-reload			// 重新加载系统服务
$ systemctl start jms // 启动jms服务

安装 docker 部署 coco 与 guacamole

  1. 安装docker服务程序
1
2
3
4
5
6
7
8
$ yum install -y yum-utils device-mapper-persistent-data lvm2
$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
$ yum makecache fast
$ rpm --import https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
$ yum -y install docker-ce
$ systemctl enable docker
$ curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
$ systemctl restart docker
  1. 配置防火墙开放指定端口号
1
2
3
// 允许 容器ip 访问宿主 8080 端口, (容器的 ip 可以进入容器查看)
$ firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="172.17.0.0/16" port protocol="tcp" port="8080" accept"
$ firewall-cmd --reload //172.17.0.x 是docker容器默认的IP池, 这里偷懒直接授权ip段了, 可以根据实际情况单独授权IP

3.使用docker运行coco与guacamole

1
2
3
4
5
6
7
8
9
10
11
$ docker run --name jms_coco -d --restart=always -p 2222:2222 -p 5000:5000 -e CORE_HOST=http://192.168.99.5:8080 -e BOOTSTRAP_TOKEN=K3k3NssvhGKnmokB jumpserver/jms_coco:1.4.8
$ docker run --name jms_guacamole -d --restart=always -p 8081:8081 -e JUMPSERVER_SERVER=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=K3k3NssvhGKnmokB jumpserver/jms_guacamole:1.4.8


// 安装 Web Terminal 前端: Luna 需要 Nginx 来运行访问 访问(https://github.com/jumpserver/luna/releases)下载对应版本的 release 包, 直接解压, 不需要编译
$ cd /opt
$ wget https://github.com/jumpserver/luna/releases/download/1.4.8/luna.tar.gz
// 如果网络有问题导致下载无法完成可以使用下面地址
$ wget https://demo.jumpserver.org/download/luna/1.4.8/luna.tar.gz
$ tar xf luna.tar.gz
$ chown -R root:root luna

配置 Nginx 整合各组件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
$ rm -rf /etc/nginx/conf.d/default.conf                 // 删除nginx的默认虚拟主机文件
$ vi /etc/nginx/conf.d/jumpserver.conf // 新建nginx的jumpserver虚拟主机文件
-----------------------------------------------------------
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/;
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/;
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;
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
$ nginx -t // 确保配置没有问题, 有问题请先解决
$ systemctl start nginx
// 访问 http://192.168.99.5(注意 没有 :8080 通过 nginx 代理端口进行访问)# 默认账号: admin 密码: admin 到会话管理-终端管理 接受 coco Guacamole 等应用的注册# 测试连接
$ ssh -p2222 admin@192.168.99.5
$ sftp -P2222 admin@192.168.99.5
密码: admin
// 如果是用在 Windows 下, Xshell Terminal 登录语法如下
$ ssh admin@192.168.99.5 2222
$ sftp admin@192.168.99.5 2222
// 密码: admin,如果能登陆代表部署成功

// sftp默认上传的位置在资产的 /tmp 目录下# windows拖拽上传的位置在资产的 Guacamole RDP上的 G 目录下