最近很多小伙伴都在问centos7使用docker安装jumpserver和centos7安装docker-compose这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展cento
最近很多小伙伴都在问centos7 使用 docker 安装 jumpserver和centos7 安装docker-compose这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展centos 安装 jumpserver、centos 7.x 安装开源堡垒机Jumpserver、CentOS 7下JumpServer安装及配置、Centos 7安装配置jumpserver堡垒机等相关知识,下面开始了哦!
本文目录一览:- centos7 使用 docker 安装 jumpserver(centos7 安装docker-compose)
- centos 安装 jumpserver
- centos 7.x 安装开源堡垒机Jumpserver
- CentOS 7下JumpServer安装及配置
- Centos 7安装配置jumpserver堡垒机
centos7 使用 docker 安装 jumpserver(centos7 安装docker-compose)
一、安装 docker
1、针对内核版本高于 3.10 的 centos 系统。
2、替换阿里云 yum 源
- wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #下载阿里 yum 源
- yum makecache #生成仓库缓存
3、安装 docker
- yum install docker -y
4、启动 docker
- systemctl start docker #启动 docker
- systemctl enable docker #开机启动 docker
- systemctl status docker #查看 docker 状态
5、查看 docker 版本
- docker -v
二、安装 jumpserver
# 生成随机加密秘钥
1.if [ "$SECRET_KEY" = "" ]; then SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50`; echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc; echo $SECRET_KEY; else echo $SECRET_KEY; fi 2.if [ "$BOOTSTRAP_TOKEN" = "" ]; then BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16`; echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc; echo $BOOTSTRAP_TOKEN; else echo $BOOTSTRAP_TOKEN; fi 3.docker run --name jms_all -d -p 80:80 -p 2222:2222 -e SECRET_KEY=$SECRET_KEY -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN jumpserver/jms_all:1.4.8
三、docker 自启动 jumpserver
docker run --restart=always
如果已经启动了则可以使用如下命令:
docker update --restart=always <CONTAINER ID>
至此,docker 安装完毕。
centos 安装 jumpserver
Centos 6.8 安装 jumpserver
系统环境:
cat /etc/redhat-release
CentOS release 6.8 (Final)
Ip:192.168.137.31
一.关闭selinux
[root@localhost ~]# sed -i '/SELINUX=/s/enforcing/disabled/' /etc/selinux/config
[root@localhost ~]# cat /etc/selinux/config
临时设置关闭
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce 0
Permissive
二.测试的先关闭防火墙,测试完成再开启,添加相应的端口
[root@localhost ~]# service iptables stop
[root@localhost ~]# iptables -nL
三.升级python2.6至python2.7
[root@localhost ~]# wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
[root@localhost ~]# tar -jxvf Python-2.7.3.tar.bz2
[root@localhost ~]# cd Python-2.7.3
[root@localhost Python-2.7.3]# ./configure
[root@localhost Python-2.7.3]# make all
[root@localhost Python-2.7.3]# make && make install
[root@localhost Python-2.7.3]# make clean
[root@localhost Python-2.7.3]# mv /usr/bin/python /usr/bin/python.bak
[root@localhost bin]# ln -s /usr/local/bin/python2.7 /usr/bin/python
python -V检验是否成功
vim /usr/bin/yum
把第一行改为#!/usr/bin/python2.6
四.安装pip
[root@localhost ~]# curl -O https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz
[root@localhost ~]# tar zxvf pip-7.1.2.tar.gz
[root@localhost ~]# cd pip-7.1.2
[root@localhost pip-7.1.2]# python setup.py install #如果以下报错,是缺少setuptools模块
Traceback (most recent call last):
File "setup.py",line 6,in <module>
from setuptools import setup,find_packages
ImportError: No module named setuptools
安装setuptools模块
[root@localhost ~]#
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e --no-check-certificate
[root@localhost ~]# tar -zxvf setuptools-0.6c11.tar.gz
[root@localhost ~]# cd setuptools-0.6c11
[root@localhost setuptools-0.6c11]# python setup.py install
#出现以下报错,则是缺少zlib模块跟相关的依赖包:
File "setup.py",line 94,in <module>
scripts = scripts,
File "/usr/local/lib/python2.7/distutils/core.py",line 152,in setup
dist.run_commands()
File "/usr/local/lib/python2.7/distutils/dist.py",line 953,in run_commands
self.run_command(cmd)
File "/usr/local/lib/python2.7/distutils/dist.py",line 972,in run_command
cmd_obj.run()
File "/root/setuptools-0.6c11/setuptools/command/install.py",line 76,in run
self.do_egg_install()
File "/root/setuptools-0.6c11/setuptools/command/install.py",line 96,in do_egg_install
self.run_command('bdist_egg')
File "/usr/local/lib/python2.7/distutils/cmd.py",line 326,in run_command
self.distribution.run_command(command)
File "/usr/local/lib/python2.7/distutils/dist.py",in run_command
cmd_obj.run()
File "/root/setuptools-0.6c11/setuptools/command/bdist_egg.py",line 236,in run
dry_run=self.dry_run,mode=self.gen_header())
File "/root/setuptools-0.6c11/setuptools/command/bdist_egg.py",line 527,in make_zipfile
z = zipfile.ZipFile(zip_filename,mode,compression=compression)
File "/usr/local/lib/python2.7/zipfile.py",line 681,in __init__
"Compression requires the (missing) zlib module"
RuntimeError: Compression requires the (missing) zlib module
[root@localhost setuptools-0.6c11]# yum install zlib-devel
安装完zlib-devel依赖包或者模块,需要重新编译一下就可以了
root@localhost ~]# cd Python-2.7.3
[root@localhost Python-2.7.3]# make && make install
[root@localhost Python-2.7.3]# cd /root/setuptools-0.6c11
[root@localhost setuptools-0.6c11]# python setup.py install #成功执行
再去到pip路径重新执行pip程序就显示可以了
[root@localhost setuptools-0.6c11]# cd /root/pip-7.1.2
[root@localhost pip-7.1.2]# python setup.py install
[root@localhost pip-7.1.2]# ln -s /usr/local/bin/pip2.7 /usr/bin/pip
[root@localhost pip-7.1.2]# pip list #出现以下报错
Traceback (most recent call last):
File "/usr/local/bin/pip",line 8,in <module>
load_entry_point('pip==7.1.2','console_scripts','pip')()
File "build/bdist.linux-x86_64/egg/pkg_resources.py",line 318,in load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources.py",line 2221,line 1954,in load
File "/usr/local/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/__init__.py",line 15,in <module>
from pip.vcs import git,mercurial,subversion,bazaar # noqa
File "/usr/local/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/vcs/subversion.py",line 9,in <module>
from pip.index import Link
File "/usr/local/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/index.py",line 30,in <module>
from pip.wheel import Wheel,wheel_ext
File "/usr/local/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/wheel.py",line 35,in <module>
from pip._vendor.distlib.scripts import ScriptMaker
File "/usr/local/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/_vendor/distlib/scripts.py",line 14,in <module>
from .compat import sysconfig,detect_encoding,ZipFile
File "/usr/local/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/_vendor/distlib/compat.py",line 31,in <module>
from urllib2 import (Request,urlopen,URLError,HTTPError,
ImportError: cannot import name HTTPSHandler
处理:yum 安装openssl 和 openssl-devel,然后重新编译python
[root@localhost pip-7.1.2]# yum install openssl openssl-devel
[root@localhost pip-7.1.2]# cd /root/Python-2.7.3
再回到pip目录
[root@localhost Python-2.7.3]# cd /root/pip-7.1.2
[root@localhost pip-7.1.2]# pip list
pip (7.1.2)
setuptools (0.6rc11)
/usr/local/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information,see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
You are using pip version 7.1.2,however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
版本太低了,我们升级一下pip
[root@localhost pip-7.1.2]# pip install -U pip
[root@localhost pip-7.1.2]# pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
setuptools (0.6rc11)
上面出现就说明好了,只是告警信息,可以忽略
五.安装依赖rpm下载阿里云的yum源
[root@localhost~]#wget-O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum install epel-release
[root@localhost ~]# yum install epel-release -y
[root@localhost ~]# yum install python-pip MysqL-devel gcc automake autoconf python-devel vim sshpass lrzsz -y
六.下载jumpserver
[root@localhost ~]# cd /opt
[root@localhost opt]# yum install git -y
[root@localhost opt]# git clone https://github.com/ibuler/jumpserver.git
执行快速安装脚本
[root@localhost opt]# cd jumpserver/install && pip install -r requirements.txt
[root@localhost jumpserver]# cd install/
[root@localhost install]# python install.py
Traceback (most recent call last):
File "install.py",in <module>
import readline
ImportError: No module named readline#缺少realine模块
[root@localhost install]# wget https://pypi.python.org/packages/source/r/readline/readline-6.2.4.1.tar.gz#md5=578237939c81fdbc2c8334d168b17907 --no-check-certificate
[root@localhost install]# tar -zxvf readline-6.2.4.1.tar.gz
[root@localhost install]# cd readline-6.2.4.1
root@localhost readline-6.2.4.1]# python setup.py install
报错:
gcc -pthread -shared build/temp.linux-x86_64-2.7/Modules/2.x/readline.o readline/libreadline.a readline/libhistory.a -lncurses -o build/lib.linux-x86_64-2.7/readline.so
/usr/bin/ld: cannot find -lncurses
collect2: ld returned 1 exit status
error: command 'gcc' Failed with exit status 1
解决:
更新系统内核,安装ncurses依赖包
[root@localhost ~]# yum install kernel devel
[root@localhost ~]# yum install ncurses-devel
[root@localhost ~]# [root@localhost ~]# cd readline-6.2.4.1
[root@localhost readline-6.2.4.1]# python setup.py install
[root@localhost readline-6.2.4.1]# cd /opt/jumpserver/install/
[root@localhost install]# python install.py
[root@localhost install]# python install.py
除了自己填自己的邮箱,账号和密码,还有设置jump的账号密码,其他默认
七.最后输入自己的服务器或者虚拟机ip即可
运行 crontab,定期处理失效连接,定期更新资产信息
[root@localhost ~]#cd /opt/jumpserver
[root@localhost ~]#python manage.py crontab add
8.更新代码
[root@localhost ~]#cd /opt/jumpserver
[root@localhost ~]#git pull
centos 7.x 安装开源堡垒机Jumpserver
环境
虚拟机 系统:centos 7
IP:192.168.168.8
目录:/opt
代理:nginx
数据库:mysql 版本大于等于 5.6 mariadb 版本大于等于 5.5.6
更新yum
yum update -y
关闭防火墙与selinux
firewall-cmd --state
systemctl stop firewalld
systemctl disable firewalld
vi /etc/sysconfig/selinux
SELINUX=enforcing 改为 SELINUX=disabled
reboot
修改字符集,否则可能报 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
安装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 # centos7下安装的是mariadb
systemctl enable mariadb
systemctl start mariadb
创建数据库 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
安装 Nginx,用代理服务器整合Jumpserver与各个组件
yum -y install nginx
systemctl enable nginx
下载编译Python3.6.1
cd /opt
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 && make install
配置并载入Python3虚拟环境
cd /opt
python3 -m venv py3
source /opt/py3/bin/activate
# 看到下面的提示符代表成功,以后运行 Jumpserver 都要先运行以上 source 命令,以下所有命令均在该虚拟环境中运行
(py3) [root@localhost opt]#
自动载入Python虚拟环境
cd /opt
git clone git://github.com/kennethreitz/autoenv.git
echo ''source /opt/autoenv/activate.sh'' >> ~/.bashrc
source ~/.bashrc
下载Jumpserver 与 Coco
cd /opt
git clone https://github.com/jumpserver/jumpserver.git
echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env
cd /opt
git clone https://github.com/jumpserver/coco.git
echo "source /opt/py3/bin/activate" > /opt/coco/.env
安装依赖 RPM 包
yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt)
yum -y install $(cat /opt/coco/requirements/rpm_requirements.txt)
安装python库依赖
pip install --upgrade pip
pip install -r /opt/jumpserver/requirements/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
pip install -r /opt/coco/requirements/requirements.txt
修改 Jumpserver 配置文件
cd /opt/jumpserver
cp config_example.py config.py
vi config.py
注意: 配置文件是 Python 格式,不要用 TAB,而要用空格
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
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''
# SECURITY WARNING: keep the bootstrap token used in production secret!
# 预共享Token coco和guacamole用来注册服务账号,不在使用原来的注册接受机制
# BOOTSTRAP_TOKEN = ''PleaseChangeMe''
ALLOWED_HOSTS = [''*'']
# Development env open this, when error occur display the full process track, Production disable it
# DEBUG 模式 开启DEBUG后遇到错误时可以看到更多日志
DEBUG = False
# DEBUG, INFO, WARNING, ERROR, CRITICAL can set. See https://docs.djangoproject.com/en/1.10/topics/logging/
# 日志级别
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 = 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''
#
# OTP_VALID_WINDOW = 0
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()
修改Coco配置文件
cd /opt/coco
cp conf_example.py conf.py # 如果 coco 与 jumpserver 分开部署,请手动修改 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 = "coco"
# Jumpserver项目的url, api请求注册会使用
CORE_HOST = os.environ.get("CORE_HOST") or ''http://127.0.0.1:8080''
# Bootstrap Token, 预共享秘钥, 用来注册coco使用的service account和terminal
# 请和jumpserver 配置文件中保持一致,注册完成后可以删除
# BOOTSTRAP_TOKEN = "PleaseChangeMe"
# 启动时绑定的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 = ''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()
安装 Web Terminal 前端: Luna
cd /opt
wget https://github.com/jumpserver/luna/releases/download/1.4.1/luna.tar.gz
tar xf luna.tar.gz
chown -R root:root luna
安装windows支持组件
yum remove docker-latest-logrotate docker-logrotate docker-selinux dockdocker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache fast
yum -y install docker-ce
systemctl start docker -d
docker pull jumpserver/guacamole:latest
重新打开一个终端
配置Nginx整合组件
source /opt/py3/bin/activate
cd /opt/
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;
}
}
cd /opt/
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
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 default_server;
#listen [::]:80 default_server;
#server_name _;
#root /usr/share/nginx/html;
# 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 {
#}
#}
# 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 {
# }
# }
}
nginx -t
生成数据库表结构和初始化数据
cd /opt/jumpserver/utils
bash make_migrations.sh
运行 Jumpserver
cd ..
./jms start all -d
# 新版本更新了运行脚本,使用方式./jms start|stop|status|restart all 后台运行请添加 -d 参数
运行Coco
cd /opt/coco
./cocod start -d
#在第一个终端里
启动 Guacamole
# 注意:这里需要修改下 http://<填写jumpserver的url地址> 例: http://192.168.168.8, 否则会出错
# 不能使用 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://192.168.168.8:8080 \
jumpserver/guacamole:latest
systemctl start nginx
登录Web管理界面:192.168.168.8
参考链接1:http://docs.jumpserver.org/zh/docs/step_by_step.html
参考链接2:http://docs.jumpserver.org/zh/docs/setup_by_centos7.html
参考链接3:https://www.cnblogs.com/bigdevilking/p/9427941.html
参考链接4:http://docs.jumpserver.org/zh/docs/faq_install.html
CentOS 7下JumpServer安装及配置
环境
- 系统
# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) # uname -r 3.10.0-693.21.1.el7.x86_64
- 关闭Selinux和防火墙
# systemctl stop firewalld.service # sed -i ‘/^SELINUX/s/enforcing/disabled/g‘ /etc/selinux/config # grep -i ^selinux /etc/selinux/config SELINUX=disabled SELINUXTYPE=targeted
- 修改字符集(因为日志里打印了中文,否则肯能报错: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 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虚拟环境
# cd /opt # python3 -m venv py3 # source /opt/py3/bin/activate
看到下面的提示符代表成功,以后运行 Jumpserver 都要先运行以上 source 命令,以下所有命令均在该虚拟环境中运行
(py3) [[email protected] py3]
- 自动载入Phthon虚拟环境
防止运行Jumpserver时忘记载入Python虚拟环境导致无法运行。
# cd /opt # git clone git://github.com/kennethreitz/autoenv.git # echo ‘source /opt/autoenv/activate.sh‘ >> ~/.bashrc # source ~/.bashrc
安装Jumpserver
- 下载或者Clone项目
可以自行选择下载zip包或者直接Clone到本地
# 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 虚拟环境
- 安装依赖RPM包
# cd /opt/jumpserver/requirements # yum -y install $(cat rpm_requirements.txt) # 如果没有任何报错请继续
- 安装Python库依赖
默认的Python库是国外站点,因为网络原因,可能会下载缓慢。这里更改使用国内源。
# pip install -r requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
以上仅为临时使用,如果想配置成默认的源,方法如下:
需要创建或修改配置文件(一般都是创建)
Linux 在 ~/.pip/pip.conf/
修改内容为:
[global] index-url = http://pypi.douban.com/simple [install] trusted-host=pypi.douban.com
- 安装Redis,Jumpserver使用Redis做cache和celery broke
# yum -y install redis # systemctl enable redis # systemctl start redis
- 安装MysqL
# yum -y install mariadb mariadb-devel mariadb-server # systemctl enable mariadb # systemctl start mariadb
- 初始化MysqL,创建数据库Jumpserver并授权
# MysqL_secure_installation #设置root登录密码,然后一路回车 # MysqL -uroot -p123456 > create database jumpserver default charset ‘utf8‘; > grant all on jumpserver.* to ‘jumpserver‘@‘127.0.0.1‘ identified by ‘123456‘; > flush privileges;
- 修改Jumpserver配置文件
# cd /opt/jumpserver # cp config_example.py config.py # 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 = ‘2vym+ky!997d5kkcc64mnz06y1mmui3lut#(^wd=%s_qj$1%x‘ ‘请随意输入随机字符串(推荐字符大于等于 50位)‘ # Django security setting,if your disable debug model,you should setting that ALLOWED_HOSTS = [‘*‘] # DEBUG 模式 True为开启 False为关闭,默认开启,生产环境推荐关闭 # 注意:如果设置了DEBUG = False,访问8080端口页面会显示不正常,需要搭建 Nginx 代理才可以正常访问 DEBUG = False # 日志级别,默认为DEBUG,可调整为INFO,WARNING,ERROR,CRITICAL,默认INFO LOG_LEVEL = ‘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 = ‘MysqL‘ DB_HOST = ‘127.0.0.1‘ DB_PORT = 3306 DB_USER = ‘jumpserver‘ DB_PASSWORD = ‘123456‘ DB_NAME = ‘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 = ‘127.0.0.1‘ REdis_PORT = 6379 REdis_PASSWORD = ‘‘ REdis_DB_CELERY = 3 REdis_DB_CACHE = 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()
- 生成数据库表结构和初始化数据
# cd /opt/jumpserver/utils # bash make_migrations.sh
- 运行Jumpserver
# cd /opt/jumpserver # ./jms start all # 后台运行使用 -d 参数./jms start all -d
运行不报错,浏览器访问http://IP地址:8080 默认账号:admin 密码:admin
安装SSH Server和WebSocket Server:Coco
- 下载或CLone项目
新开一个终端,别忘了
souce /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 虚拟环境
- 安装依赖
# cd /opt/coco/requirements # yum -y install $(cat rpm_requirements.txt) # pip install -r requirements.txt
- 修改配置文件并运行
# cd /opt/coco # cp conf_example.py conf.py # 如果 coco 与 jumpserver 分开部署,请手动修改 conf.py # vim 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 -d
启动成功后去Jumpserver 会话管理-终端管理(http://IP地址:8080/terminal/terminal/) 接受coco的注册。
安装Web Terminal 前端:Luna
Luna已改为纯前端,需要Nginx来运行访问
- 下载并解压Luna
# cd /opt # wget https://github.com/jumpserver/luna/releases/download/1.3.3/luna.tar.gz # tar xvf luna.tar.gz # chown -R root:root luna
安装Windows支持组件(若不需要可以跳过)
因为手动安装 guacamole 组件比较复杂,这里提供打包好的 docker 使用,启动 guacamole
- Docker安装
# yum remove docker-latest-logrotate docker-logrotate docker-selinux dockdocker-engine # yum install -y yum-utils device-mapper-persistent-data lvm2 # 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
- 启动 Guacamole
这里所需要注意的是 guacamole 暴露出来的端口是 8081,若与主机上其他端口冲突请自定义
启动成功后去Jumpserver 会话管理-终端管理(http://IP地址:8080/terminal/terminal/) 接受[Gua]开头的一个注册
# 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://IP地址 jumpserver/guacamole:latest
配置Nginx整合各组件
- 安装Nginx
# yum -y install Nginx
- 修改配置文件
# vim /etc/Nginx/Nginx.conf
... 省略
# 把默认server配置块改成这样,原有的内容请保持不动 server { listen 80; # 代理端口,以后将通过此端口进行访问,不再通过8080端口 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; client_max_body_size 100m; # Windows 文件上传大小限制 } 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; } } ... 省略
- 运行Nginx
# Nginx -t # 确保配置没有问题,有问题请先解决
# systemctl start Nginx # systemctl enable Nginx
- 开始使用Jumpserver
检查应用是否正常运行
# cd /opt/jumpserver # ./jms status # 确定jumpserver已经运行,如果没有运行请重新启动jumpserver # cd /opt/coco # ./cocod status # 确定jumpserver已经运行,如果没有运行请重新启动coco # 如果安装了 Guacamole # docker ps # 检查容器是否已经正常运行,如果没有运行请重新启动Guacamole
服务全部启动后,访问http://ip,访问Nginx代理的端口,不要再通过8080端口访问。
如果部署过程中,没有接受应用的注册,需要到Jumpserver的会话管理-终端管理 接受Coco Guacamode等应用的注册。
测试连接
如果登录客户端是 macOS 或 Linux ,登录语法如下
$ ssh -p2222 [email protected] $ sftp -P2222 [email protected] 密码: admin 如果登录客户端是 Windows ,Xshell Terminal 登录语法如下 $ ssh [email protected] 2222 $ sftp [email protected] 2222 密码: admin 如果能登陆代表部署成功 # sftp默认上传的位置在资产的 /tmp 目录下 # windows拖拽上传的位置在资产的 Guacamole RDP上的 G 目录下
Centos 7安装配置jumpserver堡垒机
docker封装操作
前言:
由于如果有人需要使用服务器的话,不巧没有批量管理工具,此时就需要手动为他们在服务器添加账号。当然服务器的数量比较少还好,但是一旦多起来(服务器+需求者),这个任务量可想而知。由此堡垒机(jumpserver)应运而生。具体此堡垒机的功能和组成等等资料,各位可以自行在网上查阅即可;这里多说无益。
总结:
运维需要依靠这个强大的软件,但是起初真的一点都不懂,这里聊聊遇到不懂的技术等等,该怎么样做比较合适!
- 首先不必要去了解是做什么的,书面的东西(有的时候还有专有名词)也不好理解,所以最终也是看的云里雾里的;So应该先去做如何来实现这个技术;
- 其次便是收集各方面的资料(官网+搜索)这两者相互结合,不信这个东西还整不出来;嗯哼!
- 最后大胆去尝试吧,一不小心就吼不住的,注意时间分配,最重要的是注意身体。
掌握内容:
xshell终端控制+xftp传送文件+官网当文档,解压到linux中+linux操作指令等等。
内心浮动:
不想多说什么,官网和搜索的教程,有些都不合适,各种报错,心里一万个XXX飘过~
操作次数:
虚拟机网段从129-136(虚拟机安装5次)+快照还原(5-6)次+阿里云(2次)
以下便结合官方文档讲解自己的操作过程,保准合适,不合适你来“聊”我。
操作过程:(centos 7及以上版本)
一、基本环境安装
[root@docker ~]#cd /opt ----切换目录避免与/root、/home等目录冲突
[root@dockeropt]#yum install -y epel-release ----安装依赖程序
[root@dockeropt]#yum install -y curl iptables-services ----安装防火墙服务,centos7之前使用的是iptables防火墙,现在是firewalld
[root@dockeropt]#systemctl stop iptables ----临时关闭防火墙
[root@dockeropt]#systemctl stop firewalld.service ----临时关闭防火墙
二、安装docker(容器;封装某些设置,取出后方便在其它机器中配置)---docker-ce(免费)/docker-ee(收费版)
Docker-CE安装---以下可选步骤可以不安装。(共四步)
[root@docker opt]#systemctl start docker ---临时开启docker服务
[root@docker opt]#systemctl enable docker ----开机后开启docker服务
三、安装数据库mariadb服务(centos7之前为MysqL服务,这也是网络其它教程与此教程的区别)
[root@docker opt]#yum -y install mariadb-server mariadb-devel
[root@docker opt]#systemctl start mariadb.service
[root@docker opt]#systemctl enable mariadb.service
注意:这里面有一个坑,第三个指令可以先不输入,然后等到后面python next.py的时候会报错,显示docker的ip连接不上数据库的错误。
[root@docker ~]#ifconfig ----查看网卡的ip等等信息
[root@docker opt]#MysqL -e "create database jumpserver charset='utf8';" ----创建名为jumpserver的数据库,字符集为utf8
[root@docker opt]#MysqL -e "grant all on jumpserver.* to 'jumpserver'@'192.168.44.134'identified by '5lov@wife';" ---授予权限
[root@docker opt]#MysqL -e "grant all on jumpserver.* to 'jumpserver'@'172.17.0.2'identified by '5lov@wife';" ----授予权限
[root@docker opt]#MysqL -e "flush privileges;" ----立即执行权限,以免重启
[root@docker opt]#MysqL -e "show databases;" ----显示创建好的数据库
[root@docker opt]#docker pull jiaxiangkong/jumpserver_docker:0.3.2 ----拉镜像
[root@docker opt]#docker run -d -p 2222:22 -p 8888:80 --restart=always --name jmsjiaxiangkong/jumpserver_docker:0.3.2 ---映射端口地址,避免访问失败。
[root@docker opt]#docker ps
[root@docker opt]#docker exec -it 328cfd0f67b0 /bin/sh ---登录容器
/jumpserver #ifconfig ----查看配置文件
/jumpserver # vi jumpserver.conf ---修改jumpserver的配置文件,此步骤至关重要。(涉及到文件的编写和保存及退出)
六、初始化数据库,安装jumpserver
/jumpserver # cdinstall && python next.py
七、大功告成,登录web端即可
访问192.168.44.134:8888(一定不要按照显示的登录http://ip:8000端口)登录----账号:admin;密码:admin
也许读者会不理解“为什么”你的IP地址不是192.168.44.134而是图中的这个,是不是盗的图,错!!!
这个道理很简单:我在两台服务器上配置的jumpserver(一台虚拟机+一台阿里云服务器)
本图中的为阿里云公网地址显示的(阿里云服务器竟然有两个IP)公网和私网,下期吐槽博客咱们一起来聊聊关于安装jumpserver的各种奇葩的事情。当然还会有一篇关于操作web端jumpserver的操作教程,包您满意。
关于centos7 使用 docker 安装 jumpserver和centos7 安装docker-compose的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于centos 安装 jumpserver、centos 7.x 安装开源堡垒机Jumpserver、CentOS 7下JumpServer安装及配置、Centos 7安装配置jumpserver堡垒机的相关知识,请在本站寻找。
本文标签: