之前用的JumpServer 一直是搭建在Centos 7上面的奈何对Centos 不熟悉,所以今天想把系统换成Ubuntu 18.04.

 

先来看一下我们今天的JumpServer 堡垒机的安装环境要求:

硬件配置: 2个CPU核心, 4G 内存, 50G 硬盘(最低)
操作系统: Ubuntu  Linux 发行版 x86_64

 

安装Ubuntu 的最后一定记得要选择安装 Open ssh server安装完成后,我们用SSH 客户端链接上服务器 ,可以用xshell 或者 MobaXterm。

%title插图%num

首先安装JumpServer 前我们先将Ubuntu 内置的更新源 更换成国内的,这一步是为了安装依赖包和一些必要的软件时 更快,国外的源速度不稳定时快时慢。

1. 备份原始源文件sources.list

# sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# sudo chmod 777 /etc/apt/sources.list

2. 修改源文件sources.list

# sudo vi /etc/apt/sources.list

3. 删除原来的文件内容,复制下面的任意一个到其中并保存(常用的是阿里源和清华源,推荐阿里源)

阿里源:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

清华源:

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

中国科技大学:

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
%title插图%num

4.保存退出,然后刷新软件列表

# sudo apt-get update
# sudo apt-get upgrade

环境

系统: Ubuntu 18.04
IP: 192.168.244.144
目录: /opt
数据库: mariadb
代理: nginx

一. 开始安装

一. 准备 Python3 和 Python 虚拟环境
1.1 安装依赖包

# apt-get update && apt-get -y upgrade apt-get -y install wget gcc libffi-dev git

1.2 安装 Redis, JumpServer 使用 Redis 做 cache 和 celery broke apt-get -y install redis-server

# apt-get -y install redis-server

1.3 安装 MySQL

本教程使用 Mysql 作为数据库, 如果不使用 Mysql 可以跳过相关 Mysql 安装和配置

# apt-get -y install mysql-server libmysqlclient-dev

1.4 创建数据库 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 -p -e "create database jumpserver default charset 'utf8'; grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by '$DB_PASSWORD'; flush privileges;"

生成了Mysql数据库的密码要保存好,下面需要用到

1.5 安装 Python3.6

# apt-get -y install python3.6-dev python3-venv

1.6 建立 Python 虚拟环境

为了不扰乱原来的环境我们来使用 Python 虚拟环境

# cd /opt
# python3.6 -m venv py3
# source /opt/py3/bin/activate
看到下面的提示符代表成功, 以后运行 JumpServer 都要先运行以上 source 命令, 以下所有命令均在该虚拟环境中运行
看到下面的提示符代表成功, 以后运行 JumpServer 都要先运行以上 source 命令, 以下所有命令均在该虚拟环境中运行 
看到下面的提示符代表成功, 以后运行 JumpServer 都要先运行以上 source 命令, 以下所有命令均在该虚拟环境中运行 
(py3) [root@localhost py3]

备注:接下来安装Jumpserver的所有的命令都必须在有”(py3) [root@localhost py3]”这个提示符的前提下来进行操作,如果你重启服务器或者断开服务器的链接了,请重复 1.6 的步骤以后在继续进行安装

二. 安装 JumpServer

2.1 下载或 Clone 项目

#  cd /opt/
# git clone --depth=1 https://github.com/jumpserver/jumpserver.git

备注:这一步有可能提示 无法下载,如果遇到这种情况,建议自己自行下载or 下载我提供的附件 后上传到服务器的 /opt 的目录下然后解压,在继续进行安装。

jumpserver.tar

2.2 安装依赖包

# cd /opt/jumpserver/requirements
# apt-get -y install $(cat deb_requirements.txt)

2.3 安装 Python 库依赖

#  pip install wheel
# pip install --upgrade pip setuptools
# pip install -r requirements.txt

2.4 修改 JumpServer 配置文件

# cd /opt/jumpserver
# 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" /opt/jumpserver/config.yml # sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /opt/jumpserver/config.yml # sed -i "s/# DEBUG: true/DEBUG: false/g" /opt/jumpserver/config.yml # sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" /opt/jumpserver/config.yml # sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: false/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" /opt/jumpserver/config.yml # sed -i "s/DB_PASSWORD: /DB_PASSWORD: $DB_PASSWORD/g" /opt/jumpserver/config.yml # echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m" # echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m"

这一步,命令一条一条执行不要全部复制进去一次性执行容易报错

# vim config.yml  # 确认内容有没有错误,填写数据库密码
SECURITY WARNING: keep the secret key used in production secret!
 加密秘钥 生产环境中请修改为随机字符串, 请勿外泄, PS: 纯数字不可以
 SECRET_KEY:
 SECURITY WARNING: keep the bootstrap token used in production secret!
 预共享Token koko和guacamole用来注册服务账号, 不在使用原来的注册接受机制
 BOOTSTRAP_TOKEN:
 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:
 Session expiration setting, Default 24 hour, Also set expired on on browser close
 浏览器Session过期时间, 默认24小时, 也可以设置浏览器关闭则过期
 SESSION_COOKIE_AGE: 86400
 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:
 MySQL or postgres setting like:
 使用Mysql作为数据库
 DB_ENGINE: mysql
 DB_HOST: 127.0.0.1
 DB_PORT: 3306
 DB_USER: jumpserver
 DB_PASSWORD:(填写上一步你的 MySQL的数据库密码)
 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 settings
 OTP/MFA 配置
 OTP_VALID_WINDOW: 0
 OTP_ISSUER_NAME: Jumpserver

2.5 运行 JumpServer

# cd /opt/jumpserver
# ./jms start -d  # 后台运行使用 -d 参数./jms start -d
新版本更新了运行脚本, 使用方式./jms start|stop|status all  后台运行请添加 -d 参数
# wget -O /lib/systemd/system/jms.service https://demo.jumpserver.org/download/shell/ubuntu/jms.service
# chmod 755 /lib/systemd/system/jms.service
# systemctl enable jms  # 配置自启

运行不报错, 请继续往下操作

三. 安装 SSH Server 和 WebSocket Server: koko

3.1 安装 Docker

# apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu #(lsb_release -cs) stable"
# apt-get -y update
# apt-get -y install docker-ce wget
# mkdir /etc/docker
# wget -O /etc/docker/daemon.json http://demo.jumpserver.org/download/docker/daemon.json
# systemctl restart docker.service
# Server_IP=ip addr | grep 'state UP' -A2 | grep inet | egrep -v '(127.0.0.1|inet6|docker)' | awk '{print #2}' | tr -d "addr:" | head -n 1 | cut -d / -f1 # echo -e "\033[31m 你的服务器IP是 #Server_IP \033[0m"

mkdir /etc/docker 这一步创建文件夹可能会报错无法创建,建议直接去/etc/目录下创建

3.2 部署 koko

# docker run --name jms_koko -d -p 2222:2222 -p 127.0.0.1:5000:5000 -e CORE_HOST=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN --restart=always wojiushixiaobai/jms_koko:1.5.6
 BOOTSTRAP_TOKEN 为 Jumpserver/config.yml 里面的 BOOTSTRAP_TOKEN

四. 安装 RDP Server 和 VNC Server: Guacamole

4.1 部署 Guacamole

# docker run --name jms_guacamole -d -p 127.0.0.1:8081:8080 -e JUMPSERVER_SERVER=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN --restart=always wojiushixiaobai/jms_guacamole:1.5.6 # BOOTSTRAP_TOKEN 为 Jumpserver/config.yml 里面的 BOOTSTRAP_TOKEN 

五. 安装 Web Terminal 前端: Luna

访问(https://github.com/jumpserver/luna/releases)下载对应版本的 release 包, 直接解压, 不需要编译

5.1 部署 Luna

# cd /opt/
# wget https://github.com/jumpserver/luna/releases/download/1.5.6/luna.tar.gz
 如果网络有问题导致下载无法完成可以使用下面地址
# wget https://demo.jumpserver.org/download/luna/1.5.6/luna.tar.gz
# tar xf luna.tar.gz
# chown -R root:root luna

六. 配置 Nginx 整合各组件

6.1 安装 Nginx

请先运行 source /opt/py3/bin/activate 命令,在进行一下的安装

# apt-get -y install curl gnupg2 ca-certificates lsb-release
# add-apt-repository "deb http://nginx.org/packages/ubuntu/ $(lsb_release -cs) nginx"
# curl -fsSL http://nginx.org/keys/nginx_signing.key | sudo apt-key add -
# apt-get update
# apt-get -y install nginx

6.2 准备配置文件 /etc/nginx/conf.d/jumpserver.conf

# rm -rf /etc/nginx/conf.d/default.conf

# vim /etc/nginx/conf.d/jumpserver.conf
server {
     listen 80;
     server_name _;

client_max_body_size 100m;  # 录像及文件上传大小限制

location /luna/ {
    try_files $uri / /index.html;
    alias /opt/luna/;
}

location /media/ {
    add_header Content-Encoding gzip;
    root /opt/jumpserver/data/;
}

location /static/ {
    root /opt/jumpserver/data/;
}

location /koko/ {
    proxy_pass       http://localhost:5000;
    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/;
    proxy_buffering off;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    access_log off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /ws/ {
    proxy_pass http://localhost:8070;
    proxy_http_version 1.1;
    proxy_buffering off;
    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 / {
    proxy_pass http://localhost:8080;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}

备注:将配置文件的内容全部复制粘贴进去,不用改动

6.3 重启 Nginx

# nginx -t  # 如果没有报错请继续
# systemctl restart nginx

这一步重启完Nginx, 就可以直接访问服务器IP了(如果你服务器安装中没有重启或者关机过),如果访问IP 直接显示 Nginx的欢迎界面 ,建议直接卸载Nginx,然后重新安装一遍就好了 。

 

6.4 开始使用 JumpServer

服务全部启动后, 访问 http://server ip
默认账号: admin 密码: admin
到JumpServer 会话管理-终端管理 检查 koko Guacamole 等应用的注册



微信扫描下方的二维码阅读本文

%title插图%num

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注