Zero's Blog - RHEL
https://l2dy.sourceforge.io/tag/RHEL/
-
Nginx proxy_pass 502 Bad Gateway
https://l2dy.sourceforge.io/2022/08/20/nginx-selinux-connect.html
2022-08-20T03:22:00+00:00
Rocky Linux 8 上安装 nginx 后对 nginx.conf 进行修改增加了一个 proxy_pass 配置,但用浏览器访问时提示 502 Bad Gateway,也就是连接不上后端服务。照例先怀疑一下 SELinux。# getsebool httpd_can_network_connect
httpd_can_network_connect --> off检查 SELinux 配置发现没有给 HTTP 服务主动发起 TCP 连接的权限,用 setsebool 调整后就正常了。setsebool -P httpd_can_network_connect on
-
DigitalOcean Rocky Linux 8 默认镜像释放内存
https://l2dy.sourceforge.io/2022/07/01/digitalocean-rocky-low-mem.html
2022-07-01T17:14:00+00:00
DigitalOcean 新推出了一款只有 512 MB 内存的 droplet,然而跑个 dnf upgrade 都能触发 Out of memory: Killed process 10365 (semodule)。用 ps avxf 可以查看进程的内存占用(RSS)。在搜索资料后我发现以下服务可以优化掉,不过要避免 out of memory 还是建议配置 swap,或者换个包管理器更轻量的发行版,例如 Debian。droplet-agent即 The DigitalOcean Droplet Agent,可通过 systemctl 关闭,或用 dnf 完全卸载。dnf remove droplet-agentsssd参考 https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/configuring_authentication_and_authorization_in_rhel/index 使用以下命令可切换到最小化认证并关闭 sssd 服务。authselect select minimal
systemctl stop sssd.service
systemctl disable sssd.servicetuned参考 https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/monitoring_and_managing_system_status_and_performance/getting-started-with-tuned_monitoring-and-managing-system-status-and-performance 修改 /etc/tuned/tuned-main.conf 配置即可。daemon = 0gssproxy不需要 Kerberos 的话直接卸载也不会有什么问题。 https://github.com/gssapi/gssproxy/blob/main/docs/README.mddnf remove gssproxydnf-makecachednf 缓存会定期自动更新,为了保证稳定的内存占用需要禁用掉 dnf-makecache.timer.systemctl stop dnf-makecache.timer
systemctl disable dnf-makecache.timer最终效果# free -h
total used free shared buff/cache available
Mem: 460Mi 103Mi 227Mi 6.0Mi 130Mi 339Mi
Swap: 0B 0B 0B
-
从 EPEL 安装 strongSwan 配置 IPv6-only VPN
https://l2dy.sourceforge.io/2022/06/04/strongswan-ipv6-only.html
2022-06-04T16:07:00+00:00
首先由于 IPv6 VPN 服务器会转发 IPv6 包,需要用 sysctl 开启内核的 IPv6 转发。将以下内容配置到 /etc/sysctl.d 目录下一个 .conf 文件中,并用 sysctl -p xxx.conf 加载或重启服务器。net.ipv6.conf.all.forwarding = 1然后我们来安装 strongSwan。 dnf install epel-release 安装上 EPEL 源,然后 dnf install strongswan 就 OK 了。strongSwan 现已支持 swanctl.conf 新格式的配置文件,文件路径在 /etc/strongswan/swanctl/swanctl.conf,密钥放在 /etc/strongswan/swanctl 对应目录下。下面给出一个示例配置,配置完成后可以通过 systemctl start strongswan.service 启动。connections {
ikev2-vpn {
version=2
remote_addrs=%any
local_addrs=%any
send_cert=always
pools=pool-subnet-ipv6
dpd_delay=300s
children {
ikev2-vpn {
local_ts=::/0
dpd_action=clear
}
}
local-0 {
certs = cert.pem
id = @<domain>
}
remote-0 {
auth = eap-mschapv2
id = %any
}
}
}
pools {
pool-subnet-ipv6 {
addrs=xxx:8/125
dns=2001:4860:4860::8888,2001:4860:4860::8844
}
}
secrets {
eap-user1 {
id=user1
secret="password"
}
}
authorities {
}P.S. 带有中间证书的证书文件需要拆分,strongSwan 只会读取证书文件里的第一个 PEM 证书。
-
Nginx 访问本地文件 403
https://l2dy.sourceforge.io/2022/06/03/nginx-selinux.html
2022-06-03T09:23:00+00:00
Rocky Linux 8 上安装 nginx 后对 nginx.conf 进行修改增加了一个 /var/www 路径的 root 配置,但用 curl 测试访问一个文件时却返回了 403 Forbidden。2022/06/03 <masked> [error] <pid>#0: *1 open() "/var/www/.well-known/test" failed (13: Permission denied), client: <masked>, server: _, request: "GET /.well-known/test HTTP/1.1", host: "localhost"用 namei 命令查看一下权限,没有发现问题。# namei -om /var/www/.well-known/test
f: /var/www/.well-known/test
dr-xr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root www
drwxr-xr-x root root .well-known
-rw-r--r-- root root test网上查阅资料发现可能是 SELinux 问题,故执行 setenforce 0 后再次测试,此时可以访问了。但关闭 SELinux 并不是最合理的方案,进一步查找资料发现 https://www.nginx.com/blog/using-nginx-plus-with-selinux/ 这篇文章,文中介绍了 SELinux 对文件上下文的永久变更是通过 semanage fcontext 控制的,让我们来看一下目前系统的配置。# semanage fcontext -l | grep httpd_sys_content_t
<trimmed>
/var/lib/trac(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
/var/www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
/var/www/icons(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
/var/www/svn/conf(/.*)? all files system_u:object_r:httpd_sys_content_t:s0
# ls -Z /var/www/.well-known/test
unconfined_u:object_r:var_t:s0 /var/www/.well-known/test可以发现 /var/www 目录下任意路径已经在 httpd_sys_content_t 的 file\_spec 中了但没有应用到文件上,所以直接用 restorecon 命令恢复文件和文件夹默认的安全上下文就行。restorecon -Rv /var/www/.well-known