centos7 安装 jumpserver堡垒

环境:CentOS Linux release 7.5.1804 (Core)

内核:3.10.0-862.el7.x86_64

数据库:MySQL5.7

详细参考官方文档:http://docs.jumpserver.org/zh/docs/step_by_step.html

第一步:关闭firewalld 和 selinux ,修改字符集

# setenforce 0  # 临时关闭,重启后失效
# systemctl stop firewalld.service  # 临时关闭,重启后失效

# 修改字符集,否则可能报 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 虚拟环境

2.1 安装依赖包
   # yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git
2.2 编译安装
   # wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
   # tar xvf Python-3.6.1.tar.xz  && cd Python-3.6.1 
   # ./configure && make && make install
3.3 建立 Python 虚拟环境
   # cd /opt
   # python3 -m venv py3
   # source /opt/py3/bin/activate

3.4 出现下面的样子,代表成功,以后的操作都在这个下面操作,别忘source /opt/py3/bin/activate
   (py3) [root@localhost py3]

第三步:安装 Jumpserver(别忘source /opt/py3/bin/activate)

3.1 下载或 Clone 项目
   # cd /opt/
   # git clone https://github.com/jumpserver/jumpserver.git && cd jumpserver && git checkout master
   # echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env  # 进入 jumpserver 目录时将自动载入 python 虚拟环境
3.2 安装依赖 RPM 包
   # cd /opt/jumpserver/requirements
   # yum -y install $(cat rpm_requirements.txt)  # 如果没有任何报错请继续
3.3 安装 Python 库依赖
   # pip install -r requirements.txt 
     pip可以指定源(指定不指定,随意)
     mkdir ~/.pip
     touch ~/.pip/pip.conf  
添加 [global]
     trusted-host=mirrors.aliyun.com
     index-url=http://mirrors.aliyun.com/pypi/simple/
3.4 安装 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke
   # yum -y install redis
   # systemctl enable redis
   # systemctl start redis
3.5 安装 MySQL
   # wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
   # rpm -ivh mysql57-community-release-el7-8.noarch.rpm
   # yum install mysql-server -y
   # systemctl start mysqld
   # systemctl enable mysqld
3.6 创建数据库 Jumpserver 并授权
   $ mysql -uroot -p
   > create database jumpserver default charset 'utf8';
   > grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by 'weakPassword';
   > flush privileges;
3.7 修改 Jumpserver 配置文件
   # cd /opt/jumpserver
   # cp config_example.py config.py
   # 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 'tiger123'
     DB_NAME = os.environ.get("DB_NAME") or 'jumpserver'
     HTTP_BIND_HOST = '这里改为自己的本机IP'
3.8 生成数据库表结构和初始化数据
   # cd /opt/jumpserver/utils
   # bash make_migrations.sh
3.9 运行 Jumpserver
   # cd /opt/jumpserver
   # ./jms start all  # 后台运行使用 -d 参数./jms start all -d

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

四. 安装 SSH Server 和 WebSocket Server: Coco

4.1 下载或 Clone 项目
   新开一个终端,别忘了 source /opt/py3/bin/activate
   # cd /opt
   # source /opt/py3/bin/activate
   # git clone https://github.com/jumpserver/coco.git && cd coco && git checkout master
   # echo "source /opt/py3/bin/activate" > /opt/coco/.env  # 进入 coco 目录时将自动载入 
     python 虚拟环境
4.2 安装依赖
   # cd /opt/coco/requirements
   # yum -y  install $(cat rpm_requirements.txt)
   # pip install -r requirements.txt
4.3 修改配置文件并运行
   # cd /opt/coco
   # mkdir keys
   # cp conf_example.py conf.py  # 如果 coco 与 jumpserver 分开部署,请手动修改 conf.py
   # vim conf.py    //这里我只是改动了一处,把这行的注释解开,修改为自己的本机IP
       CORE_HOST = os.environ.get("CORE_HOST") or 'http://coco安装的本机IP:8080'
4.4 启动coco
   # ./cocod start  # 后台运行使用 -d 参数./cocod start -d

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

五. 安装 Web Terminal 前端: Luna

Luna 已改为纯前端,需要 Nginx 来运行访问。
访问(https://github.com/jumpserver/luna/releases)下载对应版本的 release 包,直接解压,不需要编译

5.1 解压 Luna
   # cd /opt
   # wget https://github.com/jumpserver/luna/releases/download/1.4.3/luna.tar.gz
   # tar xvf luna.tar.gz
   # chown -R root:root luna

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

6.1 Docker安装 (仅针对CentOS7,CentOS6安装Docker相对比较复杂)
   # yum remove docker-latest-logrotate docker-logrotate docker-selinux dockdocker-engine
   # yum install -y yum-utils device-mapper-persistent-data lvm2

   # 添加docker官方源
   # yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
   # yum makecache fast
   # yum install docker-ce 

   # systemctl start docker
   # systemctl status docker 
6.2 启动 Guacamole
   这里所需要注意的是 guacamole 暴露出来的端口是 8081,若与主机上其他端口冲突请自定义
   # 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://<填写jumpserver的url地址,也就是自己的IP+8080端口> \
  jumpserver/guacamole:latest

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

七. 配置 Nginx 整合各组件

7.1 安装 Nginx 根据喜好选择安装方式和版本
   # yum -y install nginx
7.2 准备配置文件 修改 /etc/nginx/nginx.conf  
   # 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 /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/ {
            proxy_pass       http://192.168.3.211: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/ {
            proxy_pass       http://192.168.3.211: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/ {
            proxy_pass       http://192.168.3.211: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;
        }

        location / {
            proxy_pass http://192.168.3.211: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;
        }

7.3 运行 Nginx
   nginx -t   # 确保配置没有问题, 有问题请先解决

   # CentOS 7
   # systemctl start nginx
   # systemctl enable nginx
7.4 开始使用 Jumpserver
   # cd /opt/jumpserver
   # ./jms status  # 确定jumpserver已经运行,如果没有运行请重新启动jumpserver

   # cd /opt/coco
   # ./cocod status  # 确定jumpserver已经运行,如果没有运行请重新启动coco

   # 如果安装了 Guacamole
   # docker ps  # 检查容器是否已经正常运行,如果没有运行请重新启动Guacamole

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

默认账号: admin 密码: admin

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

###测试连接

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

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

# sftp默认上传的位置在资产的 /tmp 目录下
# windows拖拽上传的位置在资产的 Guacamole RDP上的 G 目录下

如果遇到guacamole终端没了,重启docker也无效的情况下

rm /opt/guacamole/key/*

重启docker容器

修改最下面图标

vim /opt/jumpserver/apps/templates/_footer.html

猜你喜欢

转载自blog.51cto.com/14051712/2408436