华为云服务器极速安装

说明

  • 全新安装的 Centos7 系统
  • 保持服务器网络畅通

开始安装

以下命令均在一个终端里面执行

  1. $ echo -e "\033[31m 1. 防火墙 Selinux 设置 \033[0m" \
  2. && 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 \
  3. && if [ "$(getenforce)" != "Disabled" ]; then setsebool -P httpd_can_network_connect 1; fi
  1. $ echo -e "\033[31m 2. 部署环境 \033[0m" \
  2. && sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/CentOS-Base.repo \
  3. && sed -i "s/mirrorlist=http/#mirrorlist=http/g" /etc/yum.repos.d/CentOS-Base.repo \
  4. && sed -i "s@http://mirror.centos.org@https://mirrors.huaweicloud.com@g" /etc/yum.repos.d/CentOS-Base.repo \
  5. && yum clean all \
  6. && yum makecache \
  7. && yum update -y \
  8. && yum -y install wget gcc epel-release git \
  9. && sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/epel.repo \
  10. && sed -i "s/mirrorlist/#mirrorlist/g" /etc/yum.repos.d/epel.repo \
  11. && sed -i "s@http://download.fedoraproject.org/pub@https://mirrors.huaweicloud.com@g" /etc/yum.repos.d/epel.repo \
  12. && yum clean all \
  13. && yum makecache \
  14. && yum install -y yum-utils device-mapper-persistent-data lvm2 \
  15. && yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo \
  16. && yum makecache fast \
  17. && rpm --import https://mirrors.aliyun.com/docker-ce/linux/centos/gpg \
  18. && 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 \
  19. && rpm --import https://nginx.org/keys/nginx_signing.key \
  20. && yum -y install redis mariadb mariadb-devel mariadb-server mariadb-shared nginx docker-ce \
  21. && systemctl enable redis mariadb nginx docker \
  22. && systemctl start redis mariadb \
  23. && yum -y install python36 python36-devel \
  24. && python3.6 -m venv /opt/py3
  1. $ echo -e "\033[31m 3. 下载组件 \033[0m" \
  2. && cd /opt \
  3. && if [ ! -d "/opt/jumpserver" ]; then git clone https://github.com/jumpserver/jumpserver.git; cd /opt/jumpserver; git checkout 1.4.8; cd /opt; fi \
  4. && if [ ! -f "/opt/luna.tar.gz" ]; then wget https://demo.jumpserver.org/download/luna/1.4.8/luna.tar.gz; tar xf luna.tar.gz; chown -R root:root luna; fi \
  5. && yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt) \
  6. && source /opt/py3/bin/activate \
  7. && pip install --upgrade pip setuptools -i https://mirrors.huaweicloud.com/repository/pypi/simple \
  8. && pip install -r /opt/jumpserver/requirements/requirements.txt -i https://mirrors.huaweicloud.com/repository/pypi/simple \
  9. && curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io \
  10. && systemctl restart docker \
  11. && docker pull jumpserver/jms_coco:1.4.8 \
  12. && docker pull jumpserver/jms_guacamole:1.4.8 \
  13. && rm -rf /etc/nginx/conf.d/default.conf \
  14. && wget -O /etc/nginx/conf.d/jumpserver.conf https://demo.jumpserver.org/download/nginx/conf.d/jumpserver.conf
  1. $ echo -e "\033[31m 4. 处理配置文件 \033[0m" \
  2. && if [ "$DB_PASSWORD" = "" ]; then DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24`; fi \
  3. && 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 \
  4. && 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 \
  5. && 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 \
  6. && 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 \
  7. && 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
  1. $ echo -e "\033[31m 5. 启动 Jumpserver \033[0m" \
  2. && systemctl start nginx \
  3. && cd /opt/jumpserver \
  4. && ./jms start -d \
  5. && 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.8 \
  6. && 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.8 \
  7. && echo -e "\033[31m 你的数据库密码是 $DB_PASSWORD \033[0m" \
  8. && echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m" \
  9. && echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m" \
  10. && echo -e "\033[31m 你的服务器IP是 $Server_IP \033[0m" \
  11. && echo -e "\033[31m 请在安全组里面放行80和2222端口 \033[0m" \
  12. && echo -e "\033[31m 请打开浏览器访问公网80端口 用户名:admin 密码:admin \033[0m"
  1. $ echo -e "\033[31m 6. 配置自启 \033[0m" \
  2. && 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; fi \
  3. && if [ ! -f "/opt/start_jms.sh" ]; then wget -O /opt/start_jms.sh https://demo.jumpserver.org/download/shell/centos/start_jms.sh; fi \
  4. && if [ ! -f "/opt/stop_jms.sh" ]; then wget -O /opt/stop_jms.sh https://demo.jumpserver.org/download/shell/centos/stop_jms.sh; fi \
  5. && if [ "$(cat /etc/rc.local | grep start_jms.sh)" == "" ]; then echo "sh /opt/start_jms.sh" >> /etc/rc.local; chmod +x /etc/rc.d/rc.local; fi \
  6. && echo -e "\033[31m 启动停止的脚本在 /opt 目录下, 如果自启失败可以手动启动 \033[0m"