AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[ruby-on-rails](server)

Martin Hope
jacob_g
Asked: 2021-05-13 09:35:48 +0800 CST

EC2:相对较小的网络输出峰值导致 100% 的 CPU 使用率

  • 0

背景

你好,

我有一台在免费 EC2 实例上运行的服务器。我使用 nginx 和乘客/rails 作为我的 Web 服务器和应用程序服务器。服务器接收到的流量很少(仍在开发中),但来自随机机器人的流量是合理的。服务器还提供来自 S3 的图像。前端mywebsite.com由一个服务器块中定义的静态服务 at 提供,后端使用乘客 at 提供服务api.mywebsite.com。

问题

服务器上的 CPU 使用率看似随机地达到 100%。CPU 使用峰值与网络输出峰值相关,尽管网络输出峰值似乎仍然相对较小。发生这种情况时,前端无法再提供服务,我什至无法通过 SSH 连接到服务器以检查正在运行的进程。

我试过的

  • 使用此 bad-bot-blocker阻止恶意机器人。
  • 将网络峰值与 nginx 访问日志中的请求相关联/var/logs/nginx/access.log。通常相关性是很不清楚的。
  • 寻找/var/logs/nginx/error.log任何相关的东西。

当 CPU 执行此操作时,我通常最终会在 EC2 控制台上重新启动服务器,这似乎可以工作,但显然是不可持续的。

我是部署东西/DevOps 的新手,所以我想知道根据这些信息是否有任何明显的我可能遗漏的东西。我什至不确定是什么层导致了问题(AWS/nginx/我的 rails 后端/vanilla HTML/JS 前端)。如果我能提供任何其他信息,请告诉我。

谢谢,

雅各布

amazon-ec2 ruby-on-rails nginx amazon-web-services cpu-usage
  • 1 个回答
  • 444 Views
Martin Hope
Jean-Paul Calderone
Asked: 2021-02-12 11:41:15 +0800 CST

如何为 GitLab NixOS 服务配置主机名?

  • 1

我正在尝试在 NixOS 20.09.1632.a6a3a368dda (Nightingale) 上部署一个新的 GitLab 实例。

我有这个相当小的configuration.nix:

{ modulesPath, ... }:
let
  host = "example.org";
  adminEmail = "admin@example.org";
in
{
  imports = [ "${modulesPath}/virtualisation/amazon-image.nix" ];
  ec2.hvm = true;

  services.gitlab = rec {
    enable = true;

    inherit host;
    port = 80;

    # You, dear sysadmin, have to make these files exist.
    initialRootPasswordFile = "/tmp/gitlab-secrets/initial-password";

    secrets = rec {
      # A file containing 30 "0" characters.
      secretFile = "/tmp/gitlab-secrets/zeros";
      dbFile = secretFile;
      otpFile = secretFile;
      # openssl genrsa 2048 > jws.rsa
      jwsFile = "/tmp/gitlab-secrets/jws.rsa";
    };
  };

  services.nginx = {
    enable = true;
    user = "gitlab";
    virtualHosts = {
      "${host}" = {
        locations."/" = {
          # http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
          proxyPass = "http://unix:/var/gitlab/state/tmp/sockets/gitlab.socket";
        };
      };
    };
  };

  networking.firewall = {
    enable = true;
    allowPing = false;
    allowedTCPPorts = [
      22
      80
    ];
  };
}

激活此配置时,会启动许多进程(redis、postgresql、sidekiq 等)。然而,nginx(感谢,我假设,GitLab 的 Rails HTTP 服务器)用以下方式响应请求/:

* Connected to example.org (X.X.X.X) port 80 (#0)
> GET / HTTP/1.1
> Host: example.org
> User-Agent: curl/7.72.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 302 Found
< Server: nginx
< Date: Thu, 11 Feb 2021 19:38:40 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Frame-Options: DENY
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Download-Options: noopen
< X-Permitted-Cross-Domain-Policies: none
< Referrer-Policy: strict-origin-when-cross-origin
< X-UA-Compatible: IE=edge
< Location: http://localhost/users/sign_in
< Cache-Control: no-cache
< Set-Cookie: experimentation_subject_id=eyJfcmFpbHMiOnsibWVzc2FnZSI6IklqZGhabU0zWXpVNExUSmxNR1F0TkdZMlpTMWlZVEkwTFdKak1EVTFaREZoTURJd1ppST0iLCJleHAiOm51bGwsInB1ciI6ImNvb2tpZS5leHBlcmltZW50YXRpb25fc3ViamVjdF9pZCJ9fQ%3D%3D--cbf53392028ed41f7c582a64e643476a5c2aab6b; path=/; expires=Mon, 11 Feb 2041 19:38:40 -0000; HttpOnly
< X-Request-Id: 545cc04e-1689-4351-b5a9-ca171f1a85d4
< X-Runtime: 0.060596
< 
* Connection #0 to host example.org left intact
<html><body>You are being <a href="http://localhost/users/sign_in">redirected</a>.</body></html>

由于localhostis not example.org,因此失败。

如何配置 GitLab 以了解其自己的主机名?

ruby-on-rails configuration gitlab nixos
  • 1 个回答
  • 389 Views
Martin Hope
kross
Asked: 2017-09-20 06:56:57 +0800 CST

GKE 上的水平自动缩放轨道 - 特别是 - Web 服务器的选择和与传统部署的区别

  • 1

这是一篇关于使用 heroku 进行扩展的精彩文章(它适用于传统部署)。

鉴于我们希望容器化应用程序是单个进程,我们如何获得:

  • 缓慢的客户保护
  • 慢响应保护

在充分利用水平 pod 自动缩放的 Kubernetes/GKE 环境中?

假设我的部署看起来很像以下(信用@nithinmalya4):

概述

我还没有选择 Web 服务器,默认情况下rackup正在服务WEBrick. 我正在考虑将其更改为多线程 Puma。

我担心的是autoscaler基于CPU的作品,而不是基于它的想法consumed by a current http/s request,所以它可能不会发挥作用。

  1. 我是否正确理解自动缩放器?
  2. 什么是理想的向上/向下扩展架构?

我们目前的想法:

  • nginxdeflater在Ingress.

  • puma在rails前面(与imagerails-api相同),假设它会更好地利用cpu并触发自动缩放

  • HPA 的自定义指标(仍然需要使用 1.8 进行研究)

ruby-on-rails
  • 2 个回答
  • 646 Views
Martin Hope
François Noël
Asked: 2017-01-18 09:04:11 +0800 CST

Nginx代理依赖域名

  • -1

我正在使用 AWS 的 EC2 和 Nginx。

假设我有三个域名:domain1.com、domain2.com、domain3.com。假设我在三个不同的端口上有三个 rails 应用程序:3000、3001、3002。

所有这些域都在端口 80 上链接到我的服务器。

根据请求的 URL,我希望我的端口 80 将请求重定向到正确的端口。

我应该如何配置我的虚拟主机文件?我知道 If 块存在,但 Nginx 似乎不推荐它。我的计划是在我的 EC2 上拥有多个站点。

我无法在我的 Rails 应用程序端口上阻止服务器,因为它会阻止 Rails 服务器。

amazon-ec2 ruby-on-rails nginx
  • 2 个回答
  • 611 Views
Martin Hope
YWCA Hello
Asked: 2016-08-18 12:37:00 +0800 CST

为什么我的请求排队时间这么长?

  • 2

我正在运行 Rails 应用程序服务器。我的设置是:

  • Apache 2,对 https 和 ssl 客户端证书使用 mod_ssl
  • Phusion 乘客 5
  • 导轨 4
  • 红宝石 2.1

我使用 NewRelic 来监控正在运行的应用程序。我最近启用了对请求排队延迟的监控,主要是出于好奇。我惊讶地发现请求队列中的延迟通常与实际的 ruby​​ 代码和数据库执行时间一样长或更长。~200 毫秒似乎很高,对吧?

显着的请求队列延迟

大多数在线信息表明,当请求队列正在等待工作人员可用时会发生这种情况,但事实并非如此。如下所示,我们几乎没有使用我们预置的实例。在高峰期,我们很少会超过 30% 的利用率。

工作人员实例的利用

其他一些注意事项:

  • Apache 和Passenger 驻留在同一台服务器上,因此不会出现由于系统时钟不同步而导致的错误计时问题。
  • 关于 SSL 处理,Apache 获取客户端 SSL 证书并将其作为请求头附加。然后,rails 应用程序处理其余的处理。

这里可能是什么问题?

apache-2.2 ruby-on-rails phusion-passenger mod-ssl
  • 1 个回答
  • 1295 Views
Martin Hope
bothsa24312
Asked: 2016-06-15 22:33:36 +0800 CST

在 Rails 上安装 Ruby 时出错

  • 0

我查阅了这份文档(如何在 Ubuntu 上使用Passenger 安装Rails 和nginx)。目前我正在使用Ubuntu 14.04.4 LTS. 这次我第一次用rails安装ruby ..我该如何解决这个问题??

rvm install 2.3.1
Searching for binary rubies, this might take some time.
Found remote file https://rubies.travis-ci.org/ubuntu/14.04/x86_64/ruby-2.3.1.tar.bz2
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system.
Installing required packages: libyaml-dev, sqlite3, libgmp-dev, libgdbm-dev, libncurses5-dev...
Error running 'requirements_debian_libs_install libyaml-dev sqlite3 libgmp-dev libgdbm-dev libncurses5-dev',
showing last 15 lines of /usr/local/rvm/log/1465971805_ruby-2.3.1/package_install_libyaml-dev_sqlite3_libgmp-dev_libgdbm-dev_libncurses5-dev.log
Building dependency tree...
Reading state information...
Package libncurses5-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  libtinfo-dev

E: Unable to locate package libyaml-dev
E: Unable to locate package sqlite3
E: Unable to locate package libgmp-dev
E: Unable to locate package libgdbm-dev
E: Package 'libncurses5-dev' has no installation candidate
++ return 100
++ return 100
Requirements installation failed with status: 100.
ubuntu installation ruby-on-rails
  • 1 个回答
  • 685 Views
Martin Hope
Weirdest
Asked: 2016-04-22 14:21:43 +0800 CST

乘客独立抛出 Nginx 404

  • 0

我有一个脚本,可以在启动时为我的 rails 应用程序启动乘客独立服务器。当我从命令行运行此脚本时,它按预期工作。但是,当它运行时,rc.local它crontab会产生此错误。我在任何日志文件中都找不到任何关于我一生的记录。这是怎么回事,我该如何解决?

一些规格:

Digital Ocean Droplet
Ubuntu 15.10:32bit
Passenger 版本:5.0.27
Rails 版本:4.2.6
Ruby 版本:2.3.0

这又是一个独立的服务器,没有反向代理。我正在使用 iptables 将端口 80 重定向到乘客所在的端口(高于 3000)。

任何帮助将不胜感激!

ubuntu ruby-on-rails nginx phusion-passenger
  • 1 个回答
  • 106 Views
Martin Hope
Darth Egregious
Asked: 2015-03-31 17:04:53 +0800 CST

将 Rails 应用程序部署到 OpsWorks 时出现错误“声明配置资源时必须提供名称”

  • 1

将 rails 应用程序从引擎场移动到 OpsWorks 时,我收到以下错误:

Error executing action `deploy` on resource 'deploy[{{ app path }}]'
you must supply a name when declaring a config resouce

将 rails 应用程序部署到 ops 时有效。错误继续说“

我已经确认我的“自定义 json”正在database.yml正确填充文件。

给出了进一步的细节:

Resource Declaration:
deploy deploy[:deploy_to] do
  provider Chef::Provider::Deploy.const_get(deploy[:chef_provider])
  ..

有趣的是,在下面的转储中,有一个params列表,其中包括

:name => nil

这似乎是问题所在。我已经检查了 OpsWorks 中的所有表单,并且每个名称字段都已填充。除此之外,自定义 JSON 似乎是正确的,因为它正在填充到 database.yml 文件中。我不知道还有什么可以从那里检查的。

以前有没有人见过这个问题,或者任何人都可以就我如何确定这里出了什么问题提供任何想法?

ruby-on-rails
  • 1 个回答
  • 1886 Views
Martin Hope
Cojones
Asked: 2015-01-28 07:44:24 +0800 CST

服务器更新后无法安装 rmagick

  • 1

我正在运行一个 debian 服务器并在一段时间后升级了所有软件包(apt-get update, apt-get upgrade, apt-get distro-upgrade)。然后 rmagick 不再工作,因为 imagemagick 已更新。

所以我跑了:

gem uninstall rmagick
bundle install

然后我得到了这个:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/local/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 0.0.0. Can't find Magick-config in /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/bin/ruby

extconf failed, exit code 1

Gem files will remain installed in /srv/www/www.example.com/shared/vendor/bundle/ruby/2.1.0/gems/rmagick-2.13.3 for inspection.
Results logged to /srv/www/www.example.com/shared/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/rmagick-2.13.3/gem_make.out
An error occurred while installing rmagick (2.13.3), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.3'` succeeds before bundling.

这是cat mkmf.log:

    checking for Ruby version >= 1.8.5... -------------------- yes

--------------------

find_executable: checking for gcc... -------------------- yes

--------------------

find_executable: checking for Magick-config... -------------------- no

--------------------

Can't install RMagick 0.0.0. Can't find Magick-config in /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

谁能帮我这个?

--- 更新 1 ---

在安装了一些 graphicsmagic 的东西之后,我得到了一些进一步的信息:

apt-get install graphicsmagick-libmagick-dev-compat
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libmagick++-6-headers libmagick++-6.q16-dev
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  libmagick++-dev libmagickcore-dev
The following NEW packages will be installed:
  graphicsmagick-libmagick-dev-compat
0 upgraded, 1 newly installed, 2 to remove and 1 not upgraded.
Need to get 0 B/26.2 kB of archives.
After this operation, 267 kB disk space will be freed.
Do you want to continue? [Y/n]

这是bundle install输出:

checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... no

Can't install RMagick 0.0.0. Can't find MagickWand.h.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/bin/ruby

extconf failed, exit code 1

这对我们有任何帮助吗?

* --- 更新 2 --- *

单独安装后graphicsmagick-libmagick-dev-compat,libmagickcore-dev我尝试安装libmagick++-dev

apt-get install libmagick++-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  graphicsmagick-libmagick-dev-compat
The following NEW packages will be installed:
  libmagick++-dev
0 upgraded, 1 newly installed, 1 to remove and 1 not upgraded.
Need to get 0 B/121 kB of archives.
After this operation, 115 kB of additional disk space will be used.
ruby-on-rails
  • 3 个回答
  • 5956 Views
Martin Hope
David Krider
Asked: 2014-08-09 11:48:02 +0800 CST

将 Rails 应用程序的 gem 与系统范围的 RVM 安装的 Ruby 捆绑在一起的当前“正确”方法是什么?

  • 0

我通过执行以下操作在系统范围内安装了 ruby​​:

\curl -sSL https://get.rvm.io | sudo bash -s stable

接着:

sudo /usr/local/rvm/bin/rvm install 2.0.0

我仍然不肯定这实际上是正确的,但它似乎奏效了。它创建了一个rvm组。我已将我的用户帐户添加到其中,然后重新登录。现在我需要bundle install为我的 Rails 应用程序添加 gems。这是我能得到的最接近的:

david@excelsior:/data/webapps/accountability$ sudo /usr/local/rvm/gems/ruby-2.0.0-p481@global/bin/bundle
/usr/bin/env: ruby_executable_hooks: No such file or directory

过去,我只是以 root 身份完成了所有这些工作,但是 rvm 网站花了很多时间告诉我这(和 rvmsudo)对于系统范围的操作是“错误的”。所以这次我想尝试“正确”地做,但我找不到他们指出我应该如何做的地方。看起来这个简单的操作将是前沿和中心的。也许我只是瞎了眼?

ruby-on-rails
  • 1 个回答
  • 732 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve