centos 7 部署新版 jumpserver(堡垒机)
关闭防火墙和 selinux
# setenforce 0 # systemctl stop firewalld.service
准备 Python3 和 Python 虚拟环境
最新的 jumpserver 环境依赖于 Python3
安装依赖包
# yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git # wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz # tar xf Python-3.6.1.tar.xz && cd Python-3.6.1 # ./configure && make install #这里必须执行编译安装,否则在安装 Python 库依赖时会有麻烦
建立 Python 虚拟环境
CentOS 7 自带 Python 2 ,而 yum 等工具依赖原来的 Python , 为了不扰乱原来的环境我们来使用 Python 虚拟环境
[root@jumpserver Python-3.6.1]# cd /opt [root@jumpserver opt]# python3 -m venv py3 [root@jumpserver opt]# source /opt/py3/bin/activate # 看到下面的提示符代表成功,以后运行 Jumpserver 都要先运行以上 source 命令,以下所有命令均在该虚拟环境中运行 (py3) [root@jumpserver opt]#
自动载入 Python 虚拟环境配置
此项仅为懒人使用,防止运行 Jumpserver 时忘记载入 Python 虚拟环境导致程序无法运行,使用 autoenv
(py3) [root@jumpserver ~]# cd /opt (py3) [root@jumpserver opt]# git clone git://github.com/kennethreitz/autoenv.git (py3) [root@jumpserver opt]# echo 'source /opt/autoenv/activate.sh' >> ~/.bashrc (py3) [root@jumpserver opt]# source ~/.bashrc
安装 Jumpserver
下载或 Clone 项目
项目提交较多 git clone 时较大,你可以选择 Github 项目页面直接下载 zip 包
(py3) [root@jumpserver opt]# git clone https://github.com/jumpserver/jumpserver.git && cd jumpserver && git checkout master (py3) [root@jumpserver jumpserver]# echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env # 进入 jumpserver 目录时将自动载入 python 虚拟环境 (py3) [root@jumpserver jumpserver]# cd requirements/ # 首次进入 jumpserver 文件夹会有提示,按 y 即可 # Are you sure you want to allow this? (y/N) y
安装依赖 RPM 包
(py3) [root@jumpserver requirements]# yum -y install $(cat rpm_requirements.txt)
安装 Python 库依赖
(py3) [root@jumpserver requirements]# pip install -r requirements.txt
安装 Redis ,Jumpserver 使用 Redis 做 cache 和 celery broke
(py3) [root@jumpserver requirements]# yum -y install redis (py3) [root@jumpserver requirements]# systemctl enable redis Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service. (py3) [root@jumpserver requirements]# systemctl start redis
安装 MySQL
(py3) [root@jumpserver requirements]# yum -y install mariadb mariadb-devel mariadb-server (py3) [root@jumpserver requirements]# systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. (py3) [root@jumpserver requirements]# systemctl start mariadb
创建数据库 Jumpserver 并授权
(py3) [root@jumpserver requirements]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database jumpserver default charset 'utf8'; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by 'somepassword'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)
修改 Jumpserver 配置文件
(py3) [root@jumpserver requirements]# cd /opt/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 # 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 False # 日志级别,默认为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 = '127.0.0.1' 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()
生成数据库表结构和初始化数据库
(py3) [root@jumpserver jumpserver]# cd /opt/jumpserver/utils
(py3) [root@jumpserver utils]# bash make_migrations.sh
运行 Jumpserver
(py3) [root@jumpserver utils]# cd /opt/jumpserver (py3) [root@jumpserver jumpserver]# ./jms start all # 新版本更新了运行脚本,使用方式./jms start|stop|status|restart all 后台运行请添加 -d 参数