开发者社区 问答 正文

常见问题:监控与自动化部署问题



如何判断弹性伸缩中实例的可用性?


如果弹性伸缩在伸缩组里配置了负载均衡,负载均衡检查您后端的ECS端口正常之后,才会将请求转发给新的实例。

弹性伸缩中的告警触发条件有哪些?


可以针对CPU负载、内存利用率、系统平均负载、外网和内网出入流量等进行监测告警,自动增加或减少ECS实例。

弹性伸缩是否可以根据云监控中自定义报警项进行动态伸缩?


目前不支持根据自定义监控进行动态伸缩。

伸缩组内创建的ECS应用部署如何自动化?


在弹性伸缩自动创建ECS实例后,如果想要自动安装、更新程序和自动加载代码,需要您在自定义镜像中存放执行脚本,并设置命令使操作系统启动后自动执行该脚本。
注意:由于 CentOS 6 及以下系统采用 system V init 作为初始化进程,但 CentOS 7 采用了systemd来做初始化进程,它的工作原理和之前的 system V init 区别较大。以下分别针对 CentOS 6 以及 CentOS 7 进行说明。

CentOS 6 及以下系统


  1. 创建以下shell测试脚本:#。/bin/sh
  2. # chkconfig: 6 10 90
  3. # description: Test Service
  4. echo "hello world!"

针对上述脚本中的# chkconfig: 6 10 90,说明如下:
其中6默认启动级别,级别有 0 ~ 6 共 7 个级别。
  • 等级0表示:关机
  • 等级1表示:单用户模式
  • 等级2表示:无网络连接的多用户命令行模式
  • 等级3表示:有网络连接的多用户命令行模式
  • 等级4表示:不可用
  • 等级5表示:带图形界面的多用户模式
  • 等级6表示:重新启动
  • 10是启动优先级,90是停止优先级,优先级范围是 0 ~ 100,数字越大,优先级越低。

将测试文件放在/etc/rc.d/init.d/目录下,执行chkconfig --level 6 test on。
说明:以后每次开机启动都会执行该测试脚本。

示例


以脚本安装Phpwind为例,您可以将phpwind安装程序放到脚本中执行(数据库密码仍需要您自己输入),如下仅是示例,您可以按照示例进行修改。
  1. cd /tmp
  2. echo "phpwind"
  3. yum install -y \
  4.      unzip \
  5.      wget \
  6.      httpd \
  7.      php \
  8.      php-fpm \
  9.      php-mysql \
  10.      php-mbstring \
  11.      php-xml \
  12.      php-gd \
  13.      php-pear \
  14.      php-devel
  15. chkconfig php-fpm on \
  16.      && chkconfig httpd on
  17. wget http://pwfiles.oss-cn-hangzhou.aliyuncs.com/com/soft/phpwind_v9.0_utf8.zip \
  18.      && unzip -d pw phpwind_v9.0_utf8.zip \
  19.      && mv pw/phpwind_v9.0_utf8/upload/*  /var/www/html \
  20.      && wget http://ess.oss-cn-hangzhou.aliyuncs.com/ossupload_utf8.zip -O ossupload_utf8.zip \
  21.      && unzip -d ossupload ossupload_utf8.zip \
  22.      && /bin/cp -rf ossupload/ossupload_utf8/* /var/www/html/src/extensions/ \
  23.      && chown -R apache:apache /var/www/html
  24. service httpd start && service php-fpm start
  25. echo "安装云监控"
  26. wget http://update2.aegis.aliyun.com/download/quartz_install.sh
  27. chmod +x quartz_install.sh
  28. bash quartz_install.sh
  29. echo "安装完成"


CentOS 7 系统


CentOS 7 采用了systemd来做初始化进程,工作原理与 system V init 区别较大。假设您已创建好脚本,并且测试其运行无误。参照如下步骤,使您使用systemd时,在系统关闭状态仍能运行脚本。

  1. 在/etc/systemd/system下创建一个文件 run-script-when-shutdown.service,文件内容如下(请把ExecStop变量的值,修改为您需要运行脚本的绝对路径): [Unit]
  2. Description=service to run script when shutdown
  3. After=syslog.target network.target
  4. [Service]
  5. Type=simple
  6. ExecStart=/bin/true
  7. ExecStop=/path/to/script/to/run
  8. RemainAfterExit=yes
  9. [Install]
  10. WantedBy=default.target

执行如下命令,使能新创建的服务:
  1. systemctl enable run-script-when-shutdown
  2. systemd start run-script-when-shutdown

说明:
  • 为了使当前服务立即生效,需另外执行restart命令。
  • 您可以配置run-script-when-shutdown运行固定的脚本。需要的时候,相关人员可以修改这个固定的脚本,使其更加灵活实用。

无需运行上述服务时,请执行如下命令:
  1. systemctl disable run-script-when-shutdown

展开
收起
青蛙跳 2018-08-17 14:09:08 1549 分享 版权
0 条回答
写回答
取消 提交回答