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 / 问题

问题[amazon-linux-2](server)

Martin Hope
rwhirn
Asked: 2021-12-24 12:59:51 +0800 CST

systemctl restart httpd 启动失败 Apache HTTP Server httpd pid 已经在运行

  • 3

请原谅来自 Stack Overflow 的交叉帖子,但我意识到这可能是更好的询问位置。

我最近在 AWS 上重建了我的服务器,从 Amazon Linux 升级到 Amazon Linux 2,就像 Linux 1 似乎是 CentOS 的一个分支,现在是 CentOS 7。我的虚拟主机配置与之前的构建保持相同,而所有其他 conf 文件都是较新的默认文件。(仅供参考,不确定它是否有任何影响)。

自从重建我不能再做systemctl restart httpd。我得到错误The Apache HTTP Server httpd pid (NNNN) already running。

我做了很多谷歌搜索,发现很多人都有这个错误,但结果总是与他们所做的不同。我想不出我所做的任何“不同”。

我了解到,我看到的“已经在运行”的 PID 由 root 拥有,是“主进程”,而 apache 拥有的所有其他 PID 都是“工作进程”。CentOS httpd 作为 root 和 apache 用户运行

root      4461     1  0 07:18 ?        00:00:00 /usr/sbin/httpd -k restart
apache    4467  4461  0 07:18 ?        00:00:09 /usr/sbin/httpd -k restart
apache    4468  4461  0 07:18 ?        00:00:08 /usr/sbin/httpd -k restart
apache    4471  4461  0 07:18 ?        00:00:08 /usr/sbin/httpd -k restart
apache    4477  4461  0 07:18 ?        00:00:08 /usr/sbin/httpd -k restart
apache    4498  4461  0 07:18 ?        00:00:07 /usr/sbin/httpd -k restart
apache    5236  4461  0 07:19 ?        00:00:08 /usr/sbin/httpd -k restart
apache    5248  4461  0 07:19 ?        00:00:09 /usr/sbin/httpd -k restart
apache    5987  4461  0 07:20 ?        00:00:09 /usr/sbin/httpd -k restart
apache    5993  4461  0 07:20 ?        00:00:08 /usr/sbin/httpd -k restart
apache    5994  4461  0 07:20 ?        00:00:09 /usr/sbin/httpd -k restart
# systemctl restart httpd;systemctl status httpd;
Job for httpd.service failed. See "systemctl status httpd.service" and "journalctl -xe" for details.
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: protocol) since Thu 2021-12-23 19:56:05 UTC; 4ms ago
     Docs: man:httpd.service(8)
  Process: 31799 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=0/SUCCESS)
 Main PID: 31799 (code=exited, status=0/SUCCESS)
   Status: "Reading configuration..."

Dec 23 19:56:04 ip-10-5-11-55.ec2.internal systemd[1]: Starting The Apache HTTP Server...
Dec 23 19:56:05 ip-10-5-11-55.ec2.internal httpd[31799]: httpd (pid 4461) already running
Dec 23 19:56:05 ip-10-5-11-55.ec2.internal systemd[1]: Failed to start The Apache HTTP Server.
Dec 23 19:56:05 ip-10-5-11-55.ec2.internal systemd[1]: Unit httpd.service entered failed state.
Dec 23 19:56:05 ip-10-5-11-55.ec2.internal systemd[1]: httpd.service failed.

Apache 错误日志中没有异常:

[Thu Dec 23 07:18:58.777745 2021] [suexec:notice] [pid 4460] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Dec 23 07:18:58.802753 2021] [lbmethod_heartbeat:notice] [pid 4461] AH02282: No slotmem from mod_heartmonitor
[Thu Dec 23 07:18:58.802850 2021] [http2:warn] [pid 4461] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more
[Thu Dec 23 07:18:58.847386 2021] [mpm_prefork:notice] [pid 4461] AH00163: Apache/2.4.51 () PHP/7.4.21 configured -- resuming normal operations
[Thu Dec 23 07:18:58.847414 2021] [core:notice] [pid 4461] AH00094: Command line: '/usr/sbin/httpd'

如果我杀死这个“主”PID,那么我可以重新启动没问题。

# kill 4461
# systemctl restart httpd;systemctl status httpd;
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-12-23 20:01:31 UTC; 6ms ago
     Docs: man:httpd.service(8)
 Main PID: 3091 (httpd)
   Status: "Configuration loaded."
   CGroup: /system.slice/httpd.service
           └─3091 /usr/sbin/httpd -DFOREGROUND

Dec 23 20:01:31 ip-10-5-11-55.ec2.internal systemd[1]: Starting The Apache HTTP Server...
Dec 23 20:01:31 ip-10-5-11-55.ec2.internal systemd[1]: Started The Apache HTTP Server.
# ps -Af | grep httpd
root      3145     1  1 20:01 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    3147  3145  0 20:01 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    3153  3145  0 20:01 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    3171  3145  0 20:01 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    3177  3145  0 20:01 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    3183  3145  0 20:01 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND

大多数人的建议是“杀死进程”,Apache 无法启动,已经运行但没有处理 pid 文件?但我需要这个在无人看管的情况下工作。我还能看什么?

httpd centos7 amazon-linux-2
  • 2 个回答
  • 6045 Views
Martin Hope
Mervin Hemaraju
Asked: 2021-12-21 07:07:26 +0800 CST

Bash 脚本中的环境变量为空

  • 1

我有一个在 AWS 上部署的 EC2 实例。

我正在使用 Amazon Linux 2,并且我正在将用户数据传递给它:

userdata_file.write(
        f'''
        #!/bin/bash\n
        export PAGERDUTYAPIKEY='mykey'\n
        sudo yum install git -y\n
        chmod +x ./basic_test.sh \n
        echo $PAGERDUTYAPIKEY> /home/ec2-user/pagerdutyapikey1.txt\n
        sudo ./basic_test.sh
        '''.strip()
    )

basic_test.sh

#!/bin/bash

echo "s/enterpagerdutyapikey/${PAGERDUTYAPIKEY}/g" > path.txt

但是,当我运行它时,path.txt它会像这样回显:

s/enterpagerdutyapikey//g

但是当我在服务器中 ssh 并运行相同的 bash 脚本时,它会这样回显:

s/enterpagerdutyapikey/mykey/g

知道为什么$PAGERDUTYAPIKEY当我运行用户数据时环境变量呈现为空吗?

linux bash amazon-web-services amazon-linux-2
  • 1 个回答
  • 607 Views
Martin Hope
Kevin Buchs
Asked: 2021-09-03 14:01:18 +0800 CST

使用 ssh 密钥、用户隔离(sftp 与 ssh)、不同端口和用户目录限制在 Amazon Linux 2 上设置 sftp

  • 3

TDLR:我有一个 Catch 22,根据用户主目录的权限,我可以让 SSH 身份验证正常工作,或者用户目录限制,但不能同时进行。

顺便说一句,我真的很想推出自己的 SFTP 服务器。请不要推荐我尝试 AWS Transfer 服务或其他替代方案。谢谢。

以下是 /etc/ssh/sshd_config 中的相关(从默认更改)内容:

Subsystem sftp internal-sftp
Port 22
Port 2299
Match Group sftpusers LocalPort 2299
  ChrootDirectory /sftp-data/%u
  ForceCommand internal-sftp
Match Group sftpusers LocalPort 22
  DenyGroups sftpusers
Match LocalPort 2299  Group *,!sftpusers
  DenyUsers *

我希望端口 22 像 ssh 通常那样运行,但仅适用于非 sftp 用户。对于 sftp 用户,在“sftpusers”组中,我希望端口 2299 仅用作 sftp,而不是 ssh。对于非 sftpusers,我希望拒绝访问端口 2299。

好的,所以,我用主目录 /sftp-data/user1 和 shell /sbin/nologin 创建了一个用户“user1”。我创建了 /sftp-data/user1/.ssh/authorized_keys 并用公共 ssh 密钥填充了它。/sftp-data 由具有 700 权限的 root 拥有。/sftp-data/user1/.ssh 及以下为 user1 所有,/sftp-data/user1/.ssh/authorized_keys 的权限为 600。 /sftp-data/user1 的所有权/权限在这里受到质疑。更多内容如下。

我创建了用户组 sftpusers 并将 user1 添加到该组。但是,您通过 AWS 获得的内置 ec2-user 不是该组的成员。使用 ec2-user 进行测试效果很好:通过 ssh 访问,端口 22 正常工作,但无法访问端口 2299。

因此,使用 user1 进行测试是有趣的地方。User1 无法访问端口 22 - 太好了!在 user1 拥有 /sftp-data/user1 的情况下,ssh 公钥认证在端口 2299 上成功,但用户立即注销,此消息保存在 /var/log/secure 中:

Sep  2 19:21:38 ip-192-168-0-25 sshd[10369]: Accepted publickey for user1 from <ip-address redacted> port 61110 ssh2: ECDSA SHA256:<sha redacted>
Sep  2 19:13:23 ip-192-168-0-25 sshd[9803]: pam_unix(sshd:session): session opened for user user1 by (uid=0)
Sep  2 19:13:23 ip-192-168-0-25 sshd[9803]: fatal: bad ownership or modes for chroot directory "/sftp-data/user1" [postauth]
Sep  2 19:13:23 ip-192-168-0-25 sshd[9803]: pam_unix(sshd:session): session closed for user user1

当然,这是有道理的。Chroot 要求 /sftp-data/user1 由 root 拥有,权限为 700。所以,这样做,现在 sftp(ssh 密钥)身份验证失败。

Sep  2 19:41:00 ip-192-168-0-25 sshd[11693]: error: AuthorizedKeysCommand /opt/aws/bin/eic_run_authorized_keys user1 SHA256:<sha redacted> failed, status 22

顺便说一句,eic_run_authorized_keys 是 AWS 围绕标准 ssh 身份验证启用 AWS Instance Connect 的包装器。

对于额外的信用......如果上述问题不够具有挑战性,你能想出一个方案,我可以让特定的 sftp 用户访问特定的项目目录,而且只有那些,而不为每个项目创建一个组?从每个用户的主目录链接到项目目录会很棒。

@anx 要求的其他信息:

# getent passwd user1
user1:x:1001:1001::/sftp-data/user1:/sbin/nologin
# namei -l /sftp-data/user1/.ssh/authorized_keys
f: /sftp-data/user1/.ssh/authorized_keys
dr-xr-xr-x root  root      /
drwxr-xr-x root  root      sftp-data
drwx------ root  root      user1
drwx------ user1 sftpusers .ssh
-rw------- user1 sftpusers authorized_keys

我为 sshd 打开了调试日志记录。使用 ChrootDirectory 指令,/sftp-data/user1 由 root 拥有,并且 SSH 身份验证失败,我在 /var/log/secure 中看到了这一点:

debug1:无法打开授权密钥“/sftp-data/user1/.ssh/authorized_keys”:权限被拒绝

ps 清楚地告诉我 root 正在运行 sshd 进程。

amazon-ec2 sftp amazon-linux amazon-linux-2 ssh-keys
  • 2 个回答
  • 1173 Views
Martin Hope
Jonas
Asked: 2021-08-19 13:07:01 +0800 CST

如何从 systemd 在 docker 中启动 etcd?

  • 1

我想从 systemd 在 docker 中启动 etcd(单节点),但似乎出了点问题 - 它在启动后大约 30 秒被终止。

看起来服务以"activating"状态启动,但在大约 30 秒后终止,但未达到"active"状态。也许 docker 容器和 systemd 之间缺少任何信号?

更新(见帖子底部):systemd 服务状态达到failed (Result: timeout)- 当我删除Restart=on-failure指令时。

当我在启动后检查 etcd 服务的状态时,我得到了这个结果:

$ sudo systemctl status etcd● etcd.service - etcd   Loaded: loaded (/etc/systemd/system/etcd.service; enabled; vendor preset: disabled)
   Active: activating (auto-restart) (Result: exit-code) since Wed 2021-08-18 20:13:30 UTC; 4s ago
  Process: 2971 ExecStart=/usr/bin/docker run -p 2380:2380 -p 2379:2379 --volume=etcd-data:/etcd-data --name etcd my-aws-account.dkr.ecr.eu-north-1.amazonaws.com/etcd:v3.5.0 /usr/local/bin/etcd --data-dir=/etcd-data --name etcd0 --advertise-client-urls http://10.0.0.11:2379 --listen-client-urls http://0.0.0.0:2379 --initial-advertise-peer-urls http://10.0.0.11:2380 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster etcd0=http://10.0.0.11:2380 (code=exited, status=125)
 Main PID: 2971 (code=exited, status=125)

我在 Amazon Linux 2 机器上运行它,并在启动时运行用户数据脚本。我已经确认docker.service并docker_ecr_login.service成功运行。

机器启动后不久,我可以看到 etcd 正在运行:

 sudo systemctl status etcd
● etcd.service - etcd
   Loaded: loaded (/etc/systemd/system/etcd.service; enabled; vendor preset: disabled)
   Active: activating (start) since Wed 2021-08-18 20:30:07 UTC; 1min 20s ago
 Main PID: 1573 (docker)
    Tasks: 9
   Memory: 24.3M
   CGroup: /system.slice/etcd.service
           └─1573 /usr/bin/docker run -p 2380:2380 -p 2379:2379 --volume=etcd-data:/etcd-data --name etcd my-aws-account.dkr.ecr.eu-north-1.amazonaws.com...

Aug 18 20:30:17 ip-10-0-0-11.eu-north-1.compute.internal docker[1573]: {"level":"info","ts":"2021-08-18T20:30:17.690Z","logger":"raft","caller":"...rm 2"}
Aug 18 20:30:17 ip-10-0-0-11.eu-north-1.compute.internal docker[1573]: {"level":"info","ts":"2021-08-18T20:30:17.691Z","caller":"etcdserver/serve..."3.5"}
Aug 18 20:30:17 ip-10-0-0-11.eu-north-1.compute.internal docker[1573]: {"level":"info","ts":"2021-08-18T20:30:17.693Z","caller":"membership/clust..."3.5"}
Aug 18 20:30:17 ip-10-0-0-11.eu-north-1.compute.internal docker[1573]: {"level":"info","ts":"2021-08-18T20:30:17.693Z","caller":"etcdserver/server.go:2...
Aug 18 20:30:17 ip-10-0-0-11.eu-north-1.compute.internal docker[1573]: {"level":"info","ts":"2021-08-18T20:30:17.693Z","caller":"api/capability.g..."3.5"}
Aug 18 20:30:17 ip-10-0-0-11.eu-north-1.compute.internal docker[1573]: {"level":"info","ts":"2021-08-18T20:30:17.693Z","caller":"etcdserver/serve..."3.5"}
Aug 18 20:30:17 ip-10-0-0-11.eu-north-1.compute.internal docker[1573]: {"level":"info","ts":"2021-08-18T20:30:17.693Z","caller":"embed/serve.go:9...ests"}
Aug 18 20:30:17 ip-10-0-0-11.eu-north-1.compute.internal docker[1573]: {"level":"info","ts":"2021-08-18T20:30:17.695Z","caller":"etcdmain/main.go...emon"}
Aug 18 20:30:17 ip-10-0-0-11.eu-north-1.compute.internal docker[1573]: {"level":"info","ts":"2021-08-18T20:30:17.695Z","caller":"etcdmain/main.go...emon"}
Aug 18 20:30:17 ip-10-0-0-11.eu-north-1.compute.internal docker[1573]: {"level":"info","ts":"2021-08-18T20:30:17.702Z","caller":"embed/serve.go:1...2379"}
Hint: Some lines were ellipsized, use -l to show in full.

无论 etcd 监听节点 IP (10.0.0.11) 还是 127.0.0.1,我都会得到相同的行为。

我可以在本地运行 etcd,从命令行开始(它不会在 30 秒后终止),使用:

sudo docker run -p 2380:2380 -p 2379:2379 --volume=etcd-data:/etcd-data --name etcd-local \
my-aws-account.dkr.ecr.eu-north-1.amazonaws.com/etcd:v3.5.0 \
/usr/local/bin/etcd --data-dir=/etcd-data \
--name etcd0 \
--advertise-client-urls http://127.0.0.1:2379 \
--listen-client-urls http://0.0.0.0:2379 \
--initial-advertise-peer-urls http://127.0.0.1:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-cluster etcd0=http://127.0.0.1:2380

etcd 的参数类似于运行单节点 etcd-ectd 3.5 文档。

这是用于启动 etcd 的启动脚本的相关部分:

sudo docker volume create --name etcd-data

cat <<EOF | sudo tee /etc/systemd/system/etcd.service
[Unit]
Description=etcd
After=docker_ecr_login.service

[Service]
Type=notify
ExecStart=/usr/bin/docker run -p 2380:2380 -p 2379:2379 --volume=etcd-data:/etcd-data \
 --name etcd my-aws-account.dkr.ecr.eu-north-1.amazonaws.com/etcd:v3.5.0 \
 /usr/local/bin/etcd --data-dir=/etcd-data \
 --name etcd0 \
 --advertise-client-urls http://10.0.0.11:2379 \
 --listen-client-urls http://0.0.0.0:2379 \
 --initial-advertise-peer-urls http://10.0.0.11:2380 \
 --listen-peer-urls http://0.0.0.0:2380 \
 --initial-cluster etcd0=http://10.0.0.11:2380
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable etcd
sudo systemctl start etcd

列出机器上的所有容器时,我可以看到它一直在运行:

sudo docker ps -a
CONTAINER ID   IMAGE                                                       COMMAND                  CREATED          STATUS                      PORTS                          NAMES
a744aed0beb1   my-aws-account.dkr.ecr.eu-north-1.amazonaws.com/etcd:v3.5.0   "/usr/local/bin/etcd…"   25 minutes ago   Exited (0) 24 minutes ago                          etcd

但我怀疑它无法重新启动,因为容器名称已经存在。

从 systemd 启动时,为什么 etcd 容器会在大约 30 秒后终止?看起来它成功启动了,但 systemd 只显示它处于“激活”状态,但从未处于“激活”状态,并且它似乎在大约 30 秒后终止。从 etcd docker 容器到 systemd 是否缺少一些信号?如果是这样,我怎样才能让那个信号正确?


更新:

删除Restart=on-failure服务单元文件中的指令后,我现在得到 status: failed (Result: timeout):

$ sudo systemctl status etcd
● etcd.service - etcd
   Loaded: loaded (/etc/systemd/system/etcd.service; enabled; vendor preset: disabled)
   Active: failed (Result: timeout) since Wed 2021-08-18 21:35:54 UTC; 5min ago
  Process: 1567 ExecStart=/usr/bin/docker run -p 2380:2380 -p 2379:2379 --volume=etcd-data:/etcd-data --name etcd my-aws-account.dkr.ecr.eu-north-1.amazonaws.com/etcd:v3.5.0 /usr/local/bin/etcd --data-dir=/etcd-data --name etcd0 --advertise-client-urls http://127.0.0.1:2379 --listen-client-urls http://0.0.0.0:2379 --initial-advertise-peer-urls http://127.0.0.1:2380 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster etcd0=http://127.0.0.1:2380 (code=exited, status=0/SUCCESS)
 Main PID: 1567 (code=exited, status=0/SUCCESS)

Aug 18 21:35:54 ip-10-0-0-11.eu-north-1.compute.internal docker[1567]: {"level":"info","ts":"2021-08-18T21:35:54.332Z","caller":"osutil/interrupt...ated"}
Aug 18 21:35:54 ip-10-0-0-11.eu-north-1.compute.internal docker[1567]: {"level":"info","ts":"2021-08-18T21:35:54.333Z","caller":"embed/etcd.go:36...379"]}
Aug 18 21:35:54 ip-10-0-0-11.eu-north-1.compute.internal docker[1567]: WARNING: 2021/08/18 21:35:54 [core] grpc: addrConn.createTransport failed ...ing...
Aug 18 21:35:54 ip-10-0-0-11.eu-north-1.compute.internal docker[1567]: {"level":"info","ts":"2021-08-18T21:35:54.335Z","caller":"etcdserver/serve...6a6c"}
Aug 18 21:35:54 ip-10-0-0-11.eu-north-1.compute.internal docker[1567]: {"level":"info","ts":"2021-08-18T21:35:54.337Z","caller":"embed/etcd.go:56...2380"}
Aug 18 21:35:54 ip-10-0-0-11.eu-north-1.compute.internal docker[1567]: {"level":"info","ts":"2021-08-18T21:35:54.338Z","caller":"embed/etcd.go:56...2380"}
Aug 18 21:35:54 ip-10-0-0-11.eu-north-1.compute.internal docker[1567]: {"level":"info","ts":"2021-08-18T21:35:54.339Z","caller":"embed/etcd.go:36...379"]}
Aug 18 21:35:54 ip-10-0-0-11.eu-north-1.compute.internal systemd[1]: Failed to start etcd.
Aug 18 21:35:54 ip-10-0-0-11.eu-north-1.compute.internal systemd[1]: Unit etcd.service entered failed state.
Aug 18 21:35:54 ip-10-0-0-11.eu-north-1.compute.internal systemd[1]: etcd.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
linux docker systemd amazon-linux-2 etcd
  • 1 个回答
  • 694 Views
Martin Hope
Jonas
Asked: 2021-08-08 15:38:22 +0800 CST

yum install 后如何将 containerd 作为服务启动?

  • 2

我使用建议的命令在 Amazon Linux 2 上安装了containerd:

sudo amazon-linux-extras enable docker
sudo yum install -y containerd

我在EC2 用户数据脚本中添加了它以在实例启动时运行。

但是,我应该如何将containerd(容器运行时 - 类似于 docker)作为服务启动?由于我通过yum那里安装似乎不包含systemd 服务文件。二进制文件位于/usr/bin/containerd. 我应该echo在引导脚本中使用来生成systemd 服务文件还是一个好的做法?

linux amazon-ec2 systemd containerd amazon-linux-2
  • 1 个回答
  • 1548 Views
Martin Hope
Pablo Pantaleon
Asked: 2021-04-07 15:54:42 +0800 CST

Amazon Linux 2 - EC2 PostgreSQL

  • 0

我有以下内容:

  • 亚马逊 Linux 2
  • Postgres 12 安装了一个用户创建的

我正在使用 ssh 连接到我的实例。

问题是它不允许我连接到我的 postgres 数据库。我已经使用类似的东西创建了一个用户:

create user myuser with encrypted password 'strongpassword';

并且 postgres 服务器运行正常,但是当我尝试连接到我的数据库时,它会抛出:

$: psql -h localhost --port 5432 --password -U myuser -d mydb    

psql: error: FATAL:  Ident authentication failed for user "myuser"

我不知道为什么它无法识别我的用户。

提前致谢


更新

在此处输入图像描述

amazon-ec2 postgresql amazon-linux-2
  • 1 个回答
  • 397 Views
Martin Hope
Graham Lea
Asked: 2020-11-26 21:54:05 +0800 CST

Fail2Ban iptables 条目拒绝 HTTPS 不停止对 Amazon Linux 2 上的 Docker 容器的请求

  • 0

nginx-http-auth我已经在 Amazon Linux 2 上设置了 Fail2Ban,使用此覆盖配置启用内置监狱:

[nginx-http-auth]
enabled = true
action = iptables[name=HTTPS, port=https, protocol=tcp]
logpath = <snip>/logs/*error*.log
findtime = 15m
bantime = 15m
maxretry = 5

动作正在触发,我得到以下条目iptables -S:

-A f2b-HTTPS -s 120.<snip>.122/32 -j REJECT --reject-with icmp-port-unreachable

但是,我可以继续从被禁止的 IP 发出新的 HTTPS 请求,这些 IP 正在接收来自 Nginx 的 401 响应。我已经从两个 IP 地址复制 - 我的手机和另一个 EC2 主机。

这是完整的输出iptables -L:(注意:Nginx 在 Docker 中运行,另外两个与本地网络隔离的容器也是如此)

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
f2b-HTTPS  tcp  --  anywhere             anywhere             tcp dpt:https

Chain FORWARD (policy DROP)
target     prot opt source               destination
DOCKER-USER  all  --  anywhere             anywhere
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain DOCKER (2 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             ip-192-168-208-2.ap-southeast-2.compute.internal  tcp dpt:webcache

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere
DROP       all  -- !ip-192-168-192-0.ap-southeast-2.compute.internal/20  anywhere
DROP       all  --  anywhere            !ip-192-168-192-0.ap-southeast-2.compute.internal/20
DROP       all  -- !ip-192-168-176-0.ap-southeast-2.compute.internal/20  anywhere
DROP       all  --  anywhere            !ip-192-168-176-0.ap-southeast-2.compute.internal/20
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

Chain DOCKER-ISOLATION-STAGE-2 (2 references)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

Chain DOCKER-USER (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

Chain f2b-HTTPS (1 references)
target     prot opt source               destination
REJECT     all  --  120.<snip>.122       anywhere             reject-with icmp-port-unreachable
RETURN     all  --  anywhere             anywhere

为什么 iptable 规则不停止 HTTPS 请求?

我是否需要以某种方式更改我的 fail2ban 配置以使其正常工作?

iptables https docker fail2ban amazon-linux-2
  • 1 个回答
  • 1283 Views
Martin Hope
vfrans
Asked: 2020-08-27 03:13:18 +0800 CST

使用 EC2 imagebuilder 从 s3 填充 authorized_keys 不起作用

  • 0

我正在努力设置 imagebuilder 以从 Amazon Linux 2 实例上的 S3 文件填充 authorized_keys 文件。

IAM 角色功能正常,管道运行良好(没有错误,也没有输出)

这是我正在使用的食谱

description: This is hello world testing document.
schemaVersion: 1.0
phases:
  - name: build
    steps:
      - name: Download_Authorized_Keys_File
        action: S3Download
        onFailure: Abort
        inputs:
          - source: 's3://mysuperbucket/authorized_keys'
            destination: '/home/ec2-user/.ssh/authorized_keys'
      - name: Ensure_Correct_File_Permission
        action: ExecuteBash
        onFailure: Abort
        inputs:
          commands:
            - 'chown ec2-user:ec2-user /home/ec2-user/.ssh/authorized_keys'
            - 'chmod 600 /home/ec2-user/.ssh/authorized_keys'

此外,在其他地方调查和复制该文件时,它运行良好并且文件存在。

当手动将该文件复制到目标时,它也可以工作。有没有人有任何线索?

amazon-web-services amazon-linux-2
  • 1 个回答
  • 218 Views
Martin Hope
philolegein
Asked: 2020-07-16 08:34:01 +0800 CST

systemd/系统覆盖应该如何工作?

  • 3

我在搞乱一些超时设置,并试图找出为 systemd/system 守护进程设置东西的正确方法。具体来说,这是一个动力不足的服务器,我在启动 clamd 时一直超时,所以我试图找出设置 TimeoutStartSec 参数需要多高。我试过了

systemctl edit --full clamd@.service

并编辑它说

TimeoutStartSec=20min

然后做了systemctl daemon-reload

但它在 7 分钟后一直神秘地超时。最终,我发现/usr/lib/systemd/system/clamd@.service有TimeoutStartSec=420.

可能反对所有正确的做事方式,我编辑了/usr/lib文件的版本,并注释掉了该行。果然,这改变了事情,但它似乎仍然没有阅读/etc/systemd版本。一旦我将其注释掉,它会在 90 秒后开始超时,我想这一定是默认设置。

作为临时解决方法,我已将/usr/lib版本编辑为我想要的 20 分钟,但是……这似乎不是正确的做事方式。

systemctl edit应该是在编辑版本吗/etc/systemd/system?这是假定正确的做事方式吗?我必须做更多的事情systemctl daemon-reload吗?

接受有关“正确方法”的任何和所有建议。

TIA

clamav systemd amazon-linux-2
  • 1 个回答
  • 844 Views
Martin Hope
Rich
Asked: 2020-06-13 09:04:38 +0800 CST

如何在 Amazon Linux 2 上安装 certbot

  • 0

我有一个运行 Amazon Linux 第 2 版 (Karoo) 的 EC2 虚拟机 我怎样才能获得certbot?

它附带awscli安装的工具,这些工具似乎与certbotin epel 不兼容:

$ sudo bash
# yum install -y epel-release
# yum-config-manager --enable epel
# yum install certbot certbot-dns-route53
# certbot certonly --dns-route53 --dns-route53-propagation-seconds 30 -d mysite.com
An unexpected error occurred:
ContextualVersionConflict: (botocore 1.13.36 (/usr/lib/python2.7/site-packages), Requirement.parse('botocore<1.6.0,>=1.5.0'), set(['boto3']))
Please see the logfile '/tmp/tmpVO1RPd/log' for more details.

此处简要讨论:https ://community.letsencrypt.org/t/contextualversionconflict-botocore-1-12-92/94922和此处:https ://unix.stackexchange.com/questions/415874/certbot-and- awscli-require-different-versions-of-botocore/456362#456362但这些修复对我不起作用(我想同时拥有 awscli)。

所以我尝试将它安装在 Python venv 中,这样我就可以拥有 certbot 和 awscli,但我得到了这个:

$ sudo bash
# yum install pip
# pip install virtualenv
# virtualenv env
# source env/bin/activate
# pip install certbot certbot-dns-route53
# certbot certonly --dns-route53 --dns-route53-propagation-seconds 30 -d mysite.com
Traceback (most recent call last):
  File "/home/ec2-user/certbot-venv/env/bin/certbot", line 5, in <module>
    from certbot.main import main
  File "/home/ec2-user/certbot-venv/env/lib/python2.7/site-packages/certbot/main.py", line 2, in <module>
    from certbot._internal import main as internal_main
  File "/home/ec2-user/certbot-venv/env/lib/python2.7/site-packages/certbot/_internal/main.py", line 21, in <module>
    from certbot._internal import cert_manager
  File "/home/ec2-user/certbot-venv/env/lib/python2.7/site-packages/certbot/_internal/cert_manager.py", line 16, in <module>
    from certbot._internal import storage
  File "/home/ec2-user/certbot-venv/env/lib/python2.7/site-packages/certbot/_internal/storage.py", line 79, in <module>
    def add_time_interval(base_time, interval, textparser=parsedatetime.Calendar()):
  File "/home/ec2-user/certbot-venv/env/lib/python2.7/site-packages/parsedatetime/__init__.py", line 270, in __init__
    self.ptc = Constants()
  File "/home/ec2-user/certbot-venv/env/lib/python2.7/site-packages/parsedatetime/__init__.py", line 2381, in __init__
    self.locale = get_icu(self.localeID)
  File "/home/ec2-user/certbot-venv/env/lib/python2.7/site-packages/parsedatetime/pdt_locales/icu.py", line 56, in get_icu
    result['icu'] = icu = pyicu.Locale(locale)
AttributeError: 'module' object has no attribute 'Locale'

有谁知道如何解决?我尝试安装一些与语言环境相关的不同东西,但还没有运气。

amazon-ec2 pip certbot amazon-linux-2
  • 2 个回答
  • 1940 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