当前位置:   article > 正文

Jumpserver安装部署_jumpserver 专线 内网

jumpserver 专线 内网

环境

  • 系统: CentOS 7
  • IP: 192.168.10.130
  • 关闭 selinux 和防火墙
  1. # CentOS 7
  2. $ setenforce 0 # 可以设置配置文件永久关闭
  3. $ systemctl stop iptables.service
  4. $ systemctl stop firewalld.service
  5. # 修改字符集,否则可能报 input/output error的问题,因为日志里打印了中文
  6. $ localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8
  7. $ export LC_ALL=zh_CN.UTF-8
  8. $ echo 'LANG=zh_CN.UTF-8' > /etc/locale.conf
  9. # CentOS6
  10. $ setenforce 0
  11. $ service iptables stop
  12. # 修改字符集,否则可能报 input/output error的问题,因为日志里打印了中文
  13. $ localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8
  14. $ export LC_ALL=zh_CN.UTF-8
  15. $ echo 'LANG=zh_CN.UTF-8' > /etc/sysconfig/i18n​

一. 准备 Python3 和 Python 虚拟环境

1.1 安装依赖包

$ yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git​

Yum 加速设置请参考 <http://mirrors.163.com/.help/centos.html>

1.2 编译安装

  1. $ mkdir /soft && cd /soft
  2. $ wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
  3. $ tar xvf Python-3.6.1.tar.xz && cd Python-3.6.1
  4. $ ./configure && make && make install
  5. # 这里必须执行编译安装,否则在安装 Python 库依赖时会有麻烦...

1.3 建立 Python 虚拟环境

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

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

二. 安装 Jumpserver 1.0.0

2.1 下载或 Clone 项目

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

  1. $ cd /opt/
  2. $ git clone --depth=1 https://github.com/jumpserver/jumpserver.git && cd jumpserver && git checkout master​

2.2 安装依赖 RPM 包

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

2.3 安装 Python 库依赖

$ pip install -r requirements.txt  # 不要指定-i参数,因为镜像上可能没有最新的包,如果没有任何报错请继续

Pip 加速设置请参考 <https://segmentfault.com/a/1190000011875306>

2.4 安装 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke

  1. $ yum -y install redis
  2. $ systemctl start redis
  3. # centos6
  4. $ service redis start​

2.5 安装 MySQL

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

  1. # centos7
  2. $ yum -y install mariadb mariadb-devel mariadb-server # centos7下安装的是mariadb
  3. $ systemctl enable mariadb
  4. $ systemctl start mariadb
  5. # centos6
  6. $ yum -y install mysql mysql-devel mysql-server
  7. $ chkconfig mysqld on
  8. $ service mysqld start

2.6 创建数据库 Jumpserver 并授权

  1. $ mysql
  2. > create database jumpserver default charset 'utf8';
  3. > grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by '密码';

2.7 修改 Jumpserver 配置文件

  1. $ cd /opt/jumpserver
  2. $ cp config_example.py config.py
  3. $ vi config.py
  4. # 我们计划修改 DevelopmentConfig 中的配置,因为默认 Jumpserver 使用该配置,它继承自 Config

注意: 配置文件是 Python 格式,不要用 TAB,而要用空格

  1. class DevelopmentConfig(Config):
  2. # pass
  3. DEBUG = True
  4. DB_ENGINE = 'mysql'
  5. DB_HOST = '127.0.0.1'
  6. DB_PORT = 3306
  7. DB_USER = 'jumpserver'
  8. DB_PASSWORD = '密码'
  9. DB_NAME = 'jumpserver'
  10. ...
  11. config = DevelopmentConfig() # 确保使用的是刚才设置的配置文件​

2.8 生成数据库表结构和初始化数据

  1. $ cd /opt/jumpserver/utils
  2. $ bash make_migrations.sh​

2.9 运行 Jumpserver

  1. $ cd /opt/jumpserver
  2. $ ./jms start all # 后台运行使用 -d 参数./jms start all -d
  3. # 新版本更新了运行脚本,使用方式./jms start|stop|status|restart all 后台运行请添加 -d 参数

运行不报错,请浏览器访问 http://192.168.10.130:8080/ 默认账号: admin 密码: admin 页面显示不正常先不用处理,搭建 nginx 代理就可以正常访问了

附上重启的方法

$ ./jms restart​

三. 安装 SSH Server 和 WebSocket Server: Coco

3.1 下载或 Clone 项目

新开一个终端,连接测试机,别忘了 source /opt/py3/bin/activate

  1. $ cd /opt
  2. $ source /opt/py3/bin/activate
  3. $ git clone https://github.com/jumpserver/coco.git && cd coco && git checkout master​

3.2 安装依赖

  1. $ cd /opt/coco/requirements
  2. $ yum -y install $(cat rpm_requirements.txt)
  3. $ pip install -r requirements.txt​

3.3 查看配置文件并运行

  1. $ cd /opt/coco
  2. $ cp conf_example.py conf.py # 如果 coco 与 jumpserver 分开部署,请手动修改 conf.py
  3. $ ./cocod start # 后台运行使用 -d 参数./cocod start -d
  4. # 执行此命令前请保证./jms start all 启动正常,192.168.10.130:8080可正常打开,
  5. # 新版本更新了运行脚本,使用方式./cocod start|stop|status|restart 后台运行请添加 -d 参数​

报错:

  1. 2018-04-16 09:50:45 [service DEBUG] Initial app service
  2. 2018-04-16 09:50:45 [service DEBUG] Load access key
  3. 2018-04-16 09:50:45 [service DEBUG] Set app service auth: f93a9592-cadb-4972-a24f-a2555dad1997
  4. 2018-04-16 09:50:45 [service ERROR] Connect server error or access key is invalid, remove `./keys/.access_key` run again
  5. 2018-04-16 09:50:48 [service ERROR] Connect server error or access key is invalid, remove `./keys/.access_key` run again
  6. 2018-04-16 09:50:51 [service ERROR] Connect server error or access key is invalid, remove `./keys/.access_key` run again

解决:

  1. # 重启jumpserver
  2. $ cd /opt/jumpserver
  3. $ ./jms restart
  4. # jumpserver启动正常后启动coco
  5. $ cd /opt/coco
  6. $ ./cocod start

启动成功后去Jumpserver 会话管理-终端管理(http://192.168.10.130:8080/terminal/terminal/)接受coco的注册,如果页面不正常可以等部署完成后再处理

四. 安装 Web Terminal 前端: Luna

Luna 已改为纯前端,需要 Nginx 来运行访问

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

4.1 解压 Luna

  1. $ pwd
  2. /opt/
  3. $ wget https://github.com/jumpserver/luna/releases/download/v1.0.0/luna.tar.gz
  4. $ tar xvf luna.tar.gz
  5. $ ls /opt/luna
  6. ...​

 

五. 安装 Windows 支持组件(如果不需要管理 windows 资产,可以直接跳过这一步)

因为手动安装 guacamole 组件比较复杂,这里提供打包好的 docker 使用, 启动 guacamole

5.1 Docker安装 (仅针对CentOS7,CentOS6安装Docker相对比较复杂)

  1. $ yum remove docker-latest-logrotate docker-logrotate docker-selinux dockdocker-engine
  2. $ yum install docker-ce
  3. $ yum install -y yum-utils device-mapper-persistent-data lvm2
  4. $ yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  5. $ yum-config-manager --enable docker-ce-edge
  6. $ yum-config-manager --enable docker-ce-test
  7. $ yum-config-manager --disable docker-ce-edge
  8. $ yum install docker-ce
  9. $ systemctl start docker
  10. $ systemctl status docker​

 

5.2 启动 Guacamole

这里所需要注意的是 guacamole 暴露出来的端口是 8081,若与主机上其他端口冲突请自定义

修改 JUMPSERVER_SERVER 环境变量的配置,填上 Jumpserver 的内网地址, 启动成功后去 Jumpserver 会话管理-终端管理(http://192.168.244.144:8080/terminal/terminal/)接受[Gua]开头的一个注册,如果页面显示不正常可以等部署完成后再处理

  1. # 注意:这里一定要改写一下本机的IP地址, 否则会出错, 带宽有限, 下载时间可能有点长,可以喝杯咖啡,撩撩对面的妹子
  2. $ docker run --name jms_guacamole -d \
  3. -p 8081:8080 -v /opt/guacamole/key:/config/guacamole/key \
  4. -e JUMPSERVER_KEY_DIR=/config/guacamole/key \
  5. -e JUMPSERVER_SERVER=http://192.168.10.130:8080 \
  6. registry.jumpserver.org/public/guacamole:1.0.0​

启动成功后去Jumpserver 会话管理-终端管理(http://192.168.10.130:8080/terminal/terminal/)接受Gua的注册,如果页面不正常可以等部署完成后再处理

六. 配置 Nginx 整合各组件

6.1 安装 Nginx 根据喜好选择安装方式和版本

$ yum -y install nginx

 

6.2 准备配置文件 修改 /etc/nginx/nginx.conf

内容如下:

  1. $ vim /etc/nginx/nginx.conf
  2. ... 省略
  3. # 把默认server配置块改成这样
  4. server {
  5. listen 80;
  6. proxy_set_header X-Real-IP $remote_addr;
  7. proxy_set_header Host $host;
  8. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  9. location /luna/ {
  10. try_files $uri / /index.html;
  11. alias /opt/luna/;
  12. }
  13. location /media/ {
  14. add_header Content-Encoding gzip;
  15. root /opt/jumpserver/data/;
  16. }
  17. location /static/ {
  18. root /opt/jumpserver/data/;
  19. }
  20. location /socket.io/ {
  21. proxy_pass http://localhost:5000/socket.io/; # 如果coco安装在别的服务器,请填写它的ip
  22. proxy_buffering off;
  23. proxy_http_version 1.1;
  24. proxy_set_header Upgrade $http_upgrade;
  25. proxy_set_header Connection "upgrade";
  26. }
  27. location /guacamole/ {
  28. proxy_pass http://localhost:8081/; # 如果guacamole安装在别的服务器,请填写它的ip
  29. proxy_buffering off;
  30. proxy_http_version 1.1;
  31. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  32. proxy_set_header Upgrade $http_upgrade;
  33. proxy_set_header Connection $http_connection;
  34. access_log off;
  35. }
  36. location / {
  37. proxy_pass http://localhost:8080; # 如果jumpserver安装在别的服务器,请填写它的ip
  38. }
  39. }
  40. ... 省略​

6.3 运行 Nginx

  1. nginx -t # 确保配置没有问题, 有问题请先解决
  2. # CentOS 7
  3. $ systemctl start nginx
  4. $ systemctl enable nginx
  5. # CentOS 6
  6. $ service nginx start
  7. $ chkconfig nginx on

 

6.4 开始使用 Jumpserver

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

  1. # 如果是新开的终端,别忘了 source /opt/py3/bin/activate
  2. $ cd /opt/jumpserver
  3. $ ./jms status # 确定jumpserver已经运行,如果没有运行请重新启动jumpserver
  4. $ cd /opt/coco
  5. $ ./cocod status # 确定jumpserver已经运行,如果没有运行请重新启动coco
  6. # 如果安装了 Guacamole
  7. $ docker ps # 检查容器是否已经正常运行,如果没有运行请重新启动Guacamole​

服务全部启动后,访问 http://192.168.10.130

默认账号: admin 密码: admin

如果部署过程中没有接受应用的注册,需要到Jumpserver 会话管理-终端管理 接受 Coco Guacamole 等应用的注册。

** 测试连接**

  1. $ ssh -p2222 admin@192.168.10.130
  2. 密码: admin
  3. 如果能登陆代表部署成功​

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号