centos7 jumpserver 部署和使用手冊(一)


測試推薦環境

  • CPU: 64位雙核處理器
  • 內存: 4G DDR3
  • 數據庫:mysql 版本大於等於 5.6 mariadb 版本大於等於 5.5.6

環境

  • 系統: CentOS 7.2
  • IP: 192.168.12.183
  • 設置 selinux 和防火牆
$ 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
$ sed -i "s/enforcing/disabled/g" /etc/selinux/config
# 修改字符集,否則可能報 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
 
          

一. 准備 Python3 和 Python 虛擬環境

1.1 安裝依賴包

$ yum -y install wget gcc epel-release git

1.2 安裝 Python3.6

$ yum -y install python36 python36-devel

1.3 建立 Python 虛擬環境

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

$ cd /opt
$ python3.6 -m venv py3
$ source /opt/py3/bin/activate # 看到下面的提示符代表成功,以后運行 Jumpserver 都要先運行以上 source 命令,以下所有命令均在該虛擬環境中運行 (py3) [root@localhost py3] 

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

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

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

二. 安裝 Jumpserver

2.1 下載或 Clone 項目

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

$ cd /opt/
$ git clone https://github.com/jumpserver/jumpserver.git
$ 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 --upgrade pip setuptools
$ pip install -r requirements.txt

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

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

2.5 安裝 MySQL

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

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

2.6 創建數據庫 Jumpserver 並授權

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

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:
    """
    Jumpserver Config File
    Jumpserver 配置文件

    Jumpserver use this config for drive django framework running,
    You can set is value or set the same envirment value,
    Jumpserver look for config order: file => env => default

    Jumpserver使用配置來驅動Django框架的運行,
    你可以在該文件中設置,或者設置同樣名稱的環境變量,
    Jumpserver使用配置的順序: 文件 => 環境變量 => 默認值
    """
    # SECURITY WARNING: keep the secret key used in production secret!
    # 加密秘鑰 生產環境中請修改為隨機字符串,請勿外泄
    SECRET_KEY = '2vym+ky!997d5kkcc64mnz06y1mmui3lut#(^wd=%s_qj$1%x'

    # Django security setting, if your disable debug model, you should setting that
    ALLOWED_HOSTS = ['*']

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

    # 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_DIR = os.path.join(BASE_DIR, 'logs')
    LOG_LEVEL = 'ERROR'
    LOG_DIR = os.path.join(BASE_DIR, 'logs')

    # Session expiration setting, Default 24 hour, Also set expired on on browser close
    # 瀏覽器Session過期時間,默認24小時, 也可以設置瀏覽器關閉則過期
    # SESSION_COOKIE_AGE = 3600 * 24
    # SESSION_EXPIRE_AT_BROWSER_CLOSE = False
    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 = os.path.join(BASE_DIR, 'data', 'db.sqlite3')

    # MySQL or postgres setting like:
    # 使用Mysql作為數據庫
    DB_ENGINE = 'mysql'
    DB_HOST = '127.0.0.1'
    DB_PORT = 3306
    DB_USER = 'jumpserver'
    DB_PASSWORD = 'weakPassword'
    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

    # Use Redis as broker for celery and web socket
    # Redis配置
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379
    # REDIS_PASSWORD = ''
    # REDIS_DB_CELERY_BROKER = 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'

    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 運行 Jumpserver

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

運行不報錯, 請繼續往下操作

三. 安裝 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 $ echo "source /opt/py3/bin/activate" > /opt/coco/.env # 進入 coco 目錄時將自動載入 python 虛擬環境 # 首次進入 coco 文件夾會有提示,按 y 即可 # Are you sure you want to allow this? (y/N) y 

3.2 安裝依賴

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

3.3 修改配置文件並運行

$ cd /opt/coco
$ mkdir keys logs
$ 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"

    # 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'

    # Bootstrap Token, 預共享秘鑰, 用來注冊coco使用的service account和terminal
    # 請和jumpserver 配置文件中保持一致,注冊完成后可以刪除
    # BOOTSTRAP_TOKEN = "PleaseChangeMe"
    BOOTSTRAP_TOKEN = "nwv4RdXpM82LtSvmV"

    # 啟動時綁定的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 = 'ERROR'

    # 日志存放的目錄
    # 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

    # SSH白名單
    # ALLOW_SSH_USER = 'all'  # ['test', 'test2']

    # SSH黑名單, 如果用戶同時在白名單和黑名單,黑名單優先生效
    # BLOCK_SSH_USER = []

    # 和Jumpserver 保持心跳時間間隔
    # HEARTBEAT_INTERVAL = 5

    # Admin的名字,出問題會提示給用戶
    # ADMINS = ''
    COMMAND_STORAGE = {
        "TYPE": "server"
    }
    REPLAY_STORAGE = {
        "TYPE": "server"
    }

    # SSH連接超時時間 (default 15 seconds)
    # SSH_TIMEOUT = 15

    # 語言 = en
    LANGUAGE_CODE = 'zh'


config = Config()
$ ./cocod start  # 后台運行使用 -d 參數./cocod start -d

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

 

四. 安裝 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.6/luna.tar.gz
$ tar xf luna.tar.gz
$ chown -R root:root luna

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

Guacamole 需要 Tomcat 來運行

5.1 安裝依賴

$ mkdir /usr/local/lib/freerdp/
$ ln -s /usr/local/lib/freerdp /usr/lib64/freerdp
$ rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
$ rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
$ yum -y localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm

$ yum install -y java-1.8.0-openjdk libtool
$ yum install -y cairo-devel libjpeg-turbo-devel libpng-devel uuid-devel
$ yum install -y ffmpeg-devel freerdp-devel freerdp-plugins pango-devel libssh2-devel libtelnet-devel libvncserver-devel pulseaudio-libs-devel openssl-devel libvorbis-devel libwebp-devel ghostscript

5.2 編譯安裝 guacamole 服務

$ cd /opt
$ git clone https://github.com/jumpserver/docker-guacamole.git
$ cd /opt/docker-guacamole/ $ tar -xf guacamole-server-0.9.14.tar.gz $ cd guacamole-server-0.9.14 $ autoreconf -fi $ ./configure --with-init-dir=/etc/init.d $ make && make install $ cd .. $ rm -rf guacamole-server-0.9.14 $ ldconfig 

5.3 配置 Tomcat

$ mkdir -p /config/guacamole /config/guacamole/lib /config/guacamole/extensions  # 創建 guacamole 目錄
$ ln -sf /opt/docker-guacamole/guacamole-auth-jumpserver-0.9.14.jar /config/guacamole/extensions/guacamole-auth-jumpserver-0.9.14.jar
$ ln -sf /opt/docker-guacamole/root/app/guacamole/guacamole.properties /config/guacamole/guacamole.properties  # guacamole 配置文件 $ cd /config $ wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz $ tar xf apache-tomcat-8.5.35.tar.gz $ rm -rf apache-tomcat-8.5.35.tar.gz $ mv apache-tomcat-8.5.35 tomcat8 $ rm -rf /config/tomcat8/webapps/* $ ln -sf /opt/docker-guacamole/guacamole-0.9.14.war /config/tomcat8/webapps/ROOT.war # guacamole client $ sed -i 's/Connector port="8080"/Connector port="8081"/g' /config/tomcat8/conf/server.xml # 修改默認端口為 8081 $ sed -i 's/FINE/WARNING/g' /config/tomcat8/conf/logging.properties # 修改 log 等級為 WARNING $ cd /config $ wget https://github.com/ibuler/ssh-forward/releases/download/v0.0.5/linux-amd64.tar.gz $ tar xf linux-amd64.tar.gz -C /bin/ $ chmod +x /bin/ssh-forward 

5.4 配置環境變量

$ export JUMPSERVER_SERVER=http://127.0.0.1:8080 # http://127.0.0.1:8080 指 jumpserver 訪問地址 $ echo "export JUMPSERVER_SERVER=http://127.0.0.1:8080" >> ~/.bashrc # BOOTSTRAP_TOKEN 為 Jumpserver/config.py 里面的 BOOTSTRAP_TOKEN $ export BOOTSTRAP_TOKEN=nwv4RdXpM82LtSvmV $ echo "export BOOTSTRAP_TOKEN=nwv4RdXpM82LtSvmV" >> ~/.bashrc $ export JUMPSERVER_KEY_DIR=/config/guacamole/keys $ echo "export JUMPSERVER_KEY_DIR=/config/guacamole/keys" >> ~/.bashrc $ export GUACAMOLE_HOME=/config/guacamole $ echo "export GUACAMOLE_HOME=/config/guacamole" >> ~/.bashrc 

5.5 啟動 Guacamole

$ /etc/init.d/guacd start
$ sh /config/tomcat8/bin/startup.sh

六. 配置 Nginx 整合各組件

6.1 安裝 Nginx

$ vi /etc/yum.repos.d/nginx.repo

[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 $ yum install -y nginx $ rm -rf /etc/nginx/conf.d/default.conf $ systemctl enable nginx 

6.3 准備配置文件 修改 /etc/nginx/conf.d/jumpserver.conf

$ vi /etc/nginx/conf.d/jumpserver.conf server { listen 80; # 代理端口,以后將通過此端口進行訪問,不再通過8080端口 # server_name demo.jumpserver.org; # 修改成你的域名或者注釋掉 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 /coco/ { proxy_pass http://localhost:5000/coco/; # 如果coco安裝在別的服務器,請填寫它的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; 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 

6.4 開始使用 Jumpserver

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

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

默認賬號: admin 密碼: admin

到Jumpserver 會話管理-終端管理 檢查 Coco Guacamole 等應用的注冊。


免責聲明!

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



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