码迷,mamicode.com
首页 > 其他好文 > 详细

jumpserver 安装

时间:2018-10-19 14:03:13      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:postgres   head   erro   ESS   bind   ota   lock   yum   status   

系统环境

系统:CentOS 7
IP:192.168.11.207
关闭selinux和防火墙

Yum 源设置请参考 <http://mirrors.163.com/.help/centos.html>;
yum -y install epel-release # epel源

#CentOS 7
[root@test4-8g ~]#  systemctl stop firewalld       #临时关闭,重启后失效
[root@test4-8g ~]#  systemctl disable firewalld
[root@test4-8g ~]#  cat /etc/selinux/config
SELINUX=disabled
[root@test4-8g ~]#  setenforce 0#临时关闭,重启后失效
[root@test4-8g ~]#  getenforce 0
Permissive

#修改字符集,否则可能报输入/输出错误的问题,因为日志里打印了中文
[root@test4-8g ~]#  localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8
[root@test4-8g ~]#  export  LC_ALL=zh_CN.UTF-8
[root@test4-8g ~]#  echo  ‘LANG="zh_CN.UTF-8"‘ > /etc/locale.conf

#CentOS6
[root@test4-8g ~]#  setenforce 0#临时关闭,重启后失效
[root@test4-8g ~]#  service iptables stop#临时关闭,重启后失效

#修改字符集,否则可能报输入/输出错误的问题,因为日志里打印了中文
[root@test4-8g ~]#  localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8
[root@test4-8g ~]#  export LC_ALL = zh_CN.UTF-8
[root@test4-8g ~]#  echo‘LANG = zh_CN.UTF-8‘> / etc / sysconfig / i18n

一,准备Python3和Python虚拟环境

1.1 安装依赖包

[root@test4-8g ~]#  yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git

1.2编译安装

[root@test4-8g ~]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
[root@test4-8g ~]# tar xvf Python-3.6.1.tar.xz && cd Python-3.6.1
[root@test4-8g Python-3.6.1]#  ./configure && make && make instal

#这里必须执行编译安装,否则在安装Python库依赖时会有麻烦...

1.3建立Python虚拟环境

[root@test4-8g Python-3.6.1]# cd /opt/
[root@test4-8g opt]# python3 -m venv py3
[root@test4-8g opt]# source /opt//py3/bin/activate

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

二,安装 Jumpserver

2.1 下载或 Clone 项目

   (py3) [root@test4-8g opt]# cd /opt/
   (py3) [root@test4-8g opt]# git clone https://github.com/jumpserver/jumpserver.git
   (py3) [root@test4-8g opt]#  cd jumpserver && git checkout master
   $ echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env  # 进入 jumpserver 目录时将自动载入 python 虚拟环境

2.2 安装依赖 RPM 包

   (py3) [root@test4-8g opt]# cd /opt/jumpserver/requirements
   (py3) [root@test4-8g requirements]# yum -y install $(cat rpm_requirements.txt)  # 如果没有任何报错请继续

2.3 安装 Python 库依赖

#pip国内源地址
#pip install pip -U
#pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple # 清华镜像源

   (py3) [root@test4-8g requirements]# pip install -r requirements.txt     # pip国外源下载缓慢,强烈建议使用国内源

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

 (py3) [root@test4-8g requirements]# yum -y install redis
 (py3) [root@test4-8g requirements]# systemctl enable redis
 (py3) [root@test4-8g requirements]# systemctl start  redis

2.5 安装 MySQL

 (py3) [root@test4-8g ~]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
 (py3) [root@test4-8g ~]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
 (py3) [root@test4-8g ~]# yum install mysql-server -y
 (py3) [root@test4-8g ~]# systemctl start mysqld
 (py3) [root@test4-8g ~]# systemctl enable mysqld

2.6 创建数据库 Jumpserver 并授权

MySq首次登陆数据库密码 # grep passw /var/log/mysql.log
Root密码修改后进行以下操作 # mysqladmin -uroot -p‘password‘ password ‘password‘

 (py3) [root@test4-8g ~]# mysql -uroot -p
   > create database jumpserver default charset ‘utf8‘;       # 建库
   > grant all on jumpserver.* to ‘jumpserver‘@‘%‘ identified by ‘Jumpserver@123‘;       #创建用户并授权
   > flush privileges;

2.7 修改 Jumpserver 配置文件

 (py3) [root@test4-8g ~]# cd /opt/jumpserver/
 (py3) [root@test4-8g jumpserver]# cp config_example.py config.py
 (py3) [root@test4-8g jumpserver]# vim config.py 
    # 去掉以下注释并修改(留意数据库用户名以及密码的修改)
    # MySQL or postgres setting like:
    DB_ENGINE = os.environ.get("DB_ENGINE") or ‘mysql‘
    DB_HOST = os.environ.get("DB_HOST") or ‘127.0.0.1‘
    DB_PORT = os.environ.get("DB_PORT") or 3306
    DB_USER = os.environ.get("DB_USER") or ‘jumpserver‘
    DB_PASSWORD = os.environ.get("DB_PASSWORD") or ‘Jumpserver@123‘    
    DB_NAME = os.environ.get("DB_NAME") or ‘jumpserver‘

    # When Django start it will bind this host and port
    # Django 监听的ip和端口
    # ./manage.py runserver 127.0.0.1:8080
    HTTP_BIND_HOST = ‘192.168.11.207‘           # 本机IP
    HTTP_LISTEN_PORT = 8080

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

 (py3) [root@test4-8g jumpserver]# cd /opt/jumpserver/utils/
 (py3) [root@test4-8g utils]# bash make_migrations.sh

2.9 运行 Jumpserver

 (py3) [root@test4-8g utils]# cd /opt/jumpserver/
 (py3) [root@test4-8g jumpserver]#  ./jms start all   # 后台运行使用 -d 参数./jms start all -d

运行不报错,请浏览器访问 http://192.168.11.207:8080/ 默认账号: admin 密码: admin 页面显示不正常先不用处理,继续往下操作,后面搭建 nginx 代理后即可正常访问,原因是因为 django 无法在非 debug 模式下加载静态资源

三. 安装 SSH Server 和 WebSocket Server: Coco

3.1 下载或 Clone 项目

新开一个终端,别忘了 source /opt/py3/bin/activate

 (py3) [root@test4-8g ~]# cd /opt/
 (py3) [root@test4-8g opt]# git clone https://github.com/jumpserver/coco.git  && cd coco && git checkout master
 (py3) [root@test4-8g coco]# echo "source /opt/py3/bin/activate" > /opt/coco/.env     # 进入 coco 目录时将自动载入 python 虚拟环境

3.2 安装依赖

  (py3) [root@test4-8g opt]# cd /opt/coco/requirements/
  (py3) [root@test4-8g requirements]# yum -y  install $(cat rpm_requirements.txt)   
  (py3) [root@test4-8g requirements]# pip install -r requirements.txt    

注:pip install -r requirements.txt 遇到一个包jumpserver-python-sdk版本不对
解决办法:好像是国内的镜像同步不到最新的版本,我把之前的pip国内镜像源先注释掉,然后就下载成功

3.3 修改配置文件并运行

  (py3) [root@test4-8g requirements]# cd /opt/coco/
  (py3) [root@test4-8g coco]# mkdir keys
  (py3) [root@test4-8g coco]# cp conf_example.py conf.py   # 如果 coco 与 jumpserver 分开部署,请手动修改 conf.py
  (py3) [root@test4-8g coco]# vim conf.py
    # 项目名称, 会用来向Jumpserver注册, 识别而已, 不能重复
    # NAME = "localhost"
    NAME = "coco"
    # Jumpserver项目的url, api请求注册会使用
    # CORE_HOST = os.environ.get("CORE_HOST") or ‘http://127.0.0.1:8080‘
    CORE_HOST = os.environ.get("CORE_HOST") or ‘http://192.168.11.207:8080‘     
    # 设置日志级别 [‘DEBUG‘, ‘INFO‘, ‘WARN‘, ‘ERROR‘, ‘FATAL‘, ‘CRITICAL‘]
    # LOG_LEVEL = ‘INFO‘
    LOG_LEVEL = ‘WARN‘
    #其他默认

3.4 启动coco

   (py3) [root@test4-8g coco]# ./cocod start  -d    # 后台运行使用 -d 

启动时遇到问题 FileNotFoundError: [Errno 2] No such file or directory: ‘/opt/coco/logs/coco.log‘
解决 : 创建‘/opt/coco/logs/coco.log‘文件

启动成功后去Jumpserver 会话管理-终端管理 http://192.168.11.207:8080/terminal/terminal/ 接受coco的注册

四. 安装 Web Terminal 前端: Luna

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

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

   (py3) [root@test4-8g coco]# cd /opt/
   (py3) [root@test4-8g opt]# wget https://github.com/jumpserver/luna/releases/download/1.4.3/luna.tar.gz
   (py3) [root@test4-8g opt]# tar xvf luna.tar.gz 
   (py3) [root@test4-8g opt]#  chown -R root:root luna

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

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

   (py3) [root@test4-8g opt]# yum remove docker-latest-logrotate docker-logrotate docker-selinux dockdocker-engine
   (py3) [root@test4-8g opt]# yum install -y yum-utils device-mapper-persistent-data lvm2
   # 添加docker官方源
   (py3) [root@test4-8g opt]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
   (py3) [root@test4-8g opt]#  yum makecache fast
   (py3) [root@test4-8g opt]# yum -y install docker-ce
   (py3) [root@test4-8g opt]# systemctl start docker
   (py3) [root@test4-8g opt]# systemctl status docker

6.2 启动 Guacamole

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

    (py3) [root@test4-8g opt]# 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.11.207:8080 \      #填写jumpserver的url地址
               jumpserver/guacamole:latest

启动成功后去Jumpserver 会话管理-终端管理 http://192.168.11.207:8080/terminal/terminal/ 接受[Gua]开头的一个注册

六. 配置 Nginx 整合各组件

6.1 下载Nginx

     (py3) [root@test4-8g opt]#  yum -y install nginx

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

  (py3) [root@test4-8g ~]# vim /etc/nginx/nginx.conf

   # 注意注释 nginx.conf 里面的 server {} 内容 ,CentOS 6 需要修改文件 /etc/nginx/cond.f/default.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 / {
            proxy_pass http://192.168.11.207: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;
        }
        location /luna/ {                                            # 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 /socket.io/ {                                                                             # 如果coco安装在别的服务器,请填写它的ip
            proxy_pass       http://192.168.11.207:5000/socket.io/;
            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/ {                                                                                              # 如果coco安装在别的服务器,请填写它的ip
            proxy_pass       http://192.168.11.207:5000/coco/;
            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/ {                                                                              # 如果guacamole安装在别的服务器,请填写它的ip
            proxy_pass       http://192.168.11.207:8081/;
            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;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

6.3 运行 Nginx

(py3) [root@test4-8g ~]#  nginx -t   # 确保配置没有问题, 有问题请先解决
# CentOS 7
(py3) [root@test4-8g ~]# systemctl start nginx 
(py3) [root@test4-8g ~]# systemctl enable nginx

# CentOS 6
$ service nginx start
$ chkconfig nginx on

6.4 开始使用 Jumpserver

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

(py3) [root@test4-8g ~]#  cd /opt/jumpserver
(py3) [root@test4-8g jumpserver]#  ./jms status  # 确定jumpserver已经运行,如果没有运行请重新启动jumpserver

(py3) [root@test4-8g ~]#  cd /opt/coco
(py3) [root@test4-8g coco]#  ./cocod status  # 确定jumpserver已经运行,如果没有运行请重新启动coco

# 如果安装了 Guacamole
(py3) [root@test4-8g ~]#  docker ps  # 检查容器是否已经正常运行,如果没有运行请重新启动Guacamole

服务全部启动后,访问 http://192.168.11.207,访问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 目录下
# windows拖拽上传的位置在资产的 Guacamole RDP上的 G 目录下

jumpserver 安装

标签:postgres   head   erro   ESS   bind   ota   lock   yum   status   

原文地址:http://blog.51cto.com/13767724/2305149

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!