Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Oracle HTTP Server (OHS) 修改監聽埠為 80 (權限提升 .apachectl setuid root)

編輯:關於伺服器

Oracle HTTP Server (OHS) 基於 Apache,預設以 Oracle 使用者運行,Linux 安全機制限制非 root 進程無法綁定 **< 1024 埠** (如 80、443)。解決方案:將 .apachectl 控制腳本擁有者改為 root 並設定 **setuid/setgid 位元**,使啟動過程暫時提權綁定低埠號。

前置條件

  • MW_HOME:/u00/app/oracle/product/fmw-11.1.1 (依實際安裝路徑調整)
  • Instance 名稱:instance1
  • OHS 元件名稱:ohs1
  • 需 root 權限執行權限變更步驟

操作步驟

1. 停止 OHS

export MW_HOME=/u00/app/oracle/product/fmw-11.1.1
cd $MW_HOME/Oracle_WT1/instances/instance1/bin
./opmnctl stopall

2. 修改 httpd.conf 監聽埠為 80

cd $MW_HOME/Oracle_WT1/instances/instance1/config/OHS/ohs1
cp httpd.conf httpd.conf.bak
# 編輯 httpd.conf,找到 Listen 指令
Listen 80
# 存檔

3. 變更 .apachectl 權限 (關鍵步驟)

# 切換至 root 用戶
cd $MW_HOME/Oracle_WT1/ohs/bin
ls -la .apachectl
# 輸出範例:-rwxr-x--- 1 oracle oinstall 13278 Dec 17 03:54 .apachectl

chown root .apachectl
chmod 6750 .apachectl
# 6750 = setuid(4) + setgid(2) + owner(rwx=7) + group(r-x=5) + other(---=0)

ls -la .apachectl
# 預期輸出:-rwsr-s--- 1 root oinstall 13278 Dec 17 03:54 .apachectl
# s 位元表示 setuid/setgid 生效

注意:.apachectl 為隱藏檔 (以點開頭),ls -la 才能看見。

4. 重啟 OHS 驗證

cd $MW_HOME/Oracle_WT1/instances/instance1/bin
./opmnctl startall
./opmnctl status -l
# 輸出應顯示 OHS 進程運行於埠 80

原理說明

  • Linux 核心限制:非 CAP_NET_BIND_SERVICE 能力的進程無法 bind() < 1024 埠。
  • chmod 4750 (或 6750) 使 .apachectl 執行時 **有效 UID/GID 變為檔案擁有者 (root/oracle)**,暫時擁有 root 權限綁定埠 80。
  • Apache 啟動後會 setuid(oracle) 降權回 Oracle 用戶運行 Worker 進程,僅 Master 進程短暫以 root 身分綁定埠口,符合最小權限原則。

替代方案 (不修改 .apachectl)

驗證清單

  1. netstat -an | grep :80 顯示 LISTEN。
  2. curl -I https://localhost/ 回傳 HTTP/1.1 200 OK。
  3. ps -ef | grep httpd Master 進程 USER=root,Worker 進程 USER=oracle。

完成上述步驟,OHS 即可合法監聽埠 80,滿足客戶「無埠號網址」需求,同時維持進程降權運行的安全基線。

Copyright © Windows教程網 All Rights Reserved
方案操作優/缺點
Authbindapt/yum install authbind → touch /etc/authbind/byport/80 → chmod 755 /etc/authbind/byport/80 → 啟動腳本加 authbind --deep無需 setuid root,較安全;需額外安裝套件
setcapsetcap 'cap_net_bind_service=+ep' /path/to/httpd僅賦予綁定低埠能力,不給完整 root;需 filesystem 支援 xattr
iptables 轉發iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 7777OHS 仍聽 7777,核心層轉發;增加 NAT 開銷、複雜度
Systemd AmbientCapabilities服務單元加 AmbientCapabilities=CAP_NET_BIND_SERVICE現代 systemd 原生做法,乾淨無 setuid;需 systemd 管理 OHS