jumper-server-部署官網版

 

本文連接:https://www.cnblogs.com/wwtao/p/11491574.htmlhtml

官網連接: https://jumpserver.readthedocs.io/zh/master/setup_by_localcloud.html前端

參考連接 : https://www.cnblogs.com/zsl-find/articles/11181624.htmlpython

 

1.mysql

環境部署yum update -y

# 防火牆 與 selinux 設置說明, 若是已經關閉了 防火牆 和 Selinux 的用戶請跳過設置
systemctl start firewalld
firewall-cmd --zone=public --add-port=80/tcp --permanent  # nginx 端口
firewall-cmd --zone=public --add-port=2222/tcp --permanent  # 用戶SSH登陸端口 koko
  --permanent  永久生效, 沒有此參數重啓後失效

firewall-cmd --reload  # 從新載入規則

setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

# 安裝依賴包
yum -y install wget gcc epel-release git

# 安裝 Redis, Jumpserver 使用 Redis 作 cache 和 celery broke
yum -y install redis
systemctl enable redis
systemctl start redis

# 安裝 MySQL, 若是不使用 Mysql 能夠跳過相關 Mysql 安裝和配置, 支持sqlite3, mysql, postgres等
yum -y install mariadb mariadb-devel mariadb-server MariaDB-shared # centos7下叫mariadb, 用法與mysql一致
systemctl enable mariadb
systemctl start mariadb
# 建立數據庫 Jumpserver 並受權
DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24`  # 生成隨機數據庫密碼
echo -e "\033[31m 你的數據庫密碼是 $DB_PASSWORD \033[0m"
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;"

# 安裝 Nginx, 用做代理服務器整合 Jumpserver 與各個組件
$ vi /etc/yum.repos.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

$ yum -y install nginx
systemctl enable nginx

# 安裝 Python3.6
yum -y install python36 python36-devel

# 配置並載入 Python3 虛擬環境
cd /opt
python3.6 -m venv py3  # py3 爲虛擬環境名稱, 可自定義
source /opt/py3/bin/activate  # 退出虛擬環境可使用 deactivate 命令

# 看到下面的提示符表明成功, 之後運行 Jumpserver 都要先運行以上 source 命令, 載入環境後默認如下全部命令均在該虛擬環境中運行
(py3) [root@localhost py3]

# 下載 Jumpserver 能夠用下載好的包上傳
$ cd /opt/
$ git clone --depth=1 https://github.com/jumpserver/jumpserver.git

# 安裝依賴 RPM 包
$ yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt)

# 安裝 Python 庫依賴
$ pip install --upgrade pip setuptools
$ pip install -r /opt/jumpserver/requirements/requirements.txt

#阿里源更新更快一些
$ 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/linux

 

 

2. # 修改 Jumpserver 配置文件
cd /opt/jumpserver
cp config_example.yml config.yml

SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50`  # 生成隨機SECRET_KEY
echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc
BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16`  # 生成隨機BOOTSTRAP_TOKEN
echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc

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

echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m"
echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m"

$ vi config.yml  # 確認內容有沒有錯誤nginx

 

 

3.運行 Jumpserver
$ cd /opt/jumpserver $ ./jms start -d # 後臺運行使用 -d 參數./jms start -d # 新版本更新了運行腳本, 使用方式./jms start|stop|status all 後臺運行請添加 -d 參數
4 。# 安裝 docker 部署 koko 與 guacamole
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
yum -y install docker-ce
systemctl enable docker
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
systemctl restart docker

# 容許 容器ip 訪問宿主 8080 端口, (容器的 ip 能夠進入容器查看)
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
# 172.17.0.x 是docker容器默認的IP池, 這裏偷懶直接受權ip段了, 能夠根據實際狀況單獨受權IP

# 獲取當前服務器 IP
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`
echo -e "\033[31m 你的服務器IP是 $Server_IP \033[0m"

# http://<Jumpserver_url> 指向 jumpserver 的服務端口, 如 http://192.168.244.144:8080
# BOOTSTRAP_TOKEN 爲 Jumpserver/config.yml 裏面的 BOOTSTRAP_TOKEN
#注意docker可能會拉取兩次guacamole 可能和docker版本有關已經下載好備份了
$ docker run --name jms_koko -d -p 2222:2222 -p 5000:5000 -e CORE_HOST=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN jumpserver/jms_koko:1.5.1
$ 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.5.1

5.# 安裝 Web Terminal 前端: Luna  須要 Nginx 來運行訪問 訪問(https://github.com/jumpserver/luna/releases)下載對應版本的 release 包, 直接解壓, 不須要編譯
$ cd /opt
$ wget https://github.com/jumpserver/luna/releases/download/1.5.1/luna.tar.gz

# 若是網絡有問題致使下載沒法完成可使用下面地址
$ wget https://demo.jumpserver.org/download/luna/1.5.1/luna.tar.gz

tar xf luna.tar.gz
chown -R root:root luna


6.vi /etc/nginx/conf.d/jumpserver.conf

server {
    listen 80;

    client_max_body_size 100m;  # 錄像及文件上傳大小限制

    location /luna/ {
        try_files $uri / /index.html;
        alias /opt/luna/;  # 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/;
        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://localhost: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://localhost: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://localhost: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.# 運行 Nginx
$ nginx -t   # 確保配置沒有問題, 有問題請先解決
$ systemctl start nginx

# 訪問 http://192.168.244.144 (注意 沒有 :8080 經過 nginx 代理端口進行訪問)
# 默認帳號: admin 密碼: admin  到會話管理-終端管理 接受 koko Guacamole 等應用的註冊
# 測試鏈接
$ 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 目錄下

8.1 rm -rf /opt/jumpserver  # jumpserver 目錄
rm -rf /opt/coco  # coco 目錄
rm -rf /opt/koko /opt/kokodir  # koko 目錄
rm -rf /opt/docker-guacamole  # guacamole 目錄
rm -rf /opt/py3  # python3 虛擬環境
rm -rf /config  # guacamole client 目錄
rm -rf /etc/nginx/conf.d/jumpserver.conf



8.2 $ rm -rf /opt/jumpserver  # jumpserver 目錄
$ rm -rf /opt/py3  # python3 虛擬環境
$ rm -rf /etc/nginx/conf.d/jumpserver.conf

# 刪除 docker 組件
$ docker rm jms_coco
$ docker rm jms_koko
$ docker rm jms_guacamole
$ docker rmi jumpserver/jms_coco:1.5.1  # 自行替換版本
$ docker rmi jumpserver/jms_koko:1.5.1  # 自行替換版本
$ docker rmi jumpserver/jms_guacamole:1.5.1  # 自行替換版本

# 刪除自啓文件
$ rm -rf /usr/lib/systemd/system/jms.service
$ rm -rf /opt/start_jms.sh
$ rm -rf /opt/stop_jms.sh

# 刪除數據庫
$ mysql -uroot
> drop database jumpserver;
> exit

# 清空 redis
$ redis-cli -h 127.0.0.1
> flushall
> exit

$ reboot # 重啓服務器



9.# Jumpserver
$ vi /usr/lib/systemd/system/jms.service
[Unit]
Description=jms
After=network.target mariadb.service redis.service docker.service
Wants=mariadb.service redis.service docker.service

[Service]
Type=forking
Environment="PATH=/opt/py3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
ExecStart=/opt/jumpserver/jms start all -d
ExecReload=
ExecStop=/opt/jumpserver/jms stop

[Install]
WantedBy=multi-user.target
--------------------------------------------------------------
# 啓動
$ vi /opt/start_jms.sh

#!/bin/bash
set -e

export LANG=zh_CN.UTF-8

systemctl start jms
docker start jms_koko
docker start jms_guacamole

exit 0
--------------------------------------------------------------
# 中止
$ vi /opt/stop_jms.sh

#!/bin/bash
set -e

export LANG=zh_CN.UTF-8

docker stop jms_koko
docker stop jms_guacamole
systemctl stop jms

exit 0
--------------------------------------------------------------
# 寫入 rc.local
$ chmod +x /etc/rc.d/rc.local
$ if [ "$(cat /etc/rc.local | grep start_jms.sh)" == "" ]; then echo "sh /opt/start_jms.sh" >> /etc/rc.local; fi

重點粘貼複製部署方式git

 

https://jumpserver.readthedocs.io/zh/master/setup_by_localcloud.htmlgithub

 

 

1.
echo -e "\033[31m 1. 防火牆 Selinux 設置 \033[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

2. 注意源可能有問題須要比對 # yum --enablerepo=updates clean metadata
 echo -e "\033[31m 2. 部署環境 \033[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]\nname=nginx stable repo\nbaseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/\ngpgcheck=1\nenabled=1\ngpgkey=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 MariaDB-shared 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

3.
echo -e "\033[31m 3. 下載組件 \033[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.5.2/luna.tar.gz; tar xf luna.tar.gz; chown -R root:root luna; fi \
  && yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt) \
  && echo -e "[easy_install]\nindex_url = https://mirrors.aliyun.com/pypi/simple/" > ~/.pydistutils.cfg \
  && 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_koko:1.5.2 \
  && docker pull jumpserver/jms_guacamole:1.5.2 \
  && rm -rf /etc/nginx/conf.d/default.conf \
  && wget -O /etc/nginx/conf.d/jumpserver.conf https://demo.jumpserver.org/download/nginx/conf.d/jumpserver.conf

4.
echo -e "\033[31m 4. 處理配置文件 \033[0m" \
  && source ~/.bashrc \
  && 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

5.

echo -e "\033[31m 5. 啓動 Jumpserver \033[0m" \
  && systemctl start nginx \
  && cd /opt/jumpserver \
  && ./jms start -d \
  && docker run --name jms_koko -d -p 2222:2222 -p 127.0.0.1:5000:5000 -e CORE_HOST=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN --restart=always jumpserver/jms_koko:1.5.2 \
  && docker run --name jms_guacamole -d -p 127.0.0.1:8081:8081 -e JUMPSERVER_SERVER=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN --restart=always jumpserver/jms_guacamole:1.5.2 \
  && echo -e "\033[31m 你的數據庫密碼是 $DB_PASSWORD \033[0m" \
  && echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m" \
  && echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m" \
  && echo -e "\033[31m 你的服務器IP是 $Server_IP \033[0m" \
  && echo -e "\033[31m 請打開瀏覽器訪問 http://$Server_IP 用戶名:admin 密碼:admin \033[0m"

----
 你的數據庫密碼是 CgOhWnDvDpvH4AskVJlNMD6p
 你的SECRET_KEY是 PaGqYgCzBNaw2t27LdLlvW5hnJvqIgh5iuGYqIl5mQsxC7rkoU
 你的BOOTSTRAP_TOKEN是 JW5HpUJMiY4Przv9
 你的服務器IP是 192.168.1.130
 請打開瀏覽器訪問 http://192.168.1.130 用戶名:admin 密碼:admin

6.
echo -e "\033[31m 6. 配置自啓 \033[0m" \
  && if [ ! -f "/usr/lib/systemd/system/jms.service" ]; then wget -O /usr/lib/systemd/system/jms.service https://demo.jumpserver.org/download/shell/centos/jms.service; chmod 755 /usr/lib/systemd/system/jms.service; systemctl enable jms; firedis

相關文章
相關標籤/搜索