(aws)使用elastic beantalk遇到的问题

分类: AUTOMATION 发布于:

Elastic beantalk提供了可自由扩展部署、监控、api柯里化等一系列非常友好的工具。

安装eb客户端

通过brew安装客户端

brew install awsebcli

确认eb输出

Welcome to the Elastic Beanstalk Command Line Interface (EB CLI).
For more information on a specific command, type "eb {cmd} --help".

commands:
  abort        Cancels an environment update or deployment.
  appversion   Listing and managing application versions
  clone        Clones an environment.
  codesource   Configures the code source for the EB CLI to use by default.
  config       Modify an environment's configuration. Use subcommands to manage saved configurations.
  console      Opens the environment in the AWS Elastic Beanstalk Management Console.
  create       Creates a new environment.
  deploy       Deploys your source code to the environment.
  events       Gets recent events.
  health       Shows detailed environment health.
  init         Initializes your directory with the EB CLI. Creates the application.
  labs         Extra experimental commands.
  list         Lists all environments.
  local        Runs commands on your local machine.
  logs         Gets recent logs.
  open         Opens the application URL in a browser.
  platform     Commands for managing platforms.
  printenv     Shows the environment variables.
  restore      Restores a terminated environment.
  scale        Changes the number of running instances.
  setenv       Sets environment variables.
  ssh          Opens the SSH client to connect to an instance.
  status       Gets environment information and status.
  swap         Swaps two environment CNAMEs with each other.
  tags         Allows adding, deleting, updating, and listing of environment tags.
  terminate    Terminates the environment.
  upgrade      Updates the environment to the most recent platform version.
  use          Sets default environment.

配置输出awslogs

自定义instance log

[messages]
file = /var/log/messages
log_group_name = jiaofu-syslog-product
log_stream_name = {instance_id}-{hostname}-messages
datetime_format = %Y-%m-%d %H:%M:%S
time_zone = LOCAL
buffer_duration = 5000

[laravel.log]
file = /var/app/current/storage/logs/laravel.log
log_group_name =  jiaofu-applog-product
log_stream_name = {instance_id}-{hostname}-applog
datetime_format = %Y-%m-%d %H:%M:%S
time_zone = LOCAL

在elastic beantalk中开启logs

npm 包安装问题

  01-start-pm2:
    command: 'npm install --unsafe-perm=true --allow-root && pm2 start ecosystem.config.js --env production'

出现错误

pm ERR! path /var/app/ondeck
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/var/app/ondeck'
npm ERR!  { [Error: EACCES: permission denied, access '/var/app/ondeck']
npm ERR!   stack: "Error: EACCES: permission denied, access '/var/app/ondeck'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/var/app/ondeck' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

解决方法

eb在deploy的时候,默认使用root执行, npm内部默认使用普通用户权限,这样就是产生了一个矛盾。

通过追加参数解决00

npm install --unsafe-perm=true --allow-root