Linux系统安装企业级JumpServer
配置基础环境
硬件配置: 2个CPU核心, 4G 内存, 50G 硬盘(最低)
操作系统: Linux 发行版 x86_64
Python = 3.6.x
Mysql Server ≥ 5.6
Mariadb Server ≥ 5.5.56
Redis
[root@jumpserver ]# firewall-cmd --zone=public --add-port=80/tcp --permanent # nginx 端口
[root@jumpserver ]# firewall-cmd --zone=public --add-port=2222/tcp --permanent # 用户SSH登录端口 coco
[root@jumpserver ]# firewall-cmd --reload # 重新载入规则
[root@jumpserver ]# setenforce 0
[root@jumpserver ]# sed -i "s/enforcing/disabled/g" /etc/selinux/config
修改字符集,否则可能报 input/output error的问题,因为日志里打印了中文
[root@jumpserver ]# localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8
[root@jumpserver ]# export LC_ALL=zh_CN.UTF-8
[root@jumpserver ]# echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf
1.准备python3和python虚拟环境
1.1安装依赖包
[root@jumpserver ~]# yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git
1.2安装Python3.6
[root@jumpserver ~]# yum -y install python36 python36-devel
1.3 建立 Python 虚拟环境
因为 CentOS 7 自带的是 Python2,而 Yum 等工具依赖原来的 Python,为了不扰乱原来的环境我们来使用 Python 虚拟环境
[root@jumpserver ~]# cd /opt/
[root@jumpserver opt]# python3.6 -m venv py3
[root@jumpserver opt]# source /opt/py3/bin/activate
(py3) [root@jumpserver opt]#
看到下面的提示符代表成功,以后运行 Jumpserver 都要先运行以上 source 命令,以下所有命令均在该虚拟环境中运行
(py3) [root@jumpserver py3]#
退出
(py3) [root@jumpserver py3]# deactivate
[root@jumpserver py3]#
1.4 自动载入 Python 虚拟环境配置
此项仅为小白使用,防止运行 Jumpserver 时忘记载入 Python 虚拟环境导致程序无法运行。使用autoenv
[root@jumpserver py3]# cd /opt/
[root@jumpserver opt]# git clone https://github.com/kennethreitz/autoenv.git
Cloning into 'autoenv'...
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 688 (delta 5), reused 9 (delta 3), pack-reused 672
Receiving objects: 100% (688/688), 111.91 KiB | 0 bytes/s, done.
Resolving deltas: 100% (362/362), done.
[root@jumpserver opt]# echo 'source /opt/autoenv/activate.sh' >> ~/.bashrc
[root@jumpserver opt]# source ~/.bashrc
2.安装Jumpserver
2.1 下载或克隆项目
项目提交较多 git clone 时较大,你可以选择去 Github 项目页面直接下载zip包
[root@jumpserver ]# cd /opt/
[root@jumpserver opt]# git clone https://github.com/jumpserver/jumpserver.git
[root@jumpserver opt]# echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env # 进入 jumpserver 目录时将自动载入 python 虚拟环境
首次进入 jumpserver 文件夹会有提示,按 y 即可
[root@jumpserver opt]# cd jumpserver/
autoenv:
autoenv: WARNING:
autoenv: This is the first time you are about to source /opt/jumpserver/.env:
autoenv:
autoenv: --- (begin contents) ---------------------------------------
autoenv: source /opt/py3/bin/activate$
autoenv:
autoenv: --- (end contents) -----------------------------------------
autoenv:
autoenv: Are you sure you want to allow this? (y/N) y
(py3) [root@jumpserver jumpserver]#
2.2 安装依赖rpm
[root@jumpserver opt]# cd /opt/jumpserver/requirements
(py3) [root@jumpserver requirements]# yum -y install $(cat rpm_requirements.txt) # 如果没有任何报错请继续
2.3 安装Python库依赖
(py3) [root@jumpserver requirements]# pip install --upgrade pip setuptools -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
(py3) [root@jumpserver requirements]# pip install -r requirements.txt
2.4 安装 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke
[root@jumpserver ]# yum -y install redis
[root@jumpserver ]# systemctl enable redis
[root@jumpserver ]# systemctl start redis
2.5 安装MySQL
本教程使用 Mysql 作为数据库,如果不使用 Mysql 可以跳过相关 Mysql 安装和配置
[root@jumpserver ]# yum -y install mariadb mariadb-devel mariadb-server # centos7下安装的是mariadb
[root@jumpserver ]# systemctl enable mariadb
[root@jumpserver ]# systemctl start mariadb
2.6 创建数据库jumpserver并授权
(py3) [root@jumpserver requirements]# mysql
MariaDB [(none)]> create database jumpserver charset utf8;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on jumpserver.* to 'jumpserver'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
数据库密码是123456
2.7 修改Jumpserver配置文件
$ cd /opt/jumpserver
(py3) [root@jumpserver jumpserver]# cp config_example.yml config.yml
生成随机SECRET_KEY
(py3) [root@jumpserver jumpserver]# SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50`
生成随机BOOTSTRAP_TOKEN
(py3) [root@jumpserver jumpserver]# BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16`
(py3) [root@jumpserver jumpserver]# sed -i "s/SECRET_KEY:/SECRET_KEY: $SECRET_KEY/g" /opt/jumpserver/config.yml
(py3) [root@jumpserver jumpserver]# sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /opt/jumpserver/config.yml
(py3) [root@jumpserver jumpserver]# sed -i "s/# DEBUG: true/DEBUG: false/g" /opt/jumpserver/config.yml
(py3) [root@jumpserver jumpserver]# sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" /opt/jumpserver/config.yml
(py3) [root@jumpserver jumpserver]# sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: false/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" /opt/jumpserver/config.yml
(py3) [root@jumpserver jumpserver]# sed -i "s/DB_PASSWORD: /DB_PASSWORD: $DB_PASSWORD/g" /opt/jumpserver/config.yml
(py3) [root@jumpserver jumpserver]# echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m"
你的SECRET_KEY是 0n1zgmvxdCAS3UxEsOBroyZAXQzcoZ6okne7oZHjJD9uwYAINW
(py3) [root@jumpserver jumpserver]# echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m"
你的BOOTSTRAP_TOKEN是 t7XoOSrskucrcHdU
vim config.yml 确认内容有没有错误
# SECURITY WARNING: keep the secret key used in production secret!
# 加密秘钥 生产环境中请修改为随机字符串,请勿外泄
SECRET_KEY:
# SECURITY WARNING: keep the bootstrap token used in production secret!
# 预共享Token coco和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: '123456'
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.8 运行Jumpserver
$ cd /opt/jumpserver
$ ./jms start all -d # 后台运行使用 -d 参数./jms start all -d
新版本更新了运行脚本,使用方式./jms start|stop|status|restart all 后台运行请添加 -d 参数
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yVmpfXSD-1590994996224)(C:\Users\百趣网\AppData\Roaming\Typora\typora-user-images\image-20200527144237728.png)]
运行不报错的话, 请继续往下操作
3安装 SSH Server 和 WebSocket Server: Coco
3.1 正常部署 coco 组件
(py3) [root@jumpserver jumpserver]# cd /opt/
(py3) [root@jumpserver opt]# source /opt/py3/bin/activate
(py3) [root@jumpserver opt]# git clone https://github.com/jumpserver/coco.git
Cloning into 'coco'...
remote: Enumerating objects: 3766, done.
remote: Total 3766 (delta 0), reused 0 (delta 0), pack-reused 3766
Receiving objects: 100% (3766/3766), 1.77 MiB | 71.00 KiB/s, done.
Resolving deltas: 100% (2435/2435), done.
$ echo "source /opt/py3/bin/activate" > /opt/coco/.env # 进入 coco 目录时将自动载入 python 虚拟环境
首次进入 coco 文件夹会有提示,按 y 即可
(py3) [root@jumpserver opt]# cd coco/
autoenv:
autoenv: WARNING:
autoenv: This is the first time you are about to source /opt/coco/.env:
autoenv:
autoenv: --- (begin contents) ---------------------------------------
autoenv: source /opt/py3/bin/activate$
autoenv:
autoenv: --- (end contents) -----------------------------------------
autoenv:
autoenv: Are you sure you want to allow this? (y/N) y
# 安装依赖
$ cd /opt/coco/requirements
$ yum -y install $(cat rpm_requirements.txt)
#注意修改一下 requirements.txt,不然会报错
vim requirements.txt
#(找到 MarkupSafe 开头那一行,替换版本号):
MarkupSafe==1.1.1
然后执行下边
$ pip install -r requirements.txt
#修改配置文件并运行
(py3) [root@jumpserver requirements]# cd /opt/coco/
(py3) [root@jumpserver coco]# mkdir keys logs
(py3) [root@jumpserver coco]# cp config_example.yml config.yml
(py3) [root@jumpserver coco]# sed -i "s/BOOTSTRAP_TOKEN: <ChangeIT>/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /opt/coco/config.yml
(py3) [root@jumpserver coco]# sed -i "s/# LOG_LEVEL: INFO/LOG_LEVEL: ERROR/g" /opt/coco/config.yml
(py3) [root@jumpserver coco]#
vim config.yml
# 项目名称, 会用来向Jumpserver注册, 识别而已, 不能重复
# NAME: {{ Hostname }}
# Jumpserver项目的url, api请求注册会使用
CORE_HOST: http://127.0.0.1:8080
# Bootstrap Token, 预共享秘钥, 用来注册coco使用的service account和terminal
# 请和jumpserver 配置文件中保持一致,注册完成后可以删除
BOOTSTRAP_TOKEN: <ChangeIT>
# 启动时绑定的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: null
# ACCESS KEY 保存的地址, 默认注册后会保存到该文件中
# ACCESS_KEY_STORE: keys/.access_key
# 加密密钥
# SECRET_KEY: null
# 设置日志级别 [DEBUG, INFO, WARN, ERROR, FATAL, CRITICAL]
LOG_LEVEL: ERROR
# 日志存放的目录
# LOG_DIR: logs
# SSH白名单
# ALLOW_SSH_USER: all
# SSH黑名单, 如果用户同时在白名单和黑名单,黑名单优先生效
# BLOCK_SSH_USER:
# -
# 和Jumpserver 保持心跳时间间隔
# HEARTBEAT_INTERVAL: 5
# Admin的名字,出问题会提示给用户
# ADMINS: ''
# SSH连接超时时间 (default 15 seconds)
# SSH_TIMEOUT: 15
# 语言 [en,zh]
# LANGUAGE_CODE: zh
# SFTP的根目录, 可选 /tmp, Home其他自定义目录
# SFTP_ROOT: /tmp
# SFTP是否显示隐藏文件
# SFTP_SHOW_HIDDEN_FILE: false
3.2 安装 Web Terminal 前端: Luna
#Luna 已改为纯前端,需要 Nginx 来运行访问
#访问(https://github.com/jumpserver/luna/releases)下载对应版本的 release 包,直接解压,不需要编译
(py3) [root@jumpserver coco]# cd /opt/
(py3) [root@jumpserver opt]# wget https://github.com/jumpserver/luna/releases/download/1.5.6/luna.tar.gz
$ tar xf luna.tar.gz
$ chown -R root:root luna
4. 安装 Windows 支持组件(如果不需要管理 windows 资产,可以直接跳过这一步)
Guacamole 需要 Tomcat 来运行
4.1 安装依赖
$ mkdir /usr/local/lib/freerdp/
$ ln -s /usr/local/lib/freerdp /usr/lib64/freerdp
$ rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
(py3) [root@jumpserver opt]# rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
Retrieving http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:nux-dextop-release-0-5.el7.nux ################################# [100%]
(py3) [root@jumpserver opt]# yum -y localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm
(py3) [root@jumpserver opt]# yum install -y java-1.8.0-openjdk libtool
(py3) [root@jumpserver opt]# yum install -y cairo-devel libjpeg-turbo-devel libpng-devel uuid-devel
(py3) [root@jumpserver opt]# yum install -y ffmpeg-devel freerdp-devel freerdp-plugins pango-devel libssh2-devel libtelnet-devel libvncserver-devel pulseaudio-libs-devel openssl-devel libvorbis-devel libwebp-devel ghostscript
4.2 编译安装 guacamole 服务
$ cd /opt
$ git clone https://github.com/jumpserver/docker-guacamole.git
$ cd /opt/docker-guacamole/
(py3) [root@jumpserver docker-guacamole]# tar xf guacamole-server-1.0.0.tar.gz
(py3) [root@jumpserver docker-guacamole]# cd guacamole-server-1.0.0/
$ autoreconf -fi
$ ./configure --with-init-dir=/etc/init.d
$ make && make install
$ cd ..
$ rm -rf guacamole-server-1.0.0
$ ldconfig
4.3 编译安装 guacamole 服务
1. 创建 guacamole 目录
$ mkdir -p /config/guacamole /config/guacamole/lib /config/guacamole/extensions
2. 创建软链接
(py3) [root@jumpserver docker-guacamole]# ln -sf /opt/docker-guacamole/guacamole-auth-jumpserver-1.0.0.jar /config/guacamole/extensions/guacamole-auth-jumpserver-1.0.0.jar
3. 链接 guacamole 配置文件
$ ln -sf /opt/docker-guacamole/root/app/guacamole/guacamole.properties /config/guacamole/guacamole.properties
4. 下载tomcat
$ cd /config
(py3) [root@jumpserver config]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.50/bin/apache-tomcat-8.5.50.tar.gz
(py3) [root@jumpserver config]# tar xf apache-tomcat-8.5.50.tar.gz
(py3) [root@jumpserver config]# rm -rf apache-tomcat-8.5.50.tar.gz
(py3) [root@jumpserver config]# mv apache-tomcat-8.5.50/ tomcat8
(py3) [root@jumpserver config]# rm -rf /config/tomcat8/webapps/*
5. 配置tomcat
(py3) [root@jumpserver config]# ln -sf /opt/docker-guacamole/guacamole-1.0.0.war /config/tomcat8/webapps/ROOT.war # guacamole client
$ sed -i 's/Connector port="8080"/Connector port="8081"/g' /config/tomcat8/conf/server.xml # 修改默认端口为 8081
$ sed -i 's/FINE/WARNING/g' /config/tomcat8/conf/logging.properties # 修改 log 等级为 WARNING
$ cd /config
$ wget https://github.com/ibuler/ssh-forward/releases/download/v0.0.5/linux-amd64.tar.gz
$ tar xf linux-amd64.tar.gz -C /bin/
$ chmod +x /bin/ssh-forward
4.4 配置环境变量
$ export JUMPSERVER_SERVER=http://127.0.0.1:8080 # http://127.0.0.1:8080 指 jumpserver 访问地址
(py3) [root@jumpserver config]# echo "export JUMPSERVER_SERVER=http://127.0.0.1:8080" >> ~/.bashrc
BOOTSTRAP_TOKEN 为 Jumpserver/config.yml 里面的 BOOTSTRAP_TOKEN
$ export BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN
$ echo "export BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc
$ export JUMPSERVER_KEY_DIR=/config/guacamole/keys
$ echo "export JUMPSERVER_KEY_DIR=/config/guacamole/keys" >> ~/.bashrc
$ export GUACAMOLE_HOME=/config/guacamole
$ echo "export GUACAMOLE_HOME=/config/guacamole" >> ~/.bashrc
4.5 启动Guacamole
(py3) [root@jumpserver config]# /etc/init.d/guacd start
Starting guacd: guacd[54108]: INFO: Guacamole proxy daemon (guacd) version 1.0.0 started
SUCCESS
(py3) [root@jumpserver config]# sh /config/tomcat8/bin/startup.sh
Using CATALINA_BASE: /config/tomcat8
Using CATALINA_HOME: /config/tomcat8
Using CATALINA_TMPDIR: /config/tomcat8/temp
Using JRE_HOME: /usr
Using CLASSPATH: /config/tomcat8/bin/bootstrap.jar:/config/tomcat8/bin/tomcat-juli.jar
Tomcat started.
5 配置 nginx 整合各组件
5.1安装Nginx
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
$ yum install -y nginx
$ rm -rf /etc/nginx/conf.d/default.conf
systemctl enable nginx & systemctl start nginx
5.2 编写配置文件
$ vi /etc/nginx/conf.d/jumpserver.conf
server {
listen 80; # 代理端口,以后将通过此端口进行访问,不再通过8080端口
server_name 192.168.10.70; # 修改成你的域名或者注释掉
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;
}
}
5.3 运行Nginx
1. 检测配置有没有问题, 有问题请先解决
nginx -t
2. 启动
$ systemctl start nginx
$ systemctl enable nginx
5.4 开始使用Jumpserver
检查应用是否已经正常运行
服务全部启动后,访问 ip 访问nginx代理的端口,不要再通过8080端口访问
默认账号: admin 密码: admin到Jumpserver 会话管理-终端管理 检查 Coco Guacamole 等应用的注册。
5.5 测试连接
如果登录客户端是 macOS 或 Linux ,登录语法如下
$ ssh -p2222 admin@10.0.0.66
$ sftp -P2222 admin@10.0.0.66
密码: admin
如果登录客户端是 Windows ,Xshell Terminal 登录语法如下
$ ssh admin@10.0.0.66 2222
$ sftp admin@10.0.0.66 2222
密码: admin
如果能登陆代表部署成功
sftp默认上传的位置在资产的 /tmp 目录下
windows拖拽上传的位置在资产的 Guacamole RDP上的 G 目录下
例如xshell连接