centos7 安装jumpserver

centos7 安装jumpserver

1.       环境:


·        系统: CentOS 7

·        IP: 192.168.24.128

·        关闭 selinux 和防火墙

[root@jumpserver~]# systemctl stop firewalld.service

[root@jumpserver~]# systemctl enable firewalld.service

[root@jumpserver~]# setenforce 0 #可以设置配置文件永久关闭

2.       修改字符集,否则可能报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

3.       准备 Python3 Python 虚拟环境

安装依赖包

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

编译安装

$ 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

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

 

建立Python 虚拟环境


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

$ cd /opt
$ python3 -m venv py3
$ source /opt/py3/bin/activate

# 看到下面的提示符代表成功,以后运行 Jumpserver 都要先运行以上 source 命令,以下所有命令均在该虚拟环境中运行

(py3)[root@localhost py3]

自动载入Python 虚拟环境配置

此项仅为懒癌晚期的人员使用,防止运行 Jumpserver 时忘记载入 Python 虚拟环境导致程序无法运行。使用autoenv

$ git clone git://github.com/kennethreitz/autoenv.git ~/.autoenv
$ echo 'source ~/.autoenv/activate.sh' >> ~/.bashrc
$ source ~/.bashrc

4.       安装 Jumpserver

下载或Clone 项目

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

$ cd /opt/
$ git clone --depth=1 https://github.com/jumpserver/jumpserver.git && cd jumpserver && git checkout master
$ echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env  # 进入 jumpserver 目录时将自动载入 python 虚拟环境

# 首次进入 jumpserver 文件夹会有提示,按 y 即可
# Are you sure you want to allow this? (y/N) y

安装依赖RPM

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

安装Python 库依赖

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

5.       安装 Redis, Jumpserver 使用 Redis cache celery broke

$ yum -y install redis
$ systemctl start redis

6.       安装 MySQL

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

$ yum -y install mariadb mariadb-devel mariadb-server # centos7下安装的是mariadb
$ systemctl enable mariadb
$ systemctl start mariadb

更改密码
systemctl start mariadb
systemctl enable mariadb
    
接下来进行MariaDB的相关简单配置,设置密码,会提示先输入密码
mysql_secure_installation
首先是设置密码,会提示先输入密码
    
Enter current password for root (enter for none):<–初次运行直接回车
    
设置密码
    
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
    
其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

创建数据库Jumpserver 并授权

$ mysql
> create database jumpserver default charset 'utf8';
> grant all on jumpserver.* to 'jumpserver'@'%' identified by '123456';
> flush privileges;

修改Jumpserver 配置文件

$ cd /opt/jumpserver
$ cp config_example.py config.py
$ vi config.py

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

class DevelopmentConfig(Config):
    DEBUG = True
    DB_ENGINE = 'mysql'
    DB_HOST = '127.0.0.1'
    DB_PORT = 3306
    DB_USER = 'jumpserver'
    DB_PASSWORD = '123456'
    DB_NAME = 'jumpserver'
...

config = DevelopmentConfig()  # 确保使用的是刚才设置的配置文件

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

$ cd /opt/jumpserver/utils
$ bash make_migrations.sh

运行Jumpserver

$ cd /opt/jumpserver
$ ./jms start all  # 后台运行使用 -d 参数./jms start all -d      (我是放在后台运行的)

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

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

附上重启的方法

$ ./jms restart



7.       安装 SSH Server WebSocket Server: Coco

下载或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 虚拟环境

# 首次进入 coco 文件夹会有提示,按 y 即可
# Are you sure you want to allow this? (y/N) y

安装依赖

$ cd /opt/coco/requirements
$ yum -y  install $(cat rpm_requirements.txt)
$ pip install -r requirements.txt -i https://pypi.org/simple

查看配置文件并运行

$ cd /opt/coco
$ cp conf_example.py conf.py  # 如果 coco 与 jumpserver 分开部署,请手动修改 conf.py
$ ./cocod start  # 后台运行使用 -d 参数./cocod start -d

# 新版本更新了运行脚本,使用方式./cocod start|stop|status|restart  后台运行请添加 -d 参数

启动成功后去Jumpserver会话管理-终端管理

http://192.168.24.128:8080/terminal/terminal/)接受coco的注册,如果页面不正常可以等部署完成后再处理


8.       安装 Web Terminal 前端: Luna

 

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

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

解压Luna

$ pwd
/opt/

$ wget https://github.com/jumpserver/luna/releases/download/v1.0.0/luna.tar.gz
$ tar xvf luna.tar.gz
$ ls /opt/luna

9.       配置 Nginx 整合各组件

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

$ yum -y install nginx

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

内容如下:

server {
    listen 80;

    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/ {
        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://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";
    }

    location /guacamole/ {
        proxy_pass       http://localhost:8081/;   # 如果guacamole安装在别的服务器,请填写它的ip
        proxy_buffering off;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $http_connection;
        access_log off;
    }

    location / {
        proxy_pass http://localhost:8080;     # 如果jumpserver安装在别的服务器,请填写它的ip
    }
}

运行Nginx

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

$ systemctl start nginx
$ systemctl enable nginx

开始使用Jumpserver

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

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

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

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

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

默认账号: admin 密码: admin

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

** 测试连接**

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

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

# sftp默认上传的位置在资产的 /tmp 目录下
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值