手把手從0開始教你搭建Jumpserver,爲服務器安全保駕護航!

圖片

1、Jumpserver簡單介紹

Jumpserver 是全球首款完全開源的堡壘機,使用 GNU GPL v2.0 開源協議,是符合 4A 的專業運維審計系統。Jumpserver 使用 Python / Django 進行開發,遵循 Web 2.0 規範,配備了業界領先的 Web Terminal 解決方案,交互界面美觀、用戶體驗好。
Jumpserver 採納分佈式架構,支持多機房跨區域部署,中心節點提供 API,各機房部署登錄節點,可橫向擴展、無併發訪問限制。

2、架構圖如下

圖片

3、組件說明

  • Jumpserver
    現指 Jumpserver 管理後臺,是核心組件(Core), 使用 Django Class Based View 風格開發,支持 Restful API。

  • Coco
    實現了 SSH Server 和 Web Terminal Server 的組件,提供 SSH 和 WebSocket 接口, 使用 Paramiko 和 Flask 開發。

  • Luna
    現在是 Web Terminal 前端,計劃前端頁面都由該項目提供,Jumpserver 只提供 API,不再負責後臺渲染html等。

  • Guacamole
    Apache 跳板機項目,Jumpserver 使用其組件實現 RDP 功能,Jumpserver 並沒有修改其代碼而是添加了額外的插件,支持 Jumpserver 調用。

  • Jumpserver-Python-SDK
    Jumpserver API Python SDK,Coco 目前使用該 SDK 與 Jumpserver API 交互。

參考文章:http://docs.jumpserver.org/zh/latest/admin_instruction.html

4、安裝環境準備

系統環境說明
[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 虛擬環境

[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]




5、安裝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

這裏直接使用二進制安裝包安裝,具體可參考之前的文章

LAMP架構應用實戰MySQL服務安裝

(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:8080

圖片

默認用戶名/密碼: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 [email protected]
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.
[email protected]'
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 [email protected]
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端也可以看到在線的會話

圖片

歷史會話

圖片

還可以看到具體回放功能,點擊回放可查看登錄用戶的操作過程

圖片

命令記錄

圖片

整體儀表盤

圖片


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章