一步一步搭建jumpserver堡垒机,centos7系统

一步一步搭建jumpserver堡垒机,centos7系统

本文档旨在帮助用户了解各组件之间的关系。

测试推荐环境

CPU: 64位双核处理器
内存: 4G DDR3
数据库:mysql 版本大于等于 5.6 mariadb 版本大于等于 5.5.6

环境

系统: CentOS 7
IP: 192.168.92.75
设置 selinux 和防火墙

$ firewall-cmd --zone=public --add-port=80/tcp --permanent  # nginx 端口
$ firewall-cmd --zone=public --add-port=16384/tcp --permanent  # 用户SSH登录端口 coco

$ firewall-cmd --reload  # 重新载入规则

$ setenforce 0
$ sed -i "s/SELINUX=enforcing/SELINUX=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

# 如果下载速度很慢, 可以换国内源
$ wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
$ yum -y install python36 python36-devel

1.3 建立 Python 虚拟环境

因为 CentOS 7 自带的是 Python2, 而 Yum 等工具依赖原来的 Python, 为了不扰乱原来的环境我们来使用 Python 虚拟环境

$ pwd   # 我搭建时候的家目录
/data
$ cd /data/bin
$ python3.6 -m venv py3
$ source /data/bin/py3/bin/activate

# 看到下面的提示符代表成功, 以后运行 Jumpserver 都要先运行以上 source 命令, 以下所有命令均在该虚拟环境中运行
(py3) [www@localhost bin]

二. 安装 Jumpserver

2.1 下载或 Clone 项目

项目提交较多 git clone 时较大, 你可以选择去 Github 项目页面直接下载zip包。

$ mkdir package      # 软件下载目录
$ cd package/
$ git clone https://github.com/jumpserver/jumpserver.git

2.2 安装依赖 RPM 包

$ cd jumpserver/requirements/
$ yum -y install $(cat rpm_requirements.txt)  # 如果没有任何报错请继续

2.3 安装 Python 库依赖

$ pip install --upgrade pip setuptools
$ pip install -r requirements.txt

# 如果下载速度很慢, 可以换国内源
$ pip install --upgrade pip setuptools -i https://mirrors.aliyun.com/pypi/simple/
$ pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

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 并授权

$ DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24`  # 生成随机数据库密码
$ echo -e "\033[31m 你的数据库密码是 $DB_PASSWORD \033[0m"
$ mysql -uroot -e "create database jumpserver default charset 'utf8'; grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by '$DB_PASSWORD'; flush privileges;"

2.7 修改 Jumpserver 配置文件

$ cd ../
$ cp config_example.yml config.yml

$ SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50`  # 生成随机SECRET_KEY
$ echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc
$ BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16`  # 生成随机BOOTSTRAP_TOKEN
$ echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc

$ sed -i "s/SECRET_KEY:/SECRET_KEY: $SECRET_KEY/g" config.yml
$ sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" config.yml
$ sed -i "s/# DEBUG: true/DEBUG: false/g" config.yml
$ sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" config.yml
$ sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: false/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" config.yml
$ sed -i "s/DB_PASSWORD: /DB_PASSWORD: $DB_PASSWORD/g" config.yml

$ echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m"
$ echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m"

2.8 运行 Jumpserver

$ cd /opt/jumpserver
$ ./jms start all -d  # 后台运行使用 -d 参数./jms start all -d

# 新版本更新了运行脚本, 使用方式./jms start|stop|status all  后台运行请添加 -d 参数

三. 安装 SSH Server 和 WebSocket Server: Coco

3.1 下载或 Clone 项目

$ cd ../
$ git clone https://github.com/jumpserver/coco.git

3.2 安装依赖

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

# 如果下载速度很慢, 可以换国内源
$ pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

3.3 修改配置文件并运行

$ cd ../
$ cp config_example.yml config.yml

$ sed -i "s/BOOTSTRAP_TOKEN: <PleasgeChangeSameWithJumpserver>/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" config.yml
$ sed -i "s/# LOG_LEVEL: INFO/LOG_LEVEL: ERROR/g" config.yml
$ sed -i "s/# SSHD_PORT: 2222#SSHD_PORT: 16384" config.yml

$ ./cocod start -d  # 后台运行使用 -d 参数./cocod start -d

# 新版本更新了运行脚本, 使用方式./cocod start|stop|status  后台运行请添加 -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.9/luna.tar.gz

# 如果网络有问题导致下载无法完成可以使用下面地址
$ wget https://demo.jumpserver.org/download/luna/1.4.9/luna.tar.gz

$ tar xf luna.tar.gz

五. 配置 Nginx 整合各组件

5.1 准备配置文件

# 根据自己的nginx配置。
... ...

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;
    }
}
... ... 

开始使用 Jumpserver

检查应用是否已经正常运行

服务全部启动后, 访问 http://192.168.92.75, 访问nginx代理的端口, 不要再通过8080端口访问

默认账号: admin 密码: admin

到Jumpserver 会话管理-终端管理 检查 Coco Guacamole 等应用的注册。

测试连接

如果登录客户端是 macOS 或 Linux, 登录语法如下
$ ssh -p2222 admin@192.168.244.144
$ sftp -P2222 admin@192.168.244.144
密码: admin

如果登录客户端是 Windows, Xshell Terminal 登录语法如下
$ ssh admin@192.168.244.144 2222
$ sftp admin@192.168.244.144 2222
密码: admin
如果能登陆代表部署成功

# sftp默认上传的位置在资产的 /tmp 目录下
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值