Jumpserver堡壘機

**

詳細請看

**
詳細文檔 https://gitee.com/crazywjj/bawei/tree/master

jumpserver介紹

Jumpserver 是全球首款完全開源的堡壘機, 使用 GNU GPL v2.0 開源協議, 是符合 4A 的專業運維審計系統。

Jumpserver 使用 Python / Django 進行開發, 遵循 Web 2.0 規範, 配備了業界領先的 Web Terminal 解決方案, 交互界面美觀、用戶體驗好。

Jumpserver 採納分佈式架構, 支持多機房跨區域部署, 中心節點提供 API, 各機房部署登錄節點, 可橫向擴展、無併發訪問限制。

Jumpserver 現已支持管理 SSH、 Telnet、 RDP、 VNC 協議資產。
jumpserver源碼下載:https://github.com/jumpserver/jumpserver

jumpserver的wiki:https://github.com/jumpserver/jumpserver/wiki

官方文檔:https://docs.jumpserver.org/zh/master/index.html

CentOS 7 安裝–適合生產環境

1、環境

系統: CentOS 7
IP: 10.0.0.44
目錄: /opt
數據庫: mariadb
代理: nginx

# 防火牆 與 selinux 設置說明, 如果已經關閉了 防火牆 和 Selinux 的用戶請跳過設置
systemctl start firewalld
# nginx 端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 用戶SSH登錄端口 koko
firewall-cmd --zone=public --add-port=2222/tcp --permanent
# --permanent  永久生效, 沒有此參數重啓後失效

# 重新載入規則
firewall-cmd --reload

setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

2、安裝依賴包

yum -y install wget gcc epel-release git

3、安裝 Redis, JumpServer 使用 Redis 做 cache 和 celery broke

yum -y install redis
systemctl enable redis
systemctl start redis

4.安裝 MySQL, 如果不使用 Mysql 可以跳過相關 Mysql 安裝和配置, 支持sqlite3, mysql, postgres等

#cat >/etc/yum.repos.d/mariadb.repo<<EOF
#[mariadb]
#name = MariaDB
#baseurl = http://yum.mariadb.org/10.3/centos7-amd64
#gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
#gpgcheck=1
#EOF
#yum clear all
#yum makecache

yum -y install mariadb mariadb-devel mariadb-server MariaDB-shared
systemctl enable mariadb
systemctl start mariadb

5、創建數據庫 JumpServer 並授權

DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24`
echo -e "\033[31m 你的數據庫密碼是 $DB_PASSWORD \033[0m"
mysql -uroot -e "create database jumpserver default charset 'utf8' collate 'utf8_bin';grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by '$DB_PASSWORD'; flush privileges;"

6、安裝 Nginx, 用作代理服務器整合 JumpServer 與各個組件

yum -y install nginx
systemctl enable nginx

7、安裝 Python3.6

yum -y install python36 python36-devel

8、配置並載入 Python3 虛擬環境

cd /opt
# py3 爲虛擬環境名稱, 可自定義$ 
python3.6 -m venv py3
source /opt/py3/bin/activate
# 退出虛擬環境可以使用 deactivate 命令
# 看到下面的提示符代表成功, 以後運行 JumpServer 都要先運行以上 source 命令, 載入環境後默認以下所有命令均在該虛擬環境中運行
(py3) [root@localhost py3]

9、下載 JumpServer

cd /opt/
git clone --depth=1 https://github.com/jumpserver/jumpserver.git

10、安裝依賴 RPM 包

yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt)

11、安裝 Python 庫依賴

pip install wheel
pip install --upgrade pip setuptools
pip install -r /opt/jumpserver/requirements/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

pip 20.0.2文檔 https://pip.pypa.io/en/stable/user_guide/#config-file
pip是一個很好用的第三方庫安裝方式,但是默認的源沒法連接,就算有時候可以成功率也很低,所以換成國內鏡像源比較方便。
將pip源更換到國內鏡像

用pip管理工具安裝庫文件時,默認使用國外的源文件,因此在國內的下載速度會比較慢,可能只有50KB/s。幸好,國內的一些頂級科研機構已經給我們準備好了各種鏡像,下載速度可達2MB/s。

臨時方法

阿里雲 https://mirrors.aliyun.com/pypi/simple/
中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) https://pypi.douban.com/simple/ 
清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
華中理工大學:http://pypi.hustunique.com/
山東理工大學:http://pypi.sdutlinux.org/

使用時直接 -i 加 url 即可如下安裝:

pip install jupyter -i https://pypi.tuna.tsinghua.edu.cn/simple

12、修改 JumpServer 配置文件

cd /opt/jumpserver
cp config_example.yml config.yml

SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50`  # 生成隨機SECRET_KEY
echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc
BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16`  # 生成隨機BOOTSTRAP_TOKEN
echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc

sed -i "s/SECRET_KEY:/SECRET_KEY: $SECRET_KEY/g" /opt/jumpserver/config.yml
sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /opt/jumpserver/config.yml
sed -i "s/# DEBUG: true/DEBUG: false/g" /opt/jumpserver/config.yml
sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" /opt/jumpserver/config.yml
sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: false/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" /opt/jumpserver/config.yml
sed -i "s/DB_PASSWORD: /DB_PASSWORD: $DB_PASSWORD/g" /opt/jumpserver/config.yml

echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m"
echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m"

確保配置文件沒問題:

(py3) [root@ c7-41 jumpserver]# 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: Ro0i3kdfjksdfsdfjldfjsdlFDSLFSDFLDJFLFDFKLDJ

# SECURITY WARNING: keep the bootstrap token used in production secret!
# 預共享Token coco和guacamole用來註冊服務賬號,不在使用原來的註冊接受機制
BOOTSTRAP_TOKEN: 1jvdjflsdfsfdsfdj

# 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: dffsfsfdfdfejenfejfefi
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 來進行認證設置
# 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
# AUTH_OPENID_IGNORE_SSL_VERIFICATION: True
# AUTH_OPENID_SHARE_SESSION: 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

13、運行 JumpServer

# 後臺運行使用 -d 參數./jms start -d
# 新版本更新了運行腳本, 使用方式./jms start|stop|status all  後臺運行請添加 -d 參數
# cd /opt/jumpserver
# ./jms start -d

wget -O /usr/lib/systemd/system/jms.service https://demo.jumpserver.org/download/shell/centos/jms.service
chmod 755 /usr/lib/systemd/system/jms.service
systemctl daemon-reload
systemctl enable jms
systemctl start jms

14、安裝 docker 部署 koko 與 guacamole

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
mkdir /etc/docker
wget -O /etc/docker/daemon.json http://demo.jumpserver.org/download/docker/daemon.json
systemctl restart docker

允許容器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

獲取當前服務器 IP

Server_IP=`ip addr | grep 'state UP' -A2 | grep inet | egrep -v '(127.0.0.1|inet6|docker)' | awk '{print $2}' | tr -d "addr:" | head -n 1 | cut -d / -f1`
echo -e "\033[31m 你的服務器IP是 $Server_IP \033[0m"

運行koko 與 guacamole

# http://<Jumpserver_url> 指向 jumpserver 的服務端口, 如 http://192.168.244.144:8080
# BOOTSTRAP_TOKEN 爲 Jumpserver/config.yml 裏面的 BOOTSTRAP_TOKEN

docker run --name jms_koko -d -p 2222:2222 -p 127.0.0.1:5000:5000 -e CORE_HOST=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN -e LOG_LEVEL=ERROR --restart=always jumpserver/jms_koko:1.5.8

docker run --name jms_guacamole -d -p 127.0.0.1:8081:8080 -e JUMPSERVER_SERVER=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN -e GUACAMOLE_LOG_LEVEL=ERROR --restart=always jumpserver/jms_guacamole:1.5.8

15、安裝 Web Terminal 前端: Luna 需要 Nginx 來運行訪問 訪問(https://github.com/jumpserver/luna/releases)下載對應版本的 release 包, 直接解壓, 不需要編譯

cd /opt
wget https://github.com/jumpserver/luna/releases/download/1.5.8/luna.tar.gz

# 如果網絡有問題導致下載無法完成可以使用下面地址
wget https://demo.jumpserver.org/download/luna/1.5.8/luna.tar.gz
tar xf luna.tar.gz
chown -R root:root luna

16、配置 Nginx 整合各組件

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

#精簡主配置文件
cat >/etc/nginx/nginx.conf<<EOF
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 65535;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   120;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;
}
EOF

cat >/etc/nginx/conf.d/jumpserver.conf<<\EOF
server {
    listen 80;
    server_name 10.0.0.41;

    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 /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_pass http://localhost:8070;
        proxy_http_version 1.1;
        proxy_buffering off;
        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 / {
        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;
        access_log off;
    }
}
EOF

運行 Nginx

nginx -t
sed -i 's/KillMode/#KillMode/g' /usr/lib/systemd/system/nginx.service
systemctl start nginx

17、測試連接jumpserver

# 訪問 http://10.0.0.41 (注意 沒有 :8080 通過 nginx 代理端口進行訪問)
# 默認賬號: admin 密碼: admin  到會話管理-終端管理 接受 koko Guacamole 等應用的註冊
# 測試連接
$ ssh -p2222 [email protected]
$ sftp -P2222 [email protected]
  密碼: admin

# 如果是用在 Windows 下, Xshell Terminal 登錄語法如下
$ ssh [email protected] 2222
$ sftp [email protected] 2222
  密碼: admin
  如果能登陸代表部署成功

# sftp默認上傳的位置在資產的 /tmp 目錄下
# windows拖拽上傳的位置在資產的 Guacamole RDP上的 G 目錄下

web頁面操作

登錄
用戶和密碼都是admin

訪問:http://10.0.0.44
創建管理用戶
在這裏插入圖片描述
創建系統用戶
在這裏插入圖片描述
創建資產列表
在這裏插入圖片描述
資產授權
在這裏插入圖片描述
web終端連接服務器
在這裏插入圖片描述
在這裏插入圖片描述

xshell連接jumpserver管理服務器

在這裏插入圖片描述

在這裏插入圖片描述
如果遇到裝不了的可以進去文件裏面註釋掉 然後 等到最後 再進行安裝 一定要注意文件DBPassword

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