jumpserver堡壘機安裝與配置


一步一步安裝(CentOS)

本文檔旨在幫助用戶了解各組件之間的關系,如果已經接觸過之前的版本,可參考 進階安裝文檔

安裝過程中遇到問題可參考 安裝過程中常見的問題

環境

  • 系統: CentOS 7
  • IP: 192.168.244.144
  • 關閉 selinux 和防火牆
# CentOS 7
$ setenforce 0  # 臨時關閉,重啟后失效
$ systemctl stop firewalld.service  # 臨時關閉,重啟后失效

# 修改字符集,否則可能報 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/locale.conf

# CentOS6
$ setenforce 0  # 臨時關閉,重啟后失效
$ service iptables stop  # 臨時關閉,重啟后失效

# 修改字符集,否則可能報 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.1 安裝依賴包

$ yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git

Yum 加速設置請參考 <http://mirrors.163.com/.help/centos.html>

1.2 編譯安裝

$ wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
$ tar xvf Python-3.6.1.tar.xz  && cd Python-3.6.1
$ ./configure && make && make install

# 這里必須執行編譯安裝,否則在安裝 Python 庫依賴時會有麻煩...

1.3 建立 Python 虛擬環境

因為 CentOS 6/7 自帶的是 Python2,而 Yum 等工具依賴原來的 Python,為了不擾亂原來的環境我們來使用 Python 虛擬環境

$ cd /opt
$ python3 -m venv py3
$ source /opt/py3/bin/activate

# 看到下面的提示符代表成功,以后運行 Jumpserver 都要先運行以上 source 命令,以下所有命令均在該虛擬環境中運行
(py3) [root@localhost py3]

1.4 自動載入 Python 虛擬環境配置

此項僅為懶癌晚期的人員使用,防止運行 Jumpserver 時忘記載入 Python 虛擬環境導致程序無法運行。使用autoenv

$ cd /opt
$ git clone git://github.com/kennethreitz/autoenv.git
$ echo 'source /opt/autoenv/activate.sh' >> ~/.bashrc
$ source ~/.bashrc

二. 安裝 Jumpserver

2.1 下載或 Clone 項目

項目提交較多 git clone 時較大,你可以選擇去 Github 項目頁面直接下載zip包。

cd /opt

wget https://github.com/jumpserver/jumpserver/archive/master.zip

yum install unzip -y

unzip master.zip

mv jumpserver-master/ jumpserver

$ cd /opt/
$ git clone https://github.com/jumpserver/jumpserver.git && cd jumpserver && git checkout master
$ 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.2 安裝依賴 RPM 包

$ cd /opt/jumpserver/requirements
$ yum -y install $(cat rpm_requirements.txt)  # 如果沒有任何報錯請繼續

2.3 安裝 Python 庫依賴

       pip install wheel && \ pip install --upgrade pip setuptools && \ pip install -r requirements.txt

$ pip install -r requirements.txt  # 不要指定-i參數,因為鏡像上可能沒有最新的包,如果沒有任何報錯請繼續
報錯:mysql_config not found
解決方法:yum -y install mariadb mariadb-devel mariadb-server

Pip 加速設置請參考 <https://segmentfault.com/a/1190000011875306>

2.4 安裝 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke

$ yum -y install redis
$ systemctl enable redis
$ systemctl start redis

# centos6
$ yum -y install redis
$ chkconfig redis on
$ service redis start

2.5 安裝 MySQL

本教程使用 Mysql 作為數據庫,如果不使用 Mysql 可以跳過相關 Mysql 安裝和配置

# centos7
$ yum -y install mariadb mariadb-devel mariadb-server # centos7下安裝的是mariadb
$ systemctl enable mariadb
$ systemctl start mariadb

# centos6
$ yum -y install mysql mysql-devel mysql-server
$ chkconfig mysqld on
$ service mysqld start

2.6 創建數據庫 Jumpserver 並授權

$ mysql
> create database jumpserver default charset 'utf8';
> grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by 'somepassword';
> flush privileges;

2.7 修改 Jumpserver 配置文件

$ cd /opt/jumpserver
$ cp config_example.py config.py
$ vi config.py

# 注意對齊,不要直接復制本文檔的內容,實際內容以文件為准,本文僅供參考

注意: 配置文件是 Python 格式,不要用 TAB,而要用空格

"""
 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: # Use it to encrypt or decrypt data # Jumpserver 使用 SECRET_KEY 進行加密,請務必修改以下設置 # SECRET_KEY = os.environ.get('SECRET_KEY') or '2vym+ky!997d5kkcc64mnz06y1mmui3lut#(^wd=%s_qj$1%x' SECRET_KEY = '請隨意輸入隨機字符串(推薦字符大於等於 50位)' # Django security setting, if your disable debug model, you should setting that ALLOWED_HOSTS = ['*'] # DEBUG 模式 True為開啟 False為關閉,默認開啟,生產環境推薦關閉 # 注意:如果設置了DEBUG = False,訪問8080端口頁面會顯示不正常,需要搭建 nginx 代理才可以正常訪問 DEBUG = os.environ.get("DEBUG") or True # 日志級別,默認為DEBUG,可調整為INFO, WARNING, ERROR, CRITICAL,默認INFO LOG_LEVEL = os.environ.get("LOG_LEVEL") or 'WARNING' LOG_DIR = os.path.join(BASE_DIR, 'logs') # 使用的數據庫配置,支持sqlite3, mysql, postgres等,默認使用sqlite3 # See https://docs.djangoproject.com/en/1.10/ref/settings/#databases # 默認使用SQLite3,如果使用其他數據庫請注釋下面兩行 # DB_ENGINE = 'sqlite3' # DB_NAME = os.path.join(BASE_DIR, 'data', 'db.sqlite3') # 如果需要使用mysql或postgres,請取消下面的注釋並輸入正確的信息,本例使用mysql做演示(mariadb也是mysql) DB_ENGINE = os.environ.get("DB_ENGINE") or 'mysql' DB_HOST = os.environ.get("DB_HOST") or '127.0.0.1' DB_PORT = os.environ.get("DB_PORT") or 3306 DB_USER = os.environ.get("DB_USER") or 'jumpserver' DB_PASSWORD = os.environ.get("DB_PASSWORD") or 'somepassword' DB_NAME = os.environ.get("DB_NAME") or 'jumpserver' # Django 監聽的ip和端口,生產環境推薦把0.0.0.0修改成127.0.0.1,這里的意思是允許x.x.x.x訪問,127.0.0.1表示僅允許自身訪問 # ./manage.py runserver 127.0.0.1:8080 HTTP_BIND_HOST = '0.0.0.0' HTTP_LISTEN_PORT = 8080 # Redis 相關設置 REDIS_HOST = os.environ.get("REDIS_HOST") or '127.0.0.1' REDIS_PORT = os.environ.get("REDIS_PORT") or 6379 REDIS_PASSWORD = os.environ.get("REDIS_PASSWORD") or '' REDIS_DB_CELERY = os.environ.get('REDIS_DB') or 3 REDIS_DB_CACHE = os.environ.get('REDIS_DB') or 4 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() 

2.8 生成數據庫表結構和初始化數據

$ cd /opt/jumpserver/utils
$ bash make_migrations.sh

2.9 運行 Jumpserver

$ cd /opt/jumpserver
$ ./jms start all  # 后台運行使用 -d 參數./jms start all -d

# 新版本更新了運行腳本,使用方式./jms start|stop|status|restart all  后台運行請添加 -d 參數

運行不報錯,請瀏覽器訪問 http://192.168.244.144:8080/ 默認賬號: admin 密碼: admin 后面搭建 nginx 代理后請通過代理的端口訪問,原因是因為 django 無法在非 debug 模式下加載靜態資源

三. 安裝 SSH Server 和 WebSocket Server: Coco

3.1 下載或 Clone 項目

新開一個終端,別忘了 source /opt/py3/bin/activate

$ cd /opt
$ source /opt/py3/bin/activate
$ git clone https://github.com/jumpserver/coco.git && cd coco && git checkout master
$ echo "source /opt/py3/bin/activate" > /opt/coco/.env  # 進入 coco 目錄時將自動載入 python 虛擬環境

# 首次進入 coco 文件夾會有提示,按 y 即可
# Are you sure you want to allow this? (y/N) y

wget https://github.com/jumpserver/koko/releases/download/1.5.9/koko-master-linux-amd64.tar.gz
tar -xf koko-master-linux-amd64.tar.gz && \ chown -R root:root kokodir && \ cd kokodir
cp config_example.yml config.yml && \ vi config.yml

3.2 安裝依賴

$ cd /opt/coco/requirements
$ yum -y  install $(cat rpm_requirements.txt)
$ pip install -r requirements.txt

3.3 修改配置文件並運行

$ cd /opt/coco
$ cp conf_example.py conf.py  # 如果 coco 與 jumpserver 分開部署,請手動修改 conf.py
$ vi conf.py

# 注意對齊,不要直接復制本文檔的內容

注意: 配置文件是 Python 格式,不要用 TAB,而要用空格

#!/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請求注冊會使用, 如果Jumpserver沒有運行在127.0.0.1:8080,請修改此處 # CORE_HOST = os.environ.get("CORE_HOST") or 'http://127.0.0.1:8080' CORE_HOST = 'http://127.0.0.1:8080' # 啟動時綁定的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 = 'WARN' # 日志存放的目錄 # 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 # 和Jumpserver 保持心跳時間間隔 # HEARTBEAT_INTERVAL = 5 # Admin的名字,出問題會提示給用戶 # ADMINS = '' COMMAND_STORAGE = { "TYPE": "server" } REPLAY_STORAGE = { "TYPE": "server" } config = Config() 
$ ./cocod start  # 后台運行使用 -d 參數./cocod start -d

# 新版本更新了運行腳本,使用方式./cocod start|stop|status|restart  后台運行請添加 -d 參數

啟動成功后去Jumpserver 會話管理-終端管理(http://192.168.244.144:8080/terminal/terminal/)接受coco的注冊

四. 安裝 Web Terminal 前端: Luna

Luna 已改為純前端,需要 Nginx 來運行訪問

訪問(https://github.com/jumpserver/luna/releases)下載對應版本的 release 包,直接解壓,不需要編譯

4.1 解壓 Luna

$ cd /opt
$ wget https://github.com/jumpserver/luna/releases/download/1.4.0/luna.tar.gz
$ tar xvf luna.tar.gz
$ chown -R root:root luna

五. 安裝 Windows 支持組件(如果不需要管理 windows 資產,可以直接跳過這一步)

因為手動安裝 guacamole 組件比較復雜,這里提供打包好的 docker 使用, 啟動 guacamole

5.1 Docker安裝 (僅針對CentOS7,CentOS6安裝Docker相對比較復雜)

$ yum remove docker-latest-logrotate docker-logrotate docker-selinux dockdocker-engine
$ yum install -y yum-utils device-mapper-persistent-data lvm2

# 添加docker官方源
$ yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
$ yum makecache fast
$ yum install docker-ce


# 國內部分用戶可能無法連接docker官網提供的源,這里提供阿里雲的鏡像節點供測試使用
$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
$ rpm --import http://mirrors.aliyun.com/docker-ce/linux/centos/gpg
$ yum makecache fast
$ yum -y install docker-ce

$ systemctl start docker
$ systemctl status docker

5.2 啟動 Guacamole

這里所需要注意的是 guacamole 暴露出來的端口是 8081,若與主機上其他端口沖突請自定義

啟動成功后去Jumpserver 會話管理-終端管理(http://192.168.244.144:8080/terminal/terminal/)接受[Gua]開頭的一個注冊

# 注意:這里需要修改下 http://<填寫jumpserver的url地址> 例: http://192.168.244.144, 否則會出錯, 帶寬有限, 下載時間可能有點長,可以喝杯咖啡,撩撩對面的妹子
# 不能使用 127.0.0.1 ,可以更換 registry.jumpserver.org/public/guacamole:latest

$ 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://<填寫jumpserver的url地址> \
  docker.io/jumpserver/guacamole:latest

docker run --name jms_guacamole -d \
-p 8083:8080 -v /opt/guacamole/key:/config/guacamole/key \
-e JUMPSERVER_KEY_DIR=/config/guacamole/key \
-e JUMPSERVER_SERVER=http://192.168.1.31:8080 \
-e BOOTSTRAP_TOKEN=zxffNymGjP79j6BN \
jumpserver/jms_guacamole:1.5.9

六. 配置 Nginx 整合各組件

6.1 安裝 Nginx 根據喜好選擇安裝方式和版本

$ yum -y install nginx

6.2 准備配置文件 修改 /etc/nginx/nginx.conf

內容如下:

$ vim /etc/nginx/nginx.conf
# CentOS 6 需要修改文件 /etc/nginx/cond.f/default.conf

... 省略
# 把默認server配置塊改成這樣,原有的內容請保持不動

server {
    listen 80;  # 代理端口,以后將通過此端口進行訪問,不再通過8080端口

    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 /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;
    }
}

... 省略

6.3 運行 Nginx

nginx -t   # 確保配置沒有問題, 有問題請先解決

# CentOS 7
$ systemctl start nginx
$ systemctl enable nginx


# CentOS 6
$ service nginx start
$ chkconfig nginx on

6.4 開始使用 Jumpserver

檢查應用是否已經正常運行

$ cd /opt/jumpserver
$ ./jms status  # 確定jumpserver已經運行,如果沒有運行請重新啟動jumpserver

$ cd /opt/coco
$ ./cocod status  # 確定jumpserver已經運行,如果沒有運行請重新啟動coco

# 如果安裝了 Guacamole
$ docker ps  # 檢查容器是否已經正常運行,如果沒有運行請重新啟動Guacamole

服務全部啟動后,訪問 http://192.168.244.144,訪問nginx代理的端口,不要再通過8080端口訪問

默認賬號: admin 密碼: admin

如果部署過程中沒有接受應用的注冊,需要到Jumpserver 會話管理-終端管理 接受 Coco Guacamole 等應用的注冊。

測試連接

如果登錄客戶端是 macOS 或 Linux ,登錄語法如下
$ ssh -p2222 admin@192.168.244.144
$ sftp -P2222 admin@192.168.244.144
密碼: admin

如果登錄客戶端是 Windows ,Xshell Terminal 登錄語法如下
$ ssh admin@192.168.244.144 2222
$ sftp admin@192.168.244.144 2222
密碼: admin
如果能登陸代表部署成功

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM