簡介:
Jumpserver 是全球首款完全開源的堡壘機,使用 GNU GPL v2.0 開源協議,是符合 4A 的專業運維審計系統。
Jumpserver 使用 Python / Django 進行開發,遵循 Web 2.0 規範,配備了業界領先的 Web Terminal 解決方案,交互界面美觀、用戶體驗好。
Jumpserver 採納分佈式架構,支持多機房跨區域部署,中心節點提供 API,各機房部署登錄節點,可橫向擴展、無併發訪問限制。
安裝文檔:http://docs.jumpserver.org/zh/docs/installation.html
以下爲虛擬機安裝上測試安裝步驟:
cd /opt/jumpserver && ./jms restart all -d
# 新版本更新了運行腳本,使用方式./jms start|stop|status|restart all 後臺運行請添加 -d 參數
cd /opt/jumpserver && ./jms restart all -d
cd /opt/coco && ./cocod restart -d
cd /opt/jumpserver && ./jms stop all -d
cd /opt/coco && ./cocod stop -d
cd /opt/coco && ./cocod restart -d
./cocod restart -d
# 新版本更新了運行腳本,使用方式./cocod start|stop|status|restart 後臺運行請添加 -d 參數
systemctl restart nginx
###################jumpserver##################################
官網文檔:http://docs.jumpserver.org/zh/docs/step_by_step.html
# 關閉selinux 防火牆
# setenforce 0 # 臨時關閉,重啓後失效
# vim /etc/selinux/config
SELINUX=disabled
# systemctl stop firewalld.service # 臨時關閉,重啓後失效
# systemctl disable firewalld
# 修改字符集,否則可能報 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
# 依賴包
yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git
# 下載編譯安裝python
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
# 虛擬環境
cd /opt/
python3 -m venv py3
git clone git://github.com/kennethreitz/autoenv.git
echo 'source /opt/autoenv/activate.sh' >> ~/.bashrc
source ~/.bashrc
# 安裝jumpserver
cd /opt/
git clone https://github.com/jumpserver/jumpserver.git && cd jumpserver && git checkout master
# 進入 jumpserver 目錄時將自動載入 python 虛擬環境
# echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env
# 首次進入 jumpserver 文件夾會有提示,按 y 即可
# Are you sure you want to allow this? (y/N) y
# cd /opt/jumpserver/requirements
# yum -y install $(cat rpm_requirements.txt)
# pip install -r requirements.txt
# 安裝 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke
# yum -y install redis
# systemctl enable redis
# systemctl start redis
# 使用 Mysql 作爲數據庫,如果不使用 Mysql 可以跳過相關 Mysql 安裝和配置
# yum -y install mariadb mariadb-devel mariadb-server
# systemctl enable mariadb
# systemctl start mariadb
# mysql -uroot -p
yoyi2018
> create database jumpserver default charset 'utf8';
> grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by 'yoyi2018';
> flush privileges;# 修改jumpserver配置文件
# cd /opt/jumpserver
# cp config_example.py config.py
# vim config.py
########以下爲文件內容##########
"""
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
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY') or '2vym+ky!997d5kkcc64mnz06y1mmui3lut#(^wd=%s_qj$1%x'
# Django security setting, if your disable debug model, you should setting that
ALLOWED_HOSTS = ['*']
# Development env open this, when error occur display the full process track, Production disable it
DEBUG = os.environ.get("DEBUG") or True
# DEBUG, INFO, WARNING, ERROR, CRITICAL can set. See https://docs.djangoproject.com/en/1.10/topics/logging/
LOG_LEVEL = os.environ.get("LOG_LEVEL") or 'DEBUG'
LOG_DIR = os.path.join(BASE_DIR, 'logs')
# Database setting, Support sqlite3, mysql, postgres ....
# See https://docs.djangoproject.com/en/1.10/ref/settings/#databases
# SQLite setting:
# DB_ENGINE = 'sqlite3'
# DB_NAME = os.path.join(BASE_DIR, 'data', 'db.sqlite3')
# MySQL or postgres setting like:
# 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 'weakPassword'
# DB_NAME = os.environ.get("DB_NAME") or '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_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):
DEBUG = True
DB_ENGINE = 'mysql'
DB_HOST = '127.0.0.1'
DB_PORT = 3306
DB_USER = 'jumpserver'
DB_PASSWORD = 'yoyi2018'
DB_NAME = 'jumpserver'
class TestConfig(Config):
pass
class ProductionConfig(Config):
pass
# Default using Config settings, you can write if/else for different env
config = DevelopmentConfig()
##############文件結束##################
# cd /opt/jumpserver/utils
# bash make_migrations.sh
# 運行 Jumpserver
# cd /opt/jumpserver
# ./jms start all -d
# 新版本更新了運行腳本,使用方式./jms start|stop|status|restart all 後臺運行請添加 -d 參數
# 訪問 http://192.168.5.189:8080/ admin admin
# 後面搭建 nginx 代理後請通過代理的端口訪問,原因是因爲 django 無法在非 debug 模式下加載靜態資源
# 新開一個終端,別忘了 source /opt/py3/bin/activate
# source /opt/py3/bin/activate
# cd /opt/
# 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
# cd /opt/coco/requirements
# yum -y install $(cat rpm_requirements.txt)# 修改配置文件並運行
# cd /opt/coco
# cp conf_example.py conf.py
# vi conf.py
#######################文件內容#####################
#!/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|stop|status|restart 後臺運行請添加 -d 參數
# 啓動成功後去Jumpserver 會話管理-終端管理(http://192.168.5.189:8080/terminal/terminal/)接受coco的註冊
# Luna 已改爲純前端,需要 Nginx 來運行訪問
# 訪問(https://github.com/jumpserver/luna/releases)下載對應版本的 release 包,直接解壓,不需要編譯
# 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# 安裝 Nginx 根據喜好選擇安裝方式和版本
# yum -y install nginx
# vim /etc/nginx/nginx.conf
####################文件內容######################
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
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 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
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;
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
訪問測試即可!
單jumpserver 缺乏可靠性,解決方案 新建vip提供對外服務,建立備份jumpserver服務, 數據庫使用主主互備 ,keepalived心跳檢測 切換ip ,以下爲 my.conf 文件, 對於其他配置 可參考以前文檔 。
第一個 my.conf 文件
server-id=1
log-bin=log
relay_log=mariadb-relay-bin
binlog-do-db=jumpserver
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog_format=mixed
read-only=0
auto-increment-increment = 10
auto-increment-offset = 1
character_set_server=utf8
interactive_timeout = 57600
slave-skip-errors=all
log-slave-updates=ON
symbolic-links=0
skip-name-resolve
第二個my.conf文件
server-id=2
log-bin=log
binlog-do-db=jumpserver
binlog-ignore-db=mysql
binlog-ignore-db = information_schema
binlog_format=mixed
relay_log=mariadb-relay-bin
read-only=0
auto-increment-increment = 10
auto-increment-offset = 2
character_set_server=utf8
interactive_timeout = 57600
expire-logs-days = 100
slave-skip-errors=all
log-slave-updates = ON
symbolic-links=0
skip-name-resolve