这是以前在北京老男孩时,写的笔记,分享给大家。
介绍
Jumpserver 是全球首款完全开源的堡垒机,使用 GNU GPL v2.0 开源协议,是符合 4A 的专业运维审计系统。
Jumpserver 使用 Python / Django 进行开发,遵循 Web 2.0 规范,配备了业界领先的 Web Terminal 解决方案,交互界面美观、用户体验好。
Jumpserver 采纳分布式架构,支持多机房跨区域部署,中心节点提供 API,各机房部署登录节点,可横向扩展、无并发访问限制。
安装
- 环境准备
修改字符集,否则可能报 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 虚拟环境
安装依赖包yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git
编译安装
wget http://192.168.21.72:8080/Python-3.6.1.tar.xz tar xvf Python-3.6.1.tar.xz && cd Python-3.6.1 ./configure && make && make install
建立 Python 虚拟环境
cd /opt python3 -m venv py3 source /opt/py3/bin/activate
退出python虚拟环境
deactivate
看到下面的提示符代表成功,以后运行 Jumpserver 都要先运行以上
source
命令,以下所有命令均在该虚拟环境中运行(py3) [root@localhost py3]
自动载入虚拟环境
cd /opt git clone https://github.com/kennethreitz/autoenv.git echo 'source /opt/autoenv/activate.sh' >> ~/.bashrc source ~/.bashrc
安装jumpserver
cd /usr/local/
wgethttp://192.168.21.72:8080/web/jumpserver-master.zip
unzip jumpserver-master.zip
mv jumpserver-master jumpserver
cd jumpserver/
echo "source /opt/py3/bin/activate" > .env # 进入 jumpserver 目录时将自动载入 python 虚拟环境
首次进入 jumpserver 文件夹会有提示,按 y 即可
Are you sure you want to allow this? (y/N) y
安装依赖 RPM 包
(py3) [root@jumpserver requirements]# pwd
/usr/local/jumpserver/requirements
(py3) [root@jumpserver requirements]# yum -y install $(cat rpm_requirements.txt)
(py3) [root@jumpserver requirements]# pip install -r requirements.txt
redis和mysql使用现有的机器
创建数据库 Jumpserver 并授权
create database jumpserver default charset 'utf8';
grant all on jumpserver.* to 'jumpserver'@'172.16.1.21' identified by '123456';
flush privileges;
配置jumpserver
本例配置文件路径
[root@jumpserver ~]# cd /usr/local/jumpserver/
(py3) [root@jumpserver jumpserver]# cp config_example.py config.py
(py3) [root@jumpserver jumpserver]# vim 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
# 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 '172.16.1.51'
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 '123456'
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 '172.16.1.91'
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()
生成数据库表结构
(py3) [root@jumpserver utils]# pwd
/usr/local/jumpserver/utils
bash make_migrations.sh
运行jumpserver
(py3) [root@jumpserver jumpserver]# pwd
/usr/local/jumpserver
./jms start all # 后台运行使用 -d 参数./jms start all -d
新版本更新了运行脚本,使用方式./jms start|stop|status|restart all 后台运行请添加 -d 参数
运行不报错,请浏览器访问 http://172.16.1.21:8080
默认账号: admin 密码: admin 页面显示不正常先不用处理,继续往下操作,后面搭建 nginx 代理后即可正常访问,原因是因为 django 无法在非 debug 模式下加载静态资源
安装 SSH Server 和 WebSocket Server: Coco
新开一个终端,别忘了 source /opt/py3/bin/activate
cd /usr/local
source /opt/py3/bin/activate
git clone https://github.com/jumpserver/coco.git && cd coco && git checkout master
echo "source /opt/py3/bin/activate" > .env # 进入 coco 目录时将自动载入 python 虚拟环境
首次进入 coco
文件夹会有提示,按 y
即可
Are you sure you want to allow this? (y/N) y
安装依赖
cd /usr/local/coco/requirements
yum -y install $(cat rpm_requirements.txt)
pip install -r requirements.txt
修改配置文件并运行
cd /usr/local
mkdir keys,logs
cp conf_example.py conf.py # 如果 coco 与 jumpserver 分开部署,请手动修改 conf.py
vim 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请求注册会使用
# 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
# 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
参数
启动成功后去Jumpserver 会话管理-终端管理(http://172.16.1.21:8080/terminal/terminal/
)接受coco的注册