• Centos7自动式脚本搭建jumpserver


    JumpServer脚本

    这里需要安装阿里的yum源和epel源并解压:

    epel源地址https://mirrors.tuna.tsinghua.edu.cn/epel//

    安装阿里互联网yum仓库

    [root@192 ~]# cd /etc/yum.repos.d/

    [root@192 yum.repos.d]# wget -O /etc/yum.repos.d/aliyun.repo https://mirrors.aliyum.com/repo/Centos-7.repo

    [root@192 ~]# rz -E

    这个就是epel源:epel-release-latest-7.noarch.rpm

    把包解压到repos.d

    r[root@192 yum.repos.d]#rpm -ivh epel-release-7-9.noarch.rpm

    [root@192 yum.repos.d]# ls

    aliyun.repo       CentOS-Debuginfo.repo  CentOS-Vault.repo            epel-testing.repo

    bak               CentOS-fasttrack.repo  docker-ce.repo               nginx.repo

    CentOS-Base.repo  CentOS-Media.repo      epel-release-7-9.noarch.rpm

    CentOS-CR.repo    CentOS-Sources.repo    epel.repo

    [root@192 ~]# vim jumpserver.sh

    #!/bin/bash

    echo -e "33[31m 1. 防火墙 Selinux 设置 33[0m"

      && if [ "$(systemctl status firewalld | grep running)" != "" ]; then firewall-cmd --zone=public --add-port=80/tcp --permanent; firewall-cmd --zone=public --add-port=2222/tcp --permanent; firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="172.17.0.0/16" port protocol="tcp" port="8080" accept"; firewall-cmd --reload; fi

      && if [ "$(getenforce)" != "Disabled" ]; then setsebool -P httpd_can_network_connect 1; fi

     

    echo -e "33[31m 2. 部署环境 33[0m"

      && yum update -y

      && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

      && yum -y install kde-l10n-Chinese

      && 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

      && yum -y install wget gcc epel-release git

      && yum install -y yum-utils device-mapper-persistent-data lvm2

      && yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

      && yum makecache fast

      && rpm --import https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

      && echo -e "[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key" > /etc/yum.repos.d/nginx.repo

      && rpm --import https://nginx.org/keys/nginx_signing.key

      && yum -y install redis mariadb mariadb-devel mariadb-server nginx docker-ce

      && systemctl enable redis mariadb nginx docker

      && systemctl start redis mariadb

      && yum -y install python36 python36-devel

      && python3.6 -m venv /opt/py3

     

    echo -e "33[31m 3. 下载组件 33[0m"

      && cd /opt

      && if [ ! -d "/opt/jumpserver" ]; then git clone --depth=1 https://github.com/jumpserver/jumpserver.git; fi

      && if [ ! -f "/opt/luna.tar.gz" ]; then wget https://demo.jumpserver.org/download/luna/1.4.9/luna.tar.gz; tar xf luna.tar.gz; chown -R root:root luna; fi

      && yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt)

      && source /opt/py3/bin/activate

      && pip install --upgrade pip setuptools -i https://mirrors.aliyun.com/pypi/simple/

      && pip install -r /opt/jumpserver/requirements/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

      && curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

      && systemctl restart docker

      && docker pull jumpserver/jms_coco:1.4.9

      && docker pull jumpserver/jms_guacamole:1.4.9

      && rm -rf /etc/nginx/conf.d/default.conf

      && curl -o /etc/nginx/conf.d/jumpserver.conf https://demo.jumpserver.org/download/nginx/conf.d/jumpserver.conf

     

    echo -e "33[31m 4. 处理配置文件 33[0m"

      && if [ "$DB_PASSWORD" = "" ]; then DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24`; fi

      && if [ "$SECRET_KEY" = "" ]; then SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50`; echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc; fi

      && if [ "$BOOTSTRAP_TOKEN" = "" ]; then BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16`; echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc; fi

      && if [ "$Server_IP" = "" ]; then Server_IP=`ip addr | grep inet | egrep -v '(127.0.0.1|inet6|docker)' | awk '{print $2}' | tr -d "addr:" | head -n 1 | cut -d / -f1`; fi

      && if [ ! -d "/var/lib/mysql/jumpserver" ]; then mysql -uroot -e "create database jumpserver default charset 'utf8';grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by '$DB_PASSWORD';flush privileges;"; fi

      && if [ ! -f "/opt/jumpserver/config.yml" ]; then cp /opt/jumpserver/config_example.yml /opt/jumpserver/config.yml; sed -i "s/SECRET_KEY:/SECRET_KEY: $SECRET_KEY/g" /opt/jumpserver/config.yml; sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /opt/jumpserver/config.yml; sed -i "s/# DEBUG: true/DEBUG: false/g" /opt/jumpserver/config.yml; sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" /opt/jumpserver/config.yml; sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: false/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" /opt/jumpserver/config.yml; sed -i "s/DB_PASSWORD: /DB_PASSWORD: $DB_PASSWORD/g" /opt/jumpserver/config.yml; fi

     

    echo -e "33[31m 5. 启动 Jumpserver 33[0m"

      && systemctl start nginx

      && cd /opt/jumpserver

      && ./jms start all -d

      && docker run --name jms_coco -d -p 2222:2222 -p 5000:5000 -e CORE_HOST=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN jumpserver/jms_coco:1.4.9

      && docker run --name jms_guacamole -d -p 8081:8081 -e JUMPSERVER_SERVER=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN jumpserver/jms_guacamole:1.4.9

      && echo -e "33[31m 你的数据库密码是 $DB_PASSWORD 33[0m"

      && echo -e "33[31m 你的SECRET_KEY$SECRET_KEY 33[0m"

      && echo -e "33[31m 你的BOOTSTRAP_TOKEN$BOOTSTRAP_TOKEN 33[0m"

      && echo -e "33[31m 你的服务器IP$Server_IP 33[0m"

      && echo -e "33[31m 请打开浏览器访问 http://$Server_IP 用户名:admin 密码:admin 33[0m"

     

    脚本执行后会给出以下提示,请保存

     你的数据库密码是 ep40Jo1ePuGr6E0syeILIv8U

     你的SECRET_KEY2iVyw2k3t6gSzVwM8dc3WWOrygdRODAbpyv90a3T5056bM9x00

     你的BOOTSTRAP_TOKENfk0G7iITiSUIfMPI

     你的服务器IP192.168.0.110

     请打开浏览器访问 http://192.168.0.110 用户名:admin 密码:admin

     配置自启

     启动停止的脚本在 /opt 目录下, 如果自启失败可以手动启动

  • 相关阅读:
    SD卡的控制方法(指令集和控制时序)
    MDK的优化应用(转)
    SD卡的SPI模式的初始化顺序(转)
    SD卡读写扇区注意事项(转)
    MDK下调试时提示AXF文件无法导入的解决方法(转)
    把一个 int 数字 n 格式化成16进制的字符串(前面补零成0位)
    DB9 公头母头引脚定义及连接、封装
    RS232 DB9 公头 母头 串口引脚定义
    Codeforces 91C Ski Base 加边求欧拉回路数量
    Cocos Code IDE + Lua初次使用FastTiledMap的坑
  • 原文地址:https://www.cnblogs.com/zc1741845455/p/10836672.html
Copyright © 2020-2023  润新知