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
]]>dnf upgrade
都能触发 Out of memory: Killed process 10365 (semodule)
。用 ps avxf
可以查看进程的内存占用(RSS)。在搜索资料后我发现以下服务可以优化掉,不过要避免 out of memory 还是建议配置 swap,或者换个包管理器更轻量的发行版,例如 Debian。
即 The DigitalOcean Droplet Agent,可通过 systemctl 关闭,或用 dnf 完全卸载。
dnf remove droplet-agent
参考 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.service
参考 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 = 0
不需要 Kerberos 的话直接卸载也不会有什么问题。 https://github.com/gssapi/gssproxy/blob/main/docs/README.md
dnf remove gssproxy
dnf 缓存会定期自动更新,为了保证稳定的内存占用需要禁用掉 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
]]>/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.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
]]>