一、Jumpserver簡單介紹
Jumpserver 是全球首款徹底開源的堡壘機,使用 GNU GPL v2.0 開源協議,是符合 4A 的專業運維審計系統。Jumpserver 使用 Python / Django 進行開發,遵循 Web 2.0 規範,配備了業界領先的 Web Terminal 解決方案,交互界面美觀、用戶體驗好。
Jumpserver 採納分佈式架構,支持多機房跨區域部署,中心節點提供 API,各機房部署登陸節點,可橫向擴展、無併發訪問限制。
html
二、架構圖以下
三、組件說明
Jumpserver
現指 Jumpserver 管理後臺,是核心組件(Core), 使用 Django Class Based View 風格開發,支持 Restful API。
前端Coco
實現了 SSH Server 和 Web Terminal Server 的組件,提供 SSH 和 WebSocket 接口, 使用 Paramiko 和 Flask 開發。
pythonLuna
如今是 Web Terminal 前端,計劃前端頁面都由該項目提供,Jumpserver 只提供 API,再也不負責後臺渲染html等。
mysqlGuacamole
Apache 跳板機項目,Jumpserver 使用其組件實現 RDP 功能,Jumpserver 並無修改其代碼而是添加了額外的插件,支持 Jumpserver 調用。
linuxJumpserver-Python-SDK
Jumpserver API Python SDK,Coco 目前使用該 SDK 與 Jumpserver API 交互。
nginx參考文章:http://docs.jumpserver.org/zh/latest/admin_instruction.html
四、安裝環境準備
系統環境說明
[root@test ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@test ~]# uname -r
3.10.0-693.el7.x86_64
[root@test ~]# ip add|grep 192.168.22
inet 192.168.22.175/24 brd 192.168.22.255 scope global ens32
關閉防火牆與selinux
[root@test ~]# systemctl stop firewalld
[root@test ~]# systemctl disable firewalld
[root@test ~]# sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config
[root@master ~]# grep "SELINUX=" /etc/selinux/config
# SELINUX= can take one of these three values:
SELINUX=disabled
[root@test ~]# reboot
準備 Python3 和 Python 虛擬環境
安裝依賴包
[root@test ~]# yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git
編譯安裝python
[root@test ~]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
[root@test ~]# tar xf Python-3.6.1.tar.xz
[root@test ~]# cd Python-3.6.1
[root@test Python-3.6.1]# ./configure
[root@test Python-3.6.1]# echo $?
0
[root@test Python-3.6.1]# make && make install
-------------------過程部分省略
fi
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.1 setuptools-28.8.0
[root@test Python-3.6.1]# echo $?
0
創建 Python 虛擬環境
由於 CentOS 6/7 自帶的是 Python2,而 Yum 等工具依賴原來的 Python,爲了避免擾亂原來的環境咱們來使用 Python 虛擬環境git
[root@test Python-3.6.1]# cd /opt/
[root@test opt]# python3 -m venv py3
[root@test opt]# source /opt/py3/bin/activate
(py3) [root@test opt]#
# 看到上面的提示符表明成功,之後運行 Jumpserver 都要先運行以上 source 命令,如下全部命令均在該虛擬環境中運行(py3) [root@localhost py3]
五、安裝jumpserver
(py3) [root@test opt]# pwd
/opt
(py3) [root@test opt]# git clone --depth=1 https://github.com/jumpserver/jumpserver.git
Cloning into 'jumpserver'...
remote: Counting objects: 718, done.
remote: Compressing objects: 100% (652/652), done.
remote: Total 718 (delta 95), reused 380 (delta 22), pack-reused 0
Receiving objects: 100% (718/718), 5.31 MiB | 440.00 KiB/s, done.
Resolving deltas: 100% (95/95), done.
(py3) [root@test opt]# cd jumpserver/
(py3) [root@test jumpserver]# git checkout master
Already on 'master'
安裝依賴 RPM 包
(py3) [root@test jumpserver]# cd /opt/jumpserver/requirements/
(py3) [root@test requirements]# yum -y install $(cat rpm_requirements.txt)
#無任何報錯便可完成
安裝 Python 庫依賴
(py3) [root@test requirements]# pip install -r requirements.txt
這裏官方比較坑,說不要指定源,不指定源根本裝不了,可根據實際狀況指定相關的新pip源進行安裝,實在安裝不了的,下載源碼包手工安裝。
安裝 Redis
Jumpserver 使用 Redis 作 cache 和 celery broke
(py3) [root@master opt]# yum -y install redis
(py3) [root@master opt]# service redis start
Redirecting to /bin/systemctl start redis.service
(py3) [root@master opt]# lsof -i :6379
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
redis-ser 22530 redis 4u IPv4 71615 0t0 TCP localhost:6379 (LISTEN)
安裝 MySQL
這裏直接使用二進制安裝包安裝,具體可參考以前的文章github
(py3) [root@master opt]# /etc/init.d/mysqld start
Starting MySQL SUCCESS!
(py3) [root@master opt]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 23081 mysql 17u IPv6 73467 0t0 TCP *:mysql (LISTEN)
建立數據庫 Jumpserver 並受權
(py3) [root@master opt]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> create database jumpserver default charset 'utf8';
Query OK, 1 row affected (0.00 sec)
MySQL [(none)]> grant all on jumpserver.* to 'jumpserver'@'localhost' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
MySQL [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
修改 Jumpserver 配置文件
(py3) [root@master opt]# cd /opt/jumpserver/
(py3) [root@master jumpserver]# cp config_example.py config.py
(py3) [root@master jumpserver]# vim config.py
--------------------
# Default using Config settings, you can write if/else for different env
class DevelopmentConfig(Config):
DEBUG = True
DB_ENGINE = 'mysql'
DB_HOST = '127.0.0.1'
DB_PORT = 3306
DB_USER = 'jumpserver'
DB_PASSWORD = '123456'
DB_NAME = 'jumpserver'
config = DevelopmentConfig()
#增長上面的內容
生成數據庫表結構和初始化數據
(py3) [root@master jumpserver]# cd /opt/jumpserver/utils/
(py3) [root@master utils]# bash make_migrations.sh
2018-05-09 13:51:48 [signals_handler DEBUG] Receive django ready signal
2018-05-09 13:51:48 [signals_handler DEBUG] - fresh all settings
Migrations for 'assets':
/opt/jumpserver/apps/assets/migrations/0002_auto_20180509_1351.py
--------------------中間省略
Running migrations:
Applying assets.0001_initial... OK
Applying assets.0002_auto_20180509_1351... OK
Applying audits.0001_initial... OK
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying captcha.0001_initial... OK
Applying common.0001_initial... OK
Applying django_celery_beat.0001_initial... OK
Applying django_celery_beat.0002_auto_20161118_0346... OK
Applying django_celery_beat.0003_auto_20161209_0049... OK
Applying django_celery_beat.0004_auto_20170221_0000... OK
Applying django_celery_beat.0005_add_solarschedule_events_choices... OK
Applying django_celery_beat.0006_auto_20180210_1226... OK
Applying ops.0001_initial... OK
Applying ops.0002_celerytask... OK
Applying users.0001_initial... OK
Applying users.0002_auto_20171225_1157... OK
Applying users.0003_auto_20180509_1351... OK
Applying perms.0001_initial... OK
Applying perms.0002_auto_20180509_1351... OK
Applying sessions.0001_initial... OK
Applying terminal.0001_initial... OK
Applying terminal.0002_auto_20180509_1351... OK
運行jumpserver
(py3) [root@master utils]# cd /opt/jumpserver/
(py3) [root@master jumpserver]# python run_server.py all
Wed May 9 13:53:15 2018
Jumpserver version 1.3.0, more see https://www.jumpserver.org
- Start Gunicorn WSGI HTTP Server
Check database structure change ...
2018-05-09 13:53:17 [signals_handler DEBUG] Receive django ready signal
2018-05-09 13:53:17 [signals_handler DEBUG] - fresh all settings
---------------
Task terminal.tasks.clean_orphan_session[eb960461-07a0-4b42-a5bb-96fdd94fabcd] succeeded in 0.11468194000190124s: None
運行以後沒有報錯信息,就可使用瀏覽器訪問了http://server_ip:8080redis
默認用戶名/密碼:admin/admin此時運行的只是jumpserver的WEB端,若是須要訪問訪問 Web Terminal 會報錯以下
安裝 SSH Server 和 WebSocket Server: Coco
新打開一個 SSH終端鏈接去安裝
下載項目文件
[root@master ~]# source /opt/py3/bin/activate
(py3) [root@master ~]# cd /opt/
(py3) [root@master opt]# git clone https://github.com/jumpserver/coco.git
Cloning into 'coco'...
remote: Counting objects: 1276, done.
remote: Total 1276 (delta 0), reused 0 (delta 0), pack-reused 1276
Receiving objects: 100% (1276/1276), 272.18 KiB | 39.00 KiB/s, done.
Resolving deltas: 100% (901/901), done.
(py3) [root@master opt]# cd coco && git checkout master
Already on 'master'
安裝依賴
(py3) [root@master coco]# cd /opt/coco/requirements/
(py3) [root@master requirements]# yum -y install $(cat rpm_requirements.txt)
(py3) [root@master requirements]# pip install -r requirements.txt
(py3) [root@master requirements]# echo $?
0
(py3) [root@master requirements]# cd /opt/coco/
(py3) [root@master coco]# cp conf_example.py conf.py
(py3) [root@master coco]# python run_server.py
Start coco process
2018-05-09 14:19:44 [service DEBUG] Initial app service
2018-05-09 14:19:44 [service DEBUG] Load access key
2018-05-09 14:19:44 [service INFO] No access key found, register it
2018-05-09 14:19:44 [service INFO] "Terminal was not accepted yet"
2018-05-09 14:19:48 [service INFO] "Terminal was not accepted yet"
#此時須要去WEB管理後臺確認註冊信息
點擊確認以後會出現下面的提示
2018-05-09 14:21:23 [service DEBUG] Set app service auth: 9f13a90b-80e4-47ae-b0ad-d825cff70ff0
2018-05-09 14:21:23 [service DEBUG] Service http auth: <jms.auth.AccessKeyAuth object at 0x7f5d1b18de10>
2018-05-09 14:21:23 [app DEBUG] Loading config from server: {"COMMAND_STORAGE": {"TYPE": "server"}, "REPLAY_STORAGE": {"TYPE": "server"}}
Wed May 9 14:21:23 2018
Coco version 1.3.0, more see https://www.jumpserver.org
Quit the server with CONTROL-C.
Starting ssh server at 0.0.0.0:2222
WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
#出現上面的提示表示成功
測試鏈接
[root@testLinux1 ~]# ssh -p2222 admin@192.168.3.82
The authenticity of host '[192.168.3.82]:2222 ([192.168.3.82]:2222)' can't be established.
RSA key fingerprint is SHA256:Dw9BcxNFFZtgc1EpavxUeamzKT1VoX6UAPNIyzaEhpw.
RSA key fingerprint is MD5:16:d8:05:5e:12:9d:e5:54:ee:96:97:21:ab:33:2c:7e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '
[192.168.3.82]:2222' (RSA) to the list of known hosts.
admin@192.168.3.82'
s password:
Administrator, 歡迎使用Jumpserver開源跳板機系統
1) 輸入 ID 直接登陸 或 輸入部分 IP,主機名,備註 進行搜索登陸(若是惟一).
2) 輸入 / + IP, 主機名 or 備註 搜索. 如: /ip
3) 輸入 P/p 顯示您有權限的主機.
4) 輸入 G/g 顯示您有權限的主機組.
5) 輸入 G/g + 組ID 顯示該組下主機. 如: g1
6) 輸入 H/h 幫助.
0) 輸入 Q/q 退出.
Opt>
#能成功登陸的表示安裝部署成功
安裝 Web Terminal 前端: Luna
Luna 已改成純前端,須要 Nginx 來運行訪問,訪問(https://github.com/jumpserver/luna/releases)下載對應版本的 release 包,直接解壓,不須要編譯。
(py3) [root@master opt]# 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://192.168.3.82:8080 \
registry.jumpserver.org/public/guacamole:1.0.0
Unable to find image 'registry.jumpserver.org/public/guacamole:1.0.0' locally
Trying to pull repository registry.jumpserver.org/public/guacamole ...
1.0.0: Pulling from registry.jumpserver.org/public/guacamole
723254a2c089: Pull complete
abe15a44e12f: Pull complete
409a28e3cc3d: Pull complete
a9511c68044a: Pull complete
9d1b16e30bc8: Pull complete
0fc5a09c9242: Pull complete
d34976006493: Pull complete
3b70003f0c10: Pull complete
bc7887582e2e: Pull complete
d2ab4f165865: Pull complete
3882b23577d6: Pull complete
9f8b758ebfa6: Pull complete
ef5d2d838878: Pull complete
310fa32446d6: Pull complete
a23204f32cd2: Pull complete
f3cba08c8ef8: Pull complete
59073672f2e3: Pull complete
86d50039bf5c: Pull complete
7041bb4312f0: Pull complete
ca5c931789c9: Pull complete
cef49dddf00f: Pull complete
3535ea408862: Pull complete
2dd70d9a46ce: Pull complete
Digest: sha256:ea862bb2e83b648701655c27900bca14b0ab7ab9d4572e716c25a816dc55307b
Status: Downloaded newer image for registry.jumpserver.org/public/guacamole:1.0.0
38910abc050cea50fa03acc913e4916f17726820de9d6a1274f6e37a9131ba31
#而後去後臺接受註冊信息
須要注意的是修改默認IP以下圖
配置 Nginx 整合各組件
(py3) [root@master opt]# yum install nginx -y
(py3) [root@master opt]# cd /etc/nginx/
(py3) [root@master nginx]# cp nginx.conf nginx.conf.bak
(py3) [root@master nginx]# vim nginx.conf
server {
listen 80;
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 /luna/ {
try_files $uri / /index.html;
alias /opt/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";
}
location /guacamole/ {
proxy_pass http://localhost:8081/;
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
access_log off;
}
location / {
proxy_pass http://localhost:8080;
}
}
}
(py3) [root@master nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
(py3) [root@master nginx]# nginx
(py3) [root@master nginx]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 24269 root 6u IPv4 100705 0t0 TCP *:http (LISTEN)
nginx 24270 nginx 6u IPv4 100705 0t0 TCP *:http (LISTEN)
最後經過nginx直接訪問以下
簡單使用配置
系統幾個用戶的區別
用戶:是指你在web上建立的用戶,會在跳板機上建立這個用戶,做用就是用於登陸跳板機,另外用戶分爲普通用戶和超級管理員,後者能夠審計查看用戶登錄記錄、命令歷史等
管理用戶:是指客戶端上的如root等高權限帳號(或普通用戶擁有NOPASSWD: ALL sudo權限), 做用用於推送系統用戶,注意是已經在客戶端用戶上存在的用戶。
系統用戶:是指要在客戶端上建立這個系統用戶,經過推送來實現,做用就是登陸客戶端。
管理用戶和系統用戶的關係:
二者都是客戶端上的用戶,後者涉及到一個推送動做
好比推送test系統用戶,也就是在客戶端上建立test用戶,那麼建立用戶須要有權限
有沒有權限建立就要看你是用客戶端的root用戶仍是普通用戶作爲管理用戶
若是後者作爲管理用戶就須要添加sudo權限又是NOPASSWD: ALL
添加用戶組
添加用戶
這個用戶是用於登陸jumpsesrver的用戶,
與後面的管理用戶、系統用戶沒有關聯
添加完成
建立管理用戶
這個用戶必須具有客戶端管理權限,
不然後面會有問題,這裏我以管理用戶爲例建立
添加系統用戶
系統用戶是Jumpserver跳轉登陸資產時使用的用戶,
能夠理解爲登陸資產用戶,如 web, sa, dba(ssh web@some-host
), 而不是使用某個用戶的用戶名跳轉登陸服務器(ssh xiaoming@some-host
); 簡單來講是 用戶使用本身的用戶名登陸Jumpserver, Jumpserver使用系統用戶登陸資產。 系統用戶建立時,若是選擇了自動推送 Jumpserver會使用ansible自動推送系統用戶到資產中,若是資產(交換機、windows)不支持ansible, 請手動填寫帳號密碼。 目前還不支持Windows的自動推送.
注:這個系統在建立時,是能夠配置sudo權限的
建立資產
建立完成後,能夠在下面的界面測試鏈接性
點擊更新硬件信息
點擊測試可鏈接性
表示正常鏈接,返回資產列表以下圖
測試登陸效果
[root@test ~]# ssh -p2222 jumpserver@192.168.3.82
jumpserver@192.168.3.82's password:
登陸到jumpserver, 歡迎使用Jumpserver開源跳板機系統
1) 輸入 ID 直接登陸 或 輸入部分 IP,主機名,備註 進行搜索登陸(若是惟一).
2) 輸入 / + IP, 主機名 or 備註 搜索. 如: /ip
3) 輸入 P/p 顯示您有權限的主機.
4) 輸入 G/g 顯示您有權限的主機組.
5) 輸入 G/g + 組ID 顯示該組下主機. 如: g1
6) 輸入 H/h 幫助.
0) 輸入 Q/q 退出.
Opt> p
ID Hostname IP LoginAs Comment
1 3.26 192.168.3.26 [3.16用戶]
2 linux 192.168.3.16 [3.16用戶]
總共: 2 匹配: 2
Opt> 1
Connecting to testsysuser@3.26 0.6
[testsysuser@linux1 ~]$ pwd
/home/testsysuser
[testsysuser@linux1 ~]$ ip add |grep 192.168.1.
inet 192.168.3.26/24 brd 192.168.3.255 scope global ens160
#能夠正經常使用系統用戶來登陸客戶端主機了
WEB端也能夠看到在線的會話
歷史會話
還能夠看到具體回放功能,點擊回放可查看登陸用戶的操做過程
命令記錄
總體儀表盤