在CentOS上配置GitLab以發送郵件通知,您需要完成以下步驟:
首先,確保您的CentOS系統已安裝了Postfix。如果沒有,請運行以下命令來安裝它:
sudo yum install postfix
編輯Postfix的主配置文件/etc/postfix/main.cf
,添加或修改以下內容:
myhostname = gitlab.example.com # 將此值更改為您的GitLab實例的主機名
inet_interfaces = all
inet_protocols = ipv4
myorigin = $myhostname
inet_addr = 127.0.0.1
mydestination = $myhostname, localhost.$mydomain, $mydomain
mynetworks = 127.0.0.0/8, ::1/128
home_mailbox = Maildir/
將gitlab.example.com
替換為您的GitLab實例的主機名,并根據需要調整其他設置。
保存并關閉文件后,重新啟動Postfix服務以應用更改:
sudo systemctl restart postfix
打開GitLab的配置文件/etc/gitlab/gitlab.rb
,找到或添加以下部分:
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.example.com" # 將此值更改為您的SMTP服務器地址
gitlab_rails['smtp_port'] = 587 # 將此值更改為您的SMTP服務器端口
gitlab_rails['smtp_user_name'] = "your-smtp-user@example.com" # 將此值更改為您的SMTP用戶名
gitlab_rails['smtp_password'] = "your-smtp-password" # 將此值更改為您的SMTP密碼
gitlab_rails['smtp_domain'] = "example.com" # 將此值更改為您的域名
gitlab_rails['smtp_authentication'] = "login" # 或者使用 "cram_md5", "plain", "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
根據您的SMTP服務器信息填寫相應的值。保存并關閉文件。
運行以下命令以重新配置并重啟GitLab,使更改生效:
sudo gitlab-ctl reconfigure
現在,GitLab應該已經配置好郵件通知功能。如果您遇到任何問題,請檢查GitLab和Postfix的日志以獲取有關錯誤的詳細信息。