在 Ubuntu 24.04 下安裝 OpenKM Community Edition
1. 建立用戶 openkm:
sudo adduser openkm
sudo usermod -aG sudo openkm
2. 登出並登入 openkm
***** 以下操作是在 openkm 用戶下進行 *****
3. 更新 APT 庫記錄
sudo apt-get update
4. 安裝 Apache HTTP 伺服器, Maridb 伺服器和 OpenJava
sudo apt install apache2 mariadb-server openjdk-8-jdk -y
5. 配置 Maridb 伺服器
sudo mysql_secure_installation
6. 下載 OpenKM 的 Installer 檔案 OKMInstaller.jar
https://www.openkm.com/en/download.html
7. 執行 OpenKM Installer
sudo java -jar OKMInstaller.jar
***** 以下操作假設除了 database 設定為 mariadb 和密碼為自定義外, 其他為預設值 *****
安裝過程中, 它會自動下載需要的 DEB 檔案
此外, 安裝程序會在 /etc/init.d 之下建立了 openkm 的檔案來啟動/停止/重啟 OpenKM
所以, 我們可以使用指令來:
啟動 OpenKM 伺服器:
sudo service openkm start
停止 OpenKM 伺服器:
sudo service openkm stop
重啟 OpenKM 伺服器:
sudo service openkm restart
8. 根據安裝指示, 登入 Mariadb (指令: mysql -u root -p), 輸入有關的 SQL 指令來建立數據庫
9. 由於 GitLab 會用 8080, 8181 埠, 所以我們先改動 OpenKM 的 Tomcat Connector Port 設定, 不用 8080 埠
參考 https://docs.openkm.com/kcenter/view/okm-6.3-com/configuring-tomcat-port.html 的說明, 修改 tomcat/conf 下的 server.xml 檔案:
nano ./tomcat/conf/server.xml
10. 如果啟動了 Firewall, 我們需要將用到的 Tomcat Connector Port 加入 firewall 列表:
sudo ufw allow <Tomcat Connector Port number>
11. 初次啟動 OpenKM 伺服器
sudo systemctl daemon-reload
sudo service openkm start
12: 測試登入 OpenKM
啟動 Firefox, 輸入 http://localhost:<Tomcat Connector Port number>/
例如: http://localhost:8280/
正常情況下會看到登入畫面, 然後輸入預設用戶:
login: okmAdmin
password: admin
如果可以登入就証明 OpenKM 已經可用了. 之後系統會在啟動時自動啟動 OpenKM 服務
在 Ubuntu 24.04 下安裝 GitLab Community Edition
參考: https://docs.gitlab.com/install/package/ubuntu/
1. 安裝和啟動 OpenSSH 伺服器
sudo apt update
sudo apt install openssh-server -y
sudo ufw allow OpenSSH
sudo systemctl enable --now ssh
2. 設定及啟動 Firewall
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
3. 安裝 Curl
sudo apt install -y curl
4. 將 Gitlab Community Edition (即 Gitlab CE) 加到 apt 庳
curl "https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh" | sudo bash
5. 下載及安裝 GitLab CE
sudo apt install gitlab-ce
註: 我們不設定 EXTERNAL_URL 是因為我們不想安裝程序 "立刻" 設定 GitLab (因為安裝會自動設定 LetsEncrypt, 如果無法設定 LetsEncrypt, 安裝將會失敗)
***** 注意 *****
以下流程是基於以下假設:
1. 只供內部網絡用
2. 內部網絡沒有 DNS, 只使用 IP 地址來連接伺服器
3. 只用 HTTP (一般情況下, 除非客戶端程序 (例如:瀏覽器) 必需使用 HTTPS, 否則在內部網絡用 "自簽" 証書的 HTTPS 是 (基本上) 沒什麼意義)
****************
參考: https://docs.gitlab.com/omnibus/settings/nginx/#use-a-non-bundled-web-server
6. 修改 GitLab 設定檔案:
sudo nano /etc/gitlab/gitlab.rb
6.1 由於只供內部網絡用和沒有 domain name, 所以停用 Let's Encrypt:
letsencrypt['enable'] = false
6.2 由於使用 Ubuntu 內的 Apache 伺服器, 所以停止 GitLab 內部的 Nginx 伺服器
nginx['enable'] = false
6.3 設定與 Apache 有關的設定
web_server['external_users'] = ['www-data']
gitlab_workhorse['listen_network'] = "tcp"
gitlab_workhorse['listen_addr'] = "127.0.0.1:8181"
7. 執行設定:
sudo gitlab-ctl reconfigure
8. 將 www-data 加入 gitlab-www 組:
sudo usermod -aG gitlab-www www-data
9. 在以下 URL 下載 Apache config 檔案:
https://gitlab.com/gitlab-org/gitlab-recipes/-/tree/master/web-server/apache?ref_type=heads
由於 Ubuntu 24.02 是安裝 2.4 版本, 所以檔案是 gitlab-omnibus-apache24.conf
10. 修改 gitlab-omnibus-apache24.conf
nano gitlab-omnibus-apache24.conf
10.1 修正檔案路徑
停用所有 "For CentOS" 部份, 即加上 # 字, 使用 "For Debian distribution" 部份, 即刪除 # 字
註: 你可以將路徑中的 YOUR_SERVER_FQDN 改為其他容易明白的名稱, 例如: gitlab_server
10.2 設定 IP Based Virtual Hosting
10.2.1 將 Server Name 設定為伺服器 IP 地址. 例如: 如果伺服器 IP 地址是 192.168.56.101 那麼設定為 ServerName 192.168.56.101
10.2.2 將 ProxyPassReverse 的 http://YOUR_SERVER_FQDN/ 改為 http://"伺服器 IP 地址"/ 例如: 如果伺服器 IP 地址是 192.168.56.101 那麼設定為 ProxyPassReverse http://192.168.56.101/
10.2.3 如果電腦是有多網卡並要同時支持不同網絡, 那麼可以增加 ServerAlias 設定. 例如電腦有 2 個 IP: 192.168.56.101 和 192.168.2.151, 那麼增加 ServerAlias 192.168.2.151
以下是一個修改後的例子:
<VirtualHost *:80>
ServerName 192.168.56.101
# Assume the following ip address is assigned for another network interface
ServerAlias 192.168.2.151
ServerSignature Off
ProxyPreserveHost On
# Ensure that encoded slashes are not decoded but left in their encoded state.
# http://doc.gitlab.com/ce/api/projects.html#get-single-project
AllowEncodedSlashes NoDecode
<Location />
# New authorization commands for apache 2.4 and up
# http://httpd.apache.org/docs/2.4/upgrading.html#access
Require all granted
#Allow forwarding to gitlab-workhorse
ProxyPassReverse http://127.0.0.1:8181
ProxyPassReverse http://192.168.56.101/
</Location>
# Apache equivalent of nginx try files
# http://serverfault.com/questions/290784/what-is-apaches-equivalent-of-nginxs-try-files
# http://stackoverflow.com/questions/10954516/apache2-proxypass-for-rails-app-gitlab
RewriteEngine on
# Enable WebSocket reverse Proxy
# Needs proxy_wstunnel enabled
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/?(.*) "ws://127.0.0.1:8181/$1" [P,L]
#Forward all requests to gitlab-workhorse except existing files like error documents
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} ^/uploads/.*
RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]
# needed for downloading attachments
DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public
#Set up apache error documents, if back end goes down (i.e. 503 error) then a maintenance/deploy page is thrown up.
ErrorDocument 404 /404.html
ErrorDocument 422 /422.html
ErrorDocument 500 /500.html
ErrorDocument 502 /502.html
ErrorDocument 503 /503.html
# Debian and CentOS distribution defaults provided below
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
#For CentOS distributions use
#ErrorLog /var/log/httpd/logs/YOUR_SERVER_FQDN_error.log
#CustomLog /var/log/httpd/logs/YOUR_SERVER_FQDN_forwarded.log common_forwarded
#CustomLog /var/log/httpd/logs/YOUR_SERVER_FQDN_access.log combined env=!dontlog
#CustomLog /var/log/httpd/logs/YOUR_SERVER_FQDN.log combined
#For Debian distributions use
ErrorLog /var/log/apache2/gitlab_server_error.log
CustomLog /var/log/apache2/gitlib_server_forwarded.log common_forwarded
CustomLog /var/log/apache2/gitlab_server_access.log combined env=!dontlog
CustomLog /var/log/apache2/gitlab_server.log combined
</VirtualHost>
11. 將 conf 檔案複製到 apache 設定資料夾:
sudo cp gitlab-omnibus-apache24.conf /etc/apache2/sites-available/
12. 啟動設定
sudo a2ensite gitlab-omnibus-apache24
13. 啟動以下 Apache 模組
sudo a2enmod proxy proxy_http rewrite
14. 重啟 apache 伺服器
sudo systemctl reload apache2
15. 用 Firefox 測試是否可以顯示 GitLab 登入畫面
http://"伺服器 IP 地址"/ 例如: http://192.168.56.101/
16. 第一次登入 GitLab
參考: https://docs.gitlab.com/install/next_steps/#initial-sign-in
登入用戶: root
密碼: 在 /etc/gitlab/initial_root_password 內 (安裝 24 小時後會被自動刪除)
如果可以成功登入, 那 GitLab 是可以用了. (記得修改 root 密碼)