腳本內容html
#!/bin/bash # coding: utf-8 # Copyright (c) 2018 set -e #返回值爲非0時,退出腳本 echo "0. 系統的一些配置" setenforce 0 || true systemctl stop iptables.service || true >/dev/null 2>&1 systemctl stop firewalld.service || true >/dev/null 2>&1 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/sysconfig/i18n echo "1. 備份yum" { for i in /etc/yum.repos.d/*.repo;do cp $i ${i%.repo}.bak;done rm -rf /etc/yum.repos.d/*.repo } || { echo "yum出錯,請更換源從新運行" exit 1 } echo "2. 獲取網絡yum" { wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo >/dev/null 2>&1 wget -P /etc/yum.repos.d/ http://mirrors.163.com/.help/CentOS7-Base-163.repo >/dev/null 2>&1 yum clean >/dev/null 2>&1 yum repolist >/dev/null 2>&1 } || { echo "yum出錯,請更換源從新運行" exit 1 } echo "3. 安裝基本依賴" { yum update -y>/dev/null && yum install wget unzip epel-release nginx sqlite-devel xz gcc automake zlib-devel openssl-devel redis mariadb mariadb-devel mariadb-server supervisor -y >/dev/null 2>&1 } || { echo "yum出錯,請更換源從新運行" exit 1 } echo "4. 準備python" { cd /opt/ wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz -O /opt/Python-3.6.1.tar.xz >/dev/null 2>&1 } || { echo "pyhton 依賴包下載出錯,請嘗試使用特殊工具進行手工下載https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz ,而且放至於/opt/Python-3.6.1.tar.xz,如您是手工下載,請註釋上面wget命令再運行本腳本" exit 1 } { tar xf Python-3.6.1.tar.xz && cd Python-3.6.1 && ./configure>/dev/null && make>/dev/null && make install >/dev/null 2>&1 } || { echo "解壓或編譯python出錯,請嘗試使用上面的命令手工解壓或編譯,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } { python3 -m venv py3 } || { echo "創建python虛擬環境出錯,請嘗試手工執行,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } echo "5. 下載jummpserver包並解壓" { wget https://github.com/jumpserver/jumpserver/archive/master.zip -O /opt/jumpserver.zip >/dev/null 2>&1 } || { echo "下載jumpserver包出錯,請嘗試手工執行,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } { wget https://github.com/jumpserver/coco/archive/master.zip -O /opt/coco.zip >/dev/null 2>&1 } || { echo "下載coco包出錯,請嘗試手工執行,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } { wget https://github.com/jumpserver/luna/archive/master.zip -O /opt/luna.zip >/dev/null 2>&1 } || { echo "下載luna包出錯,請嘗試手工執行,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } { cd /opt unzip coco.zip >/dev/null && mv coco-master coco && unzip jumpserver.zip >/dev/null && mv jumpserver-master jumpserver && unzip luna.zip >/dev/null && mv luna-master luan 2>&1 } || { echo "解壓出錯,請嘗試手工執行,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } echo "6. 安裝yum依賴" { yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt) >/dev/null && yum -y install $(cat /opt/coco/requirements/rpm_requirements.txt) >/dev/null 2>&1 } || { echo "安裝jumpserver的依賴出錯,請嘗試手工執行,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } echo "7. 安裝pip依賴" { python3 -m venv py3 && \ source /opt/py3/bin/activate && pip install --upgrade pip>/dev/null && pip install -r /opt/jumpserver/requirements/requirements.txt>/dev/null && pip install -r /opt/coco/requirements/requirements.txt >/dev/null 2>&1 } || { echo "安裝pip的依賴出錯,請嘗試手工執行,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } echo "8. 建立數據庫" mkdir -p /opt/mysql/share/mysql/ { wget https://github.com/jumpserver/Dockerfile/blob/mysql/alpine/mysql_security.sql?raw=true -O /opt/mysql/mysql_security.sql >/dev/null 2>&1 wget https://github.com/jumpserver/Dockerfile/blob/mysql/alpine/mysql.cnf?raw=true -O /etc/my.cnf >/dev/null 2>&1 wget https://github.com/jumpserver/Dockerfile/blob/mysql/alpine/errmsg.sys?raw=true -O /opt/mysql/share/mysql/errmsg.sys >/dev/null 2>&1 } || { echo "下載數據庫依賴文件出錯,請嘗試手工執行,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } echo "9. 準備文件" { wget https://github.com/jumpserver/Dockerfile/blob/mysql/alpine/nginx.conf?raw=true -O /etc/nginx/nginx.conf >/dev/null 2>&1 wget https://github.com/jumpserver/Dockerfile/blob/mysql/alpine/supervisord.conf?raw=true -O /etc/supervisord.conf >/dev/null 2>&1 wget https://github.com/jumpserver/Dockerfile/blob/mysql/alpine/jumpserver_conf.py?raw=true -O /opt/jumpserver/config.py >/dev/null 2>&1 wget https://github.com/jumpserver/Dockerfile/blob/mysql/alpine/coco_conf.py?raw=true -O /opt/coco/conf.py >/dev/null 2>&1 wget https://github.com/jumpserver/Dockerfile/blob/mysql/alpine/start_jms.sh?raw=true -O /opt/start_jms.sh >/dev/null 2>&1 } || { echo "下載配置文件出錯,請嘗試手工執行,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } echo "10. 安裝docker" yum check-update >/dev/null 2>&1 { yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo >/dev/null && yum clean all>/dev/null && yum repolist >/dev/null 2>&1 yum -y install epel-release docker-ce >/dev/null 2>&1 systemctl start docker tee -a /etc/sysctl.conf <<-EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl -p >/dev/null 2>&1 tee -a /etc/docker/daemon.json <<-EOF { "registry-mirrors": [ "https://registry.docker-cn.com" ] } EOF } || { echo "安裝docker 出錯,請嘗試手工執行,如手工操做成功,請註釋上述代碼再運行本腳本" exit 1 } systemctl daemon-reload systemctl restart docker echo "11. 安裝guacamole" host_ip=`python -c "import socket;print([(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1])"` docker run --name jms_guacamole -d \ --restart always \ -p 8081:8080 -v /opt/guacamole/key:/config/guacamole/key \ -e JUMPSERVER_KEY_DIR=/config/guacamole/key \ -e JUMPSERVER_SERVER=http://$host_ip:8080 \ registry.jumpserver.org/public/guacamole:1.0.0 echo "12. 配置nginx" yum -y install nginx >/dev/null 2>&1 cat << EOF > /etc/nginx/conf.d/jumpserver.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 } } EOF mkdir -p /opt/nginx/log && chmod -R 777 /opt/nginx { systemctl restart nginx systemctl enable nginx } || { service restart nginx } || { nginx -s reload } || { echo "請檢查nginx的啓動命令" exit 1 } chmod +x /opt/start_jms.sh echo " 安裝完成,請運行/opt/start_jms.sh啓動jumpserver" 標籤: