2026年2月1日星期日

在 Ubuntu 24.02 安裝 OpenKM 和 GitLab Community Edition

 在 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 指令來建立數據庫

註:

8.1. 為了完全支持 UTF8 編碼, 最好將 SQL 指令中的 utf8 改為 utf8mb4, utf8_bin 改為 utf8mb4_bin

例如: CREATE DATABASE okmdb DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin; 改為 CREATE DATABASE okmdb DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;


8.2. 如果打算透過 ZIP 檔案來批量上載檔案, 在建立 ZIP 檔案時, 將 Parameter 部份增加 cu+ 參數

 (參考: https://forum.openkm.com/viewtopic.php?t=20585&start=15)


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 密碼)

2024年3月4日星期一

Decimal to/from Octal by Qt QString

 quint32 oct_value = 20;

QString str_oct;


// from oct to dec

str_oct.setNum(oct_value);

quint32 dec_value = str_oct.toUInt(nullptr, 8);


// from dec to oct

str_oct.setNum(dec_value, 8);

oct_value = str_oct.toUInt();


2021年2月3日星期三

Directory Selection Menu Example for Linux (Bash Shell Script)

 #!/bin/bash

selectdir() {

# get directory list and convert it to an array

dir_list=($(ls -d $1/* | awk '{ print $1 }'))


selection=$(whiptail --title "Folder Selection" --menu "Select a folder:" 14 40 6 \

            `for index in ${!dir_list[*]}; do printf "%d %s " $index ${dir_list[$index]}; done` \

            3>&1 1>&2 2>&3)


exitstatus=$?

if [ $exitstatus -eq 0 ]; then

    echo ${dir_list[$selection]}

fi

}

path=$(selectdir $PWD)

echo "selected path = "$path


2018年4月11日星期三

iBus, iBus Pinyin and BLFS 8.2 (Systemd edition)

1. Remove "i18h.h" for iBus

We can remove the file "/etc/profile.d/i18n.h" so that the system variable "LANG" will be handled by the file "/etc/locale.conf" only. The advantage is we can use the systemd command "localectl" to configure the system locale. (The command "localectl will NOT handle the file "i18h.h" so sometimes you will find that the system locale is incorrect even you have used the command "localectl" to set your system locale setting.)

2. Setup system variables for ibus

Create the following file:

cat > /etc/profile.d/ibus.sh << EOF

export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus

EOF

3. Setup auto start for iBus

Create the following file:

cat > /etc/xdg/autostart/ibus-daemon.desktop << EOF

[Desktop Entry]
Type=Application
Encoding=UTF-8
Version=1.5.18
Name=ibus-daemon
Comment=iBus Daemon
Exec=/usr/bin/ibus-daemon --xim -d
X-GNOME-Autostart-enabled=true
X-KDE-autostart-after=panel

EOF

4. Build iBus Pinyin

4.1 Install Berkely Database

4.2 Download three files from iBus libpinyin web site (https://sourceforge.net/projects/libpinyin)

- libpinyin source code
- model file (in this example, model15 is used)
- ibus-pinyin source code

4.3 Build libpinyin

extract the source code package and run the following commands:

cp ../model15.text.tar.gz data/
sed '51,51d' -i data/Makefile.am

./autogen.sh --prefix=/usr --disable-static
make
make install

Note: The above "cp" and "sed" commands are used to remove the "wget" instruction and copy the model file to the target folder so we can build the source codes in the offline environment.

4.4 Build ibus-pinyin

extract the sourc code package and run the following commands:

./autogen.sh --prefix=/usr --sysconfdir=/etc
make
make install

5. Test iBus for pinyin

If you run the command "gtk-query-immodules-2.0" (for GTK+ 2.x) or the command "gtk-query-immodules-3.0" (for GTK+ 3.x), you will find that iBus input module will be activated if the beginning of the system locale is "zh", "ja" or "ko" only.
Therefore, we have to use the systemd command "localectl" to set the correct system locale such as "zh_CN.GB18030". You can run "locale -a" to find out the available system locale and read the Chapter 6.2 (Glibc 2.27) of LFS 8.2 for more information.

Then, you can start the iBus configure panel and add "Pinyin" method in the list.
Now, you should able to switch iBus input method and input Chinese characters in your text editor (e.g. mousepad).

Setup Notification Deamo for BLFS 8.2

If Notification daemon is not started automatically, you can run the following command (as root):

cp /usr/share/applications/notification-daemon.desktop /etc/xdg/autostart/

2018年4月7日星期六

Install Onboard for BLFS 8.2

1. Install hunspell

1.1 extract the source code package
1.2 execute:
autoreconf -vfi
./configure --prefix=/usr --sysconfdir=/etc
make
make install
ldconfig

2. Install python distutils extra

2.1 extract the source code package
2.2 execute:
python3 setup.py build
python3 setup.py install --optimize=1


3. Install Onboard

3.1 extract the source code package
3.2 execute:

python3 setup.py build
python3 setup.py install --optimize=1

glib-compile-schemas /usr/share/glib-2.0/schemas


Install X11Vnc for BLFS 8.2

X11Vnc is a VNC server for Linux

1. Install libvncserver

1.1 extract the source code package
1.2 execute:
./autogen.sh --prefix=/usr
make
make install

2. Install TCL and TK packages

3. Install x11vnc

3.1 extract the source codes package
3.2 execute:
./autogen.sh --prefix=/usr --sysconfdir=/etc
make
make install