2026/11/20

Apache TinkerPop

Apache TinkerPop is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP). Gremlin is a graph traversal language and virtual machine developed by Apache TinkerPop.

Apache TinkerPop has below sub projects:

  • Gremlin: A graph traversal (query) language
  • Gremlin Console: An interactive shell for working with local or remote graphs (based on the Groovy console)
  • Gremlin Server: Allows hosting of graphs remotely via a HTTP/WebSocket connection
  • TinkerGraph: A small in-memory graph implementation

使用 gremlin-server.sh 啟動 server,在最近的 Java 版本(例如 Java 21), 因為 Java module system 的關係,最好加上下面的設定:

# Set Java options
if [[ "$JAVA_OPTIONS" = "" ]] ; then
    JAVA_OPTIONS="-Xms512m -Xmx4096m --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED"
fi

如果要啟動 server 在前景執行

bin/gremlin-server.sh console

如果要啟動 server 在背景執行

bin/gremlin-server.sh start

如果要查詢在背景執行的 server 目前的狀態

bin/gremlin-server.sh status

如果要停止在背景執行的 server

bin/gremlin-server.sh stop

SSL/TLS

使用 keytool 建立 keystroe:

keytool -genkeypair -alias server \
-dname "CN=localhost, OU=IT Department, O=Orange Inc. ,L=Taipei, S=Taiwan,C=TW" \
-ext SAN=DNS:localhost,IP:127.0.0.1 \
-keyalg RSA -keysize 2048 -sigalg SHA256withRSA -storetype PKCS12 \
-validity 3650 \
-keypass password -keystore ./trusted.keystore -storepass password

修改 gremlin-server.yaml,加入下面的設定

authentication: {
  authenticator: org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator,
  config: {
    credentialsDb: conf/tinkergraph-credentials.properties
  }
}
ssl: {
  enabled: true,
  sslEnabledProtocols: [TLSv1.3],
  keyStore: conf/trusted.keystore,
  keyStorePassword: password,
  keyStoreType: PKCS12
}

相關連結

Apache Solr

Apache Solr 基於 Apache Lucene, 以 Java 編寫,是一個開源、高效能、企業級全文搜尋引擎伺服器。它提供強大的分面搜尋(Faceting)、 命中標示、富文件處理(PDF/Word)及分散式搜尋功能(SolrCloud)。Solr 具備 REST API。

Solr 有 standalone 與 cloud 模式的差別,二個模式的差異在於 cloud 模式使用 Apache ZooKeeper 儲存設定 (不管是使用自帶的或者是外部的 ZooKeeper service)。

下面是使用自帶的 ZooKeeper service 啟動服務的例子:

bin/solr start -c -z localhost:9983 -p 8983

下面是啟動 example 的 Solr cloud 指令(使用自帶的 ZooKeeper service):

bin/solr start -e cloud

重新啟動 node1 的指令如下:

bin/solr restart -c -p 8983 --solr-home example/cloud/node1/solr

重新啟動 node2 的指令如下:

bin/solr restart -c -p 7574 -z localhost:9983 --solr-home example/cloud/node2/solr

Solr 使用 Apache ZooKeeper 儲存設定。如果沒有特別指定,Solr 使用自己附帶的 ZooKeeper。 如果要使用外部的 ZooKeeper service,可以使用 -z 在命令列參數指定。

bin/solr start -e cloud -z localhost:2181

或者是修改 solr.in.sh

ZK_HOST="localhost:2181"

停止 server

bin/solr stop --all

刪除示範的目錄:

rm -Rf example/cloud/

如果要建立新的 collection,可以使用 Solr Admin Web interface 建立一個新的 collection。 也可以使用下列的指令:

bin/solr create -c mycollection -d _default
bin/solr create -c films --shards 2 --replication-factor 2

Extraction and SQL module

修改 solr.in.sh

SOLR_MODULES=extraction,sql

SQL module 修改過後重啟 server 即可使用,Extraction 還需要額外的設定(在 9.0 還需要 Apache Tita server)。

下載 Apache Tika 以後執行:

java -jar tika-server-standard-3.2.3.jar

使用下列的指令更新設定:

curl -X POST -H 'Content-type:application/json' -d '{
  "add-requesthandler": {
    "name": "/update/extract",
    "class": "solr.extraction.ExtractingRequestHandler",
    "extraction.backend": "tikaserver",
    "tikaserver.url": "http://localhost:9998",
    "defaults":{
      "lowernames": "true",
      "captureAttr":"true"
    }
  }
}' 'http://localhost:8983/solr/gettingstarted/config'

SSL

使用 keytool 建立 keystroe:

keytool -genkeypair -alias server \
-dname "CN=localhost, OU=IT Department, O=Orange Inc. ,L=Taipei, S=Taiwan,C=TW" \
-ext SAN=DNS:localhost,IP:127.0.0.1 \
-keyalg RSA -keysize 2048 -sigalg SHA256withRSA -storetype PKCS12 \
-validity 3650 \
-keypass password -keystore ./trusted.keystore -storepass password

修改 solr.in.sh

# Enables HTTPS. It is implictly true if you set SOLR_SSL_KEY_STORE. Use this config
# to enable https module with custom jetty configuration.
SOLR_SSL_ENABLED=true
# Uncomment to set SSL-related system properties
# Be sure to update the paths to the correct keystore for your environment
SOLR_SSL_KEY_STORE=/home/danilo/Programs/solr/bin/trusted.keystore
SOLR_SSL_KEY_STORE_PASSWORD=password
SOLR_SSL_TRUST_STORE=/home/danilo/Programs/solr/bin/trusted.keystore
SOLR_SSL_TRUST_STORE_PASSWORD=password

Basic Authentication Plugin

security.json(username solr with the password SolrRocks)

{
  "authentication":{
    "blockUnknown": true,
    "class":"solr.BasicAuthPlugin",
    "credentials":{"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="}
  },
  "authorization":{
    "class":"solr.RuleBasedAuthorizationPlugin",
    "permissions":[{"name":"security-edit", "role":"admin"}],
    "user-role":{"solr":"admin"}
  }
}

Upload the file to ZooKeeper using the zkcli script

server/scripts/cloud-scripts/zkcli.sh -zkhost localhost:9983 -cmd putfile /security.json security.json

相關連結

Apache Cassandra

Apache Cassandra 使用 Java 撰寫, 是一套開源分散式 NoSQL 資料庫系統,提供了優秀的橫向拓展能力以及不錯的寫入效率, 最初由臉書開發,用於改善電子郵件系統的搜尋效能的簡單格式資料, 集 Google BigTable 的資料模型與 Amazon Dynamo 的完全分散式架構於一身。 Cassandra 在分散式系統的設計中採用了 Eventual Consistency 模式(最終一致性模式), 也就是重視 Availability 犧牲 Consistency,不過 Cassandra 提供了可以調整 Consistency 的相關參數, 雖然無法提供強一致性但是仍然可以對一致性要求有所增強。

因為使用 Google BigTable 的資料模型,所以主鍵 (partition key) 十分重要, Cassandra 中的主鍵代表一個特殊惟一的資料分割區以及分割區內的資料排列方式。

Cassandra 的查詢語言為類似 SQL 的 Cassandra Query Langauge (CQL)。

設定檔為 conf 目錄下的 cassandra.yaml。如果想要使用密碼認證,可以這樣設定:

authenticator: PasswordAuthenticator

預設的 username 為 cassandra,password 為 cassandra。如果使用 PasswordAuthenticator, 使用者資料放在 system_auth 中。


Cassandra cpp driver 提供了 C++ driver。 下面是一個使用的例子。

#include <cassandra.h>
#include <stdio.h>

int main() {
    /* Setup and connect to cluster */
    CassFuture *connect_future = NULL;
    CassCluster *cluster = cass_cluster_new();
    CassSession *session = cass_session_new();

    const char *username = "cassandra";
    const char *password = "cassandra";

    cass_cluster_set_credentials(cluster, username, password);    

    /* Add contact points */
    cass_cluster_set_contact_points(cluster, "127.0.0.1");

    /* Provide the cluster object as configuration to connect the session */
    connect_future = cass_session_connect(session, cluster);

    if (cass_future_error_code(connect_future) == CASS_OK) {
        CassFuture *close_future = NULL;

        /* Build statement and execute query */
        CassStatement *statement =
            cass_statement_new("SELECT keyspace_name "
                               "FROM system_schema.keyspaces",
                               0);

        CassFuture *result_future = cass_session_execute(session, statement);

        if (cass_future_error_code(result_future) == CASS_OK) {
            /* Retrieve result set and iterate over the rows */
            const CassResult *result = cass_future_get_result(result_future);
            CassIterator *rows = cass_iterator_from_result(result);

            while (cass_iterator_next(rows)) {
                const CassRow *row = cass_iterator_get_row(rows);
                const CassValue *value =
                    cass_row_get_column_by_name(row, "keyspace_name");

                const char *keyspace;
                size_t keyspace_length;
                cass_value_get_string(value, &keyspace, &keyspace_length);
                printf("keyspace_name: '%.*s'\n", (int)keyspace_length,
                       keyspace);
            }

            cass_result_free(result);
            cass_iterator_free(rows);
        } else {
            /* Handle error */
            const char *message;
            size_t message_length;
            cass_future_error_message(result_future, &message, &message_length);
            fprintf(stderr, "Unable to run query: '%.*s'\n",
                    (int)message_length, message);
        }

        cass_statement_free(statement);
        cass_future_free(result_future);

        /* Close the session */
        close_future = cass_session_close(session);
        cass_future_wait(close_future);
        cass_future_free(close_future);
    } else {
        /* Handle error */
        const char *message;
        size_t message_length;
        cass_future_error_message(connect_future, &message, &message_length);
        fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length,
                message);
    }

    cass_future_free(connect_future);
    cass_cluster_free(cluster);
    cass_session_free(session);

    return 0;
}

(注意: system_schema.keyspaces 為 3.x 之後使用的名稱,3.0 之前使用 system.schema_keyspaces)

CassTcl 是 Cassandra Tcl driver,建立在 CPP driver 之上。

在 openSUSE 上編譯:

autoconf
./configure --enable-64bit --libdir=/usr/lib64/tcl
make
sudo make install

下面是測試是否可以連線的程式:

package require casstcl

set cass [::casstcl::connect -host 127.0.0.1 -port 9042 -user cassandra -password cassandra]
$cass select "SELECT keyspace_name FROM system_schema.keyspaces;" row {
  parray row
}
$cass delete

目前 casstcl 在 prepared statement 使用 ? 做 parameters binding, 需要在在 create table 之後呼叫 reimport_column_type_map,執行的結果才會是正確的 (更正:或者是在第一次使用 exec 前呼叫也可以,要這樣做是因為新增的 table 還沒有對應資料)。

相關連結

CrateDB

CrateDB is a distributed SQL database management system that integrates a fully searchable document oriented data store. CrateDB is designed for high scalability and includes components from Facebook Presto, Apache Lucene, Elasticsearch and Netty.

CrateDB's language is SQL but it uses the document-oriented approach of NoSQL style databases. CrateDB uses the SQL parser from Facebook Presto, its own query analysis and distributed query engine. Elasticsearch and Lucene is used for the transport protocol and cluster discovery and Netty for asynchronous event driven network application framework.

CrateDB 在分散式系統的設計中採用了 Eventual Consistency 模式(最終一致性模式), 也就是重視 Availability 犧牲 Consistency。 営寫入資料時,CrateDB 會將記錄被寫入記憶體緩衝區。該緩衝區中的記錄尚未建立索引。查詢不會存取記憶體緩衝區, 因此其內容不會包含在任何查詢結果中。 同時,該記錄也會寫入磁碟上的交易日誌。交易日誌用於資料恢復的場合,並且在主鍵查找中也發揮特殊作用。 經過一段時間後,記憶體緩衝區中累積的所有記錄都會建立索引並傳送到記憶體中的 Lucene segment。 Lucene segment 是一個完全獨立的索引結構,支援資料查詢。 資料從記憶體緩衝區傳送到記憶體段的間隔稱為更新間隔 (refresh interval),預設值為一秒。 更新操作會將記憶體中的段移到磁碟。此更新操作不會影響查詢行為,但允許清除交易日誌。 當然,使用者可以手動執行更新操作。但是不管如何,CrateDB 在寫入資料之後有可能在某個時間區段無法讀取到其最新的資料, 因為需要等待內部的更新資料,所以 CrateDB 在一致性上是有所取捨的。

CrateDB 使用 Java 撰寫,授權為 Apache License 2.0,解壓縮後執行 server 就可以使用。

CrateDB 提供了互動式 shell crash。 Server protocol 支援 REST 與 PostgreSQL 二種協議,我只有測試過 REST intrerface,其預設 port 為 4200。

SSL/TLS

在 config 目錄下使用 keytool 建立 keystroe:

keytool -genkeypair -alias server \
-dname "CN=localhost, OU=IT Department, O=Orange Inc. ,L=Taipei, S=Taiwan,C=TW" \
-ext SAN=DNS:localhost,IP:127.0.0.1 \
-keyalg RSA -keysize 2048 -sigalg SHA256withRSA -storetype PKCS12 \
-validity 3650 \
-keypass password -keystore ./trusted.keystore -storepass password

修改 config 目錄下的 crate.yml

# Enable encrypted communication for the HTTP endpoints:
ssl.http.enabled: true

# Enable encrypted communication for the PostgreSQL wire protocol:
#ssl.psql.enabled: true

# The full path to the node keystore file
ssl.keystore_filepath: /home/danilo/Programs/crate/config/trusted.keystore

# The password used to decrypt the keystore_file.jks
ssl.keystore_password: password

# The password entered at the end of the keytool -genkey command if different
# than the keystore_password.
ssl.keystore_key_password: password

# Optional configuration for truststore

# The full path to the node truststore file
ssl.truststore_filepath: /home/danilo/Programs/crate/config/trusted.keystore

相關連結

2026/11/03

LightDM

Display Manager 使用於 X Window System,作為以 GUI 登入以及登入後顯示 GUI 畫面, 以及使用 GUI 切換使用者的應用程式。 一般而言 Gnome 使用 GDM,KDE Plasma 使用 SDDM, 同時也有可以適用於不同的 Window Manager 的 LightDM 可以使用。 理論上來說 Display Manager 與 Window Manager 是彼此獨立的程式, 實作良好的 Display Manager 只要設定沒問題就可以正確啟動各種 Window Manager session。

如果想要在 openSUSE 使用 LighDM,如果還沒有安裝,首先是安裝的指令:

sudo zypper in lightdm

如果要設定自動登入(並且關閉 guest login),編輯 /etc/lightdm/lightdm.conf:

[Seat:*]
allow-guest=false
user-session=default
greeter-setup-script=/usr/bin/numlockx default
autologin-user=
autologin-user-timeout=0
autologin-session=default

user-session 與 autologin-session 有效的選項可以查看 /usr/share/xsessions 以及 /usr/share/wayland-sessions 二個目錄下的設定。

使用下列的指令將 default display manager 設為 LightDM。

sudo systemctl enable -f lightdm.service

如果是 OpenSUSE Leap 15.0,使用下列的命令:

sudo update-alternatives --config default-displaymanager

(注意:如果是從 OpenSUSE Leap 升級到新的系統,系統可能使用相容的方式運作, 在第一次使用 systemctl enable 設置 display manager 時, 要先查詢 display-manager-legacy.service 是否正在執行,如果是要記得 disable)

或者是使用 Yast 設定,Yast > Miscellaneous > Alternatives。 自動登入也可以使用 Yast 設定,選擇 User and Group Management,點擊 Expert Options, 然後找到 Login Settings,這裡可以選擇 Display Manager 是否允許自動登入,勾選 Auto Login 並且選擇使用者。

使用下列的方式確定目前使用的 Display Manager:

sudo systemctl status display-manager

也可以檢查 systemd 所使用的檔案來確定目前所使用的服務:

file /etc/systemd/system/display-manager.service

2026/10/09

IceWM Window Manager

IceWM 是一個專為 X Window System 設計的視窗管理員, 由 Marko Maček 於 1997 年開始開發。 IceWM 是個十分輕量的視窗管理員,通常一些設定需要自行修改文字設定檔才行。 要考量的是 IceWM 只是一個視窗管理員,而不是一個桌面環境, 因此缺少檔案管理員 (File Manager) 等內建程式, 需要安裝某個桌面環境提供的程式或者是外部的應用程式。應該也有為了能夠在老舊硬體也能夠執行良好, 使用 IceWM 作為核心,組合其它的應用程式加上自己的設定以後的 Linux Distribution。 因為 Gnome 與 KDE 都相繼轉向 Wayland-only 的環境,但是我仍然需要一個 X Window System 的環境, 所以開始嘗試使用 IceWM。

在安裝完成之後,建立 ~/.config/icewm 目錄(openSUSE 可以使用此目錄進行設定), 再複製下列的設定檔:

cp -a /usr/share/icewm/{prefoverride,toolbar,menu} ~/.config/icewm/

檔案 prefoverride 可以作為主設定檔(包含 theme 設定的項目可以在這裡再設定一次覆蓋掉); 工具列設定在 toolbar;主選單在 menu。

IceWM 支援 theme,在 ~/.config/icewm 下建立 theme 檔案, OpenSUSE 內建的 theme 在 /usr/share/icewm/themes,設定的方式如下:

Theme="win95/default.theme"

下面是我工具列 toolbar 的設定:

prog "xterm" utilities-terminal xterm
prog "Firefox" firefox firefox file:///home/danilo/public_html/index.html
prog PCManFM-Qt pcmanfm-qt pcmanfm-qt
prog "Volume Control"  multimedia-volume-control pavucontrol-qt

(在 prog 後面的項目是:程式名稱 程式圖示 程式執行路徑與參數,menu 與 toolbar prog 的設定語法相同)

下面是我主選單 menu 的設定:

prog XTerm utilities-terminal xterm
prog PCManFM-Qt pcmanfm-qt pcmanfm-qt
menu Favorites folder {
    prog Firefox firefox firefox
    prog Thunderbird thunderbird thunderbird
    prog LibreOffice libreoffice-main libreoffice
    prog "SciTE Editor" Sci48M SciTE
    prog QPdfView qpdfview qpdfview
    prog GIMP gimp gimp
    prog Nomacs org.nomacs.ImageLounge nomacs
    prog Audacious audacious audacious
    prog "VLC Player" vlc vlc
}
includeprog icewm-menu-fdo --seps -d1400 -D1650 -S --limit-max-len=42
#menufile Programs folder programs
menufile Tool_bar folder toolbar
menuprog SUSE folder xdg_menu --format icewm

icewm-menu-fdo 指令可以從系統資料自動產生選單與子選單。 IceWM 有個很有趣的功能, 可以使用 icesh 這個命令列工具組合選取條件、過濾器與動作來控制視窗屬性或 IceWM 本身。 因此我們可以使用 icesh restart 重新啟動 IceWM, 觀察是否有正確修改 theme 或者是選單。


我修改的主要設定檔 prefoverride 設定項目為:

#  Command to lock display/screensaver.
LockCommand="xautolock -locknow"

#  Opaque window move.
OpaqueMove=0 # 0/1

#  Opaque window resize.
OpaqueResize=0 # 0/1

#  Favour Xft fonts over core X11 fonts where possible.
PreferFreetypeFonts=1 # 0/1

#  Enable Alt+Tab window switching.
QuickSwitch=1 # 0/1

#  Show mailbox status on task bar.
TaskBarShowMailboxStatus=0 # 0/1

#  Show 'show desktop' button on taskbar (value of 2 to put after the clock)
TaskBarShowShowDesktopButton=2 # [0-2]

#  Desktop background color(s), comma separated.
DesktopBackgroundColor=""

#  Desktop background image(s), comma separated.
# DesktopBackgroundImage=""
DesktopBackgroundImage="/home/danilo/Pictures/orange-cat.jpg"

在 prefoverride 設定完桌面的背景桌布以後,可以使用 icewmbg -r 重新載入觀察結果。

PulseAudio and PipeWire

二者我都有用過,都工作的很好。

PipeWire 是目前 openSUSE Tumbleweed 的預設值 (在 20220708 之後,不過如果是從 openSUSE Leap 升上來的,如果使用者沒有手動變更,便用的仍然是 PulseAudio)。 PulseAudio 的問題在於其設計者腦子裡並沒有考慮軟體相容性, 在當時已經有延屬較低而且被不少專業音訊軟體採用的 JACK 存在, 但是其設計者卻完全不考慮軟體相容性並且與 JACK 並不相容,而 Redhat 也不管軟體相容問題直接力推 PulseAudio, 造成一些軟體相容性的問題。 就我來說,建議使用 PipeWire,PipeWire 優越的地方就是提供了 PulseAudio 與 JACK 相容的軟體介面,但是延遲比 PulseAudio 較低且通常使用的資源比較少。

下面是安裝 PipeWire 的指令:

sudo zypper in pipewire-pulseaudio pipewire-alsa

要注意 PipeWire 與 PulseAudio 無法共存,所以要選擇 deinstallation PulseAudio 的套件。


因為 IceWM 本身不包含音訊管理功能,需要在啟動時設定自動執行 PipeWire 服務。 不過好像不設定也可以,在我設定之前,音訊功能似乎也可以正常工作。 IceWM 的自動啟動檔案為 ~/.config/icewm/startup (記得使用 chmod +x startup 設定檔案屬性為可執行)。 使用 systemd 的系統,startup 檔案內容如下:

# Pass environment variables to systemd --user session
if command -v dbus-update-activation-environment >/dev/null 2>&1; then
    dbus-update-activation-environment --systemd --all
fi

# For PireWire (systemd)
systemctl --user start pipewire pipewire-pulse wireplumber

如果使用非 systemd 系統,則改為如下:

#!/bin/bash

pipewire &
pipewire-pulse &
wireplumber &

檢查是否設定成功:

pactl info

如果輸出結果中的 Server Name 顯示為 PulseAudio (on PipeWire x.y.z), 就代表設定成功。

如果想要設定音量,可以安裝 pavucontrol-qt (適合 PulseAudio 以及有安裝 PulseAudio 相容軟體層的 PipeWire 使用)。

NetworkManager

接下來加入網路設定的部份。如果使用 NetworkManager 設定網路,可以安裝 NetworkManager-applet 來更方便的設定網路。 修改 startup 檔案:

#!/bin/bash

# start network manager
sleep 1 && nm-applet &

# allow notifications
/usr/libexec/notification-daemon &

# Pass environment variables to systemd --user session
if command -v dbus-update-activation-environment >/dev/null 2>&1; then
    dbus-update-activation-environment --systemd --all
fi

# For PipeWire
systemctl --user start pipewire pipewire-pulse wireplumber

Lock screen

接下來設定螢幕鎖定功能。 這裡使用 xautolock 與 xscreensaver 結合使用的方式,因此需要二個套件都有安裝。

修改主要設定檔 prefoverride,設定 LockCommand:

#  Command to lock display/screensaver.
LockCommand="xautolock -locknow"

修改 startup 檔案:

#!/bin/bash

# pcmanfm-qt desktop icon manager
#pcmanfm-qt --desktop &

# start network manager
sleep 1 && nm-applet &

# enable screensaver
xscreensaver -nosplash &

# allow notifications
/usr/libexec/notification-daemon &

# enable lockscreen
xautolock -detectsleep -time 10 -locker "xscreensaver-command -lock" &

# Pass environment variables to systemd --user session
if command -v dbus-update-activation-environment >/dev/null 2>&1; then
    dbus-update-activation-environment --systemd --all
fi

# For PireWire
systemctl --user start pipewire pipewire-pulse wireplumber

xautolock 的 -time 用來設定時間,這裡的 10 就是 10 分鐘; -locker 用來呼叫執行螢幕鎖定功能的程式。 在使用 xautolock 控制 xscreensaver 時,需要調整 xscreensaver 本身的設定, 避免二個套件在螢幕鎖定時間的衝突, 執行 xscreensaver-demo(xscreensaver 的設定界面),取消勾選 Lock Screen After。

Theme (Gtk/Qt)

下面嘗試設定 Gtk 以及 Qt 的 theme 設定,讓使用 Gtk 以及 Qt 撰寫的程式看起來比較美觀; 以及 LibreOffice 的相關設定。設定方式為在 ~/.config/icewm/env 這個檔案設定環境變數:

GTK_THEME="Adwaita"
#GTK_THEME="Adwaita:dark"
QT_QPA_PLATFORMTHEME="qt6ct"
SAL_USE_VCLPLUGIN="qt6"

原本我 QT_QPA_PLATFORMTHEME 嘗試使用 platform theme 並且設為 gtk3, 但是在使用中發現這並不是正確的設法,還是需要使用 qt6ct 處理 Qt6 在非 Qt 開發的環境下的視覺設定, 不過也一樣需要設定 QT_QPA_PLATFORMTHEME 為正確的值 (qt6ct) 才行。

xdg-desktop-portal

我發現 xdg-desktop-portal service 並沒有正確啟動(有安裝 xdg-desktop-portal-gtk 但是沒有啟動成功), 而原因是 graphical-session.target 沒有正確啟動服務。 嘗試採用 workaround 避開這個問題, 修改 /usr/lib/systemd/user/xdg-desktop-portal.service:

[Unit]
Description=Portal service
#PartOf=graphical-session.target
#Requisite=graphical-session.target
#After=graphical-session.target

[Service]
Type=dbus
BusName=org.freedesktop.portal.Desktop
ExecStart=/usr/libexec/xdg-desktop-portal
Slice=session.slice

使用下列的指令檢查目前的服務狀態:

systemctl --user status xdg-desktop-portal.service

PCManFM-Qt

PCManFM-Qt 是一個輕量的檔案管理以及桌面管理程式。 檔案管理方面有二個地方要設定,Edit > Preference > Advanced, 選擇要使用的 Terminal emulator 以及 Archiver integration(如果沒有安裝其它桌面環境的 archive manager, 可以安裝同樣是 LXQt 桌面環境組件的 lxqt-archiver 並且設定使用)。

IceWM 使用 icewmbg 處理桌面上的桌布。如果要讓 pcmanfm-qt 處理, 那麼要在 prefoverride 將 DesktopBackgroundImage 與 DesktopBackgroundColor 都設為空白, 並且在 startup 設定啟動 pcmanfm-qt desktop manager。加入下面的設定內容:

#!/bin/bash

# pcmanfm-qt desktop icon manager
pcmanfm-qt --desktop &

在 pcmanfm-qt 管理桌面以後,按右鍵選擇 Desktop Preferences 就可以設定桌面選項 (我使用的版本行為是這樣)。 但是有個麻煩的地方是 desktop icon 不管什麼桌面環境都會放在家目錄下的 Desktop 目錄, 所以彼此可能會發生衝突。在考慮以後,我決定使用 IceWM 原來的 icewmbg 管理桌布, 而不使用 pcmanfm-qt(在 startup 關於 pcmanfm-qt 的設定需要移除或者是註解掉)。

XTerm

X Window 內建的終端模擬器為 XTerm,其設定檔可以使用家目錄下的 .Xresources。

! Set font and anti-aliasing
xterm*faceName: Monospace
XTerm*faceSize: 16

! Enable a scrollbar on the right side
XTerm*scrollBar: true
XTerm*rightScrollBar: true

! Configuring the maximized window size
XTerm*maximized: true

! Set color scheme (Black background, white text)
XTerm*vt100.background: black
XTerm*vt100.foreground: white

! Display Scrollbar
XTerm.vt100.scrollBar: true
XTerm.vt100.scrollbar.width: 8

! Increase history scrollback buffer
XTerm*saveLines: 4096

! Selections are available via the standard clipboard
XTerm*selectToClipboard: false

! Fix backspace behavior
XTerm*vt100.backarrowKey: false

! Custom Key Bindings for copy and paste
XTerm*vt100*translations:      #override \n\
Shift <Key>Insert:  insert-selection(CLIPBOARD) \n\
Ctrl <Key>Insert:   copy-selection(CLIPBOARD) \n\
Ctrl Shift <Key>C:  copy-selection(CLIPBOARD) \n\
Ctrl Shift <Key>V:  insert-selection(CLIPBOARD)

(原本我將 XTerm*selectToClipboard 設為 true,這樣只要選取文字就會自動複製到 clipboard。 不過後來我決定採取更手動的方式,所以使用 custom key bindings 的方式,設定 Ctrl+Insert 用來複製文字; 並且加入 Shfit+Ctrl+C 與 Shfit+Ctrl+V 這組按鍵。)

如果要立即生效,使用下列的指令:

xrdb -merge ~/.Xresources

XTerm 讀取環境變數 SHELL 作為執行命令時的命令列介面程式,如果需要使用指定的 SHELL, 可以設定環境變數 SHELL 以後再執行 xterm:

SHELL=/usr/bin/tcsh xterm

Mozilla Firefox

Firefox 支援佈景主題 (Themes) 與內建 PDF.js。下面是我目前有在使用的套件:

  • uBlock Origin: 高效率的廣告攔截工具
  • Decentraleyes: 用於保護使用者免遭集中的內容交付網路(CDN)的跟蹤
  • Privacy Badger: 用於阻止那些不遵守 DNT 協定的廣告商跟蹤行為
  • Flagfox: 以旗幟圖示顯示出目前網頁伺服器實際位置的擴充套件
  • Livemarks: Get auto-updated RSS feed bookmark folders

Thunderbird

下面是 gmail 的設定資料,Thunderbird 本身已經有設定資料,只是用來檢查設定是否正確。

內送郵件伺服器 (IMAP)

  • 伺服器名稱 (Host):imap.gmail.com
  • 通訊埠 (Port):993
  • 安全性加密類型:SSL 或 TLS
  • 使用者名稱 (Username):Gmail 電子郵件地址
  • 密碼 (Password):Gmail 密碼或應用程式密碼(若已開啟兩步驟驗證)

外寄郵件伺服器 (SMTP)

  • 伺服器名稱 (Host):smtp.gmail.com
  • 通訊埠 (Port):465(搭配 SSL)
  • 安全性加密類型:TLS 或 SSL
  • 需要驗證:勾選「我的外寄伺服器 (SMTP) 需要驗證」(設定與內送相同)

從 2025 年開始,Google 帳戶已全面不支援僅用「使用者名稱與密碼」登入的低安全性第三方應用程式, 第三方郵件端需改用 OAuth 2.0 或「應用程式密碼」來進行身分驗證。

下面是 Account Settings 要注意的部份。
在 Server Settings 中,不要勾選 Clean up ("Expunge") Inbox on Exit 與 Empty Trash on Exit。
在 Copies & Folders 中,不要勾選 Place a copy in 選項, 在 Drafts and Templates 的 Keep message drafts in: 選項中,選擇 Other, Drafts on [Your Gmail address]。
在 Spam Settings,不要勾選 Enable adaptive junk mail controls for this account。


下面是 hotmail 的設定資料,Thunderbird 本身已經有設定資料,只是用來檢查設定是否正確。

內送郵件伺服器 (IMAP)

  • 伺服器名稱 (Host):outlook.office365.com
  • 通訊埠 (Port):993
  • 加密方法:SSL / TLS
  • 使用者名稱 (Username):Hotmail 電子郵件地址
  • 密碼 (Password):Hotmail 密碼或應用程式密碼(若已開啟兩步驟驗證)

外寄郵件伺服器 (SMTP)

  • 伺服器名稱 (Host):smtp-mail.outlook.com
  • 通訊埠 (Port):587
  • 加密方法:STARTTLS
  • 驗證方式:OAuth2

注意需要啟用 IMAP 功能:登入 Outlook 網頁版,前往 設定 > 郵件 > 轉寄和 IMAP,確認已勾選 開啟 IMAP 並儲存。

下面是 Account Settings 要注意的部份。
在 Copies & Folders 中,在 Place a copy in 選項 選擇 Other 選項。

SciTE

選單 Options > Open User Options File, 然後加入要設定的選項(可以先複製 global options 的內容到此處再設定)。 User Option file 檔案為家目錄下的 .SciTEUser.properties。 下面只是目前修改的結果,主要修改使用者介面、code page 以及字型設定。

# Window sizes and visibility
position.maximize=1
#position.tile=1
#full.screen.hides.menu=1
#minimize.to.tray=1
#icon.busy=1
split.vertical=0
#split.wide=1
#output.horizontal.size=200
#output.vertical.size=60
#output.initial.hide=1
#horizontal.scrollbar=0
#horizontal.scroll.width=10000
#horizontal.scroll.width.tracking=0
#output.horizontal.scrollbar=0
#output.horizontal.scroll.width=10000
#output.horizontal.scroll.width.tracking=0
#output.scroll=0
#error.select.line=1
#end.at.last.line=0
tabbar.visible=1
#tabbar.hide.one=1
#tabbar.hide.index=1
#tabbar.multiline=1
toolbar.visible=1
#toolbar.usestockicons=1
#toolbar.large=1
#menubar.detachable=1
#undo.redo.lazy=1
undo.selection.history=1
statusbar.visible=1

# Sizes and visibility in edit pane
line.margin.visible=1
line.margin.width=2+

view.whitespace=1

check.if.already.open=1
#temp.files.sync.load=1
default.file.ext=.txt
#source.default.extensions=.h|.cxx|.bat
title.full.path=1
open.dialog.in.file.directory=1
save.check.modified.time=1

# Indentation
tabsize=4
indent.size=4
use.tabs=1

# Wrapping of long lines
wrap=1
wrap.style=2

# Behaviour
#eol.mode=LF
eol.auto=1
clear.before.execute=1

# Unicode
code.page=65001
output.code.page=65001

# Give symbolic names to the set of fonts used in the standard styles.
font.base=$(font.monospace)
font.small=font:Noto Sans Mono CJK TC, size:10
font.comment=$(font.monospace)
font.code.comment.box=$(font.monospace)
font.code.comment.line=$(font.monospace)
font.code.comment.doc=$(font.monospace)
font.code.comment.nested=$(font.monospace)
font.text=$(font.monospace)
font.text.comment=$(font.monospace)
font.embedded.base=$(font.monospace)
font.embedded.comment=$(font.monospace)
font.monospace=font:Noto Sans Mono CJK TC, size:12
font.monospace.small=font:Noto Sans Mono CJK TC, size:10
font.vbs=$(font.monospace)

Tips

OpenGL Software render

如果因為 OpenGL 版本的關係, 需要使用 Mesa 的 OpenGL Software render 實作(或者是因為應用程式所使用的 OpenGL 版本的關係),使用下列的環境變數設定:

export __GLX_VENDOR_LIBRARY_NAME=mesa
export LIBGL_ALWAYS_SOFTWARE=1 

Mime type

使用 xdg-mime 查詢與設定使用哪個預設的程式來開啟執行某個檔案類型。

以 C source code 為例,首先是查詢:

xdg-mime query default text/x-csrc

如果是空白或者是不符合目前的需要,使用下列的方式設定:

xdg-mime default SciTE.desktop text/x-csrc

適用的應用程式可以參考 /usr/share/applications 下的檔案。

加入字型

英文字體分類通常可以分為三類:Serif(襯線體)、Sans-serif(無襯線體)與 Monospace(等寬字體)。 而中文最常用的明體(與宋體)、黑體、仿宋、楷體這四大經典印刷字體,黑體是無襯線體字型, 明體(與宋體) 則是襯線體字型。

因為漢字文字眾多,所以會有缺字的問題, Google Noto 字型已經讓自由軟體環境缺字的情況大幅度減少,已可以滿足大多數的使用情境。 如果要在 openSUSE 使用 zypper 安裝 Google Noto 字型繁體中文的部份:

sudo zypper in google-noto-sans-tc-fonts google-noto-sans-tc-mono-fonts google-noto-serif-tc-fonts

目前就我所知,支援到 Unicode 17.0 全部漢字的字型為 Jigmo(字雲)。 在 Linux 將字型加入個人使用環境的方式如下:

  • 首先把字型複製到 ~/.local/share/fonts/ 目錄下面
  • 執行 fc-cache -v -f

而後使用 fc-list 配合 grep 觀察是否有成功安裝。

Clear the GTK/FreeDesktop History File

使用下列的指令:

rm -f ~/.local/share/recently-used.xbel
touch ~/.local/share/recently-used.xbel

2026/07/28

龍芯

我發覺對中國的事物是真的無知,至少我讀了龙芯,正式进入 PostgreSQL 官方仓库以後,才想要查詢一下目前龍芯的進展。

來自 Google 以後的資訊:
龍芯是由中國科學院計算技術研究所及龍芯中科等機構設計的一系列中國國產通用中央處理器與晶片,核心產品涵蓋龍芯1號(嵌入式)、龍芯2號(工控)與龍芯3號(桌面及伺服器),採用完全自主的「龍架構」(LoongArch)指令集。

雖然說龍芯大致對標國際主流水準,不過實際上仍然是落後的(我知道有些人應該會嘲笑這點,我是覺得大可不必),只是有幾件事值得注意:

  • 龍芯是否可以持續研發
  • 龍芯是否可以由中國國內廠商完全國產(雖然可以找其它地方的代工廠,但是為了避免在極端情況下的問題,中國國內廠商需要有能力可以自行生產)

如果答案都是「是」,那麼目前大致對標國際主流水準而有一些地方落後是可以接受的,只要能夠持續進步,同時中國國內廠商(也就是晶圓代工廠們)可以繼續推進其製程反過來促進龍芯的進步,而龍芯可以切入工控電腦等領域並且有效取代,我是覺得就沒有問題。

另外,龍芯要注意的就是其軟體生態圈是否可以建立,如果可以(最少中國有人使用),或許也是一條中國值得走的路。

2026/07/15

Apache CouchDB

Apache CouchDB 是一個開源資料庫,主要功能使用 Erlang 撰寫。 專注於易用性和成為"完全擁抱web的資料庫"。 它是一個使用 JSON 作為儲存格式,JavaScript 作為查詢語言,MapReduce 和 HTTP 作為 API 的文件導向 NoSQL 資料庫。 其中一個顯著的功能就是多主複製。Apache CouchDB 在 CAP Theorem 中屬於 Eventual Consistency 類型。

使用從 source code 編譯,下面是設定的指令(如果 JavaScript engine 想要使用 QuickJS):

./configure --spidermonkey-version 115 --js-engine=quickjs --disable-spidermonkey

而後將 rel/couchdb 目錄複製到 /opt/couchdb。

建立 couchdb 使用者。

sudo useradd -r -c 'CouchDB Administrator' -d/opt/couchdb -U -M -s/bin/bash couchdb

設定 couchdb 目錄的使用者。

sudo chown -R couchdb:couchdb /opt/couchdb

設定 couchdb 目錄的權限。

sudo find /opt/couchdb -type d -exec chmod 0770 {} \;
sudo chmod 0644 /opt/couchdb/etc/*

第一次執行

sudo -i -u couchdb /opt/couchdb/bin/couchdb

你會發現無法執行,修改 /opt/couchdb/etc/local.ini,加入 admin 帳號。

[admins]
admin = admin

再次啟動 server。如果成功,連線到 http://127.0.0.1:5984/_utils/index.html 並且使用 username = admin, password = admin 登入。 可以建立一個資料庫 my_database,然後使用 http://localhost:5984/_utils/index.html#verifyinstall 檢查目前的情況。

下面是 /opt/couchdb/etc/local.ini 關於使用者認證的部份,加入 cookie authentication 的設定。

[chttpd]
require_valid_user = true
authentication_handlers = {couch_httpd_auth, cookie_authentication_handler}, {chttpd_auth, default_authentication_handler}

[chttpd_auth]
secret = your_long_secure_shared_secret

SSL

建立 ssl.conf 設定檔

[req]
prompt = no
default_md = sha256
default_bits = 2048
distinguished_name = dn
x509_extensions = v3_req

[dn]
C = TW
ST = Taiwan
L = Taipei
O = Orange Inc.
OU = IT Department
emailAddress = admin@example.com
CN = localhost

[v3_req]
subjectAltName = @alt_names

[alt_names]
DNS.1 = *.localhost
DNS.2 = localhost
IP.1 = 127.0.0.1

透過指令建立開發測試用途的自簽憑證

openssl req -x509 -new -nodes -sha256 -utf8 -days 3650 -newkey rsa:2048 \
-keyout couchdb.key -out couchdb.crt -config ssl.conf

將 couchdb.key 與 couchdb.crt 複製到 /opt/couchdb/etc 目錄(需要使用 su 切換到 root 身份或者使用 sudo)。

修改 /opt/couchdb/etc/local.ini

[ssl]
enable = true
port = 6984
cert_file = /opt/couchdb/etc/couchdb.crt
key_file = /opt/couchdb/etc/couchdb.key
;password = somepassword

相關連結

2026/04/25

MariaDB

MariaDB 出垷的原因是因為 MySQL 被賣給了 SUN, 而後 SUN 被 Oracle 併購,所以 MySQL 被 Oracle 所擁有, 這導致一些 MySQL 原本的開發團隊人員對於 MySQL 是否能夠維持開放原始碼產生質疑, 所以複製 MySQL 5.5 原始碼出來維護的分支,並且成為大多數 Linux distribution 的內建選擇。 一開始 Oracle 其實對 MySQL 的管理還不錯,事情變化的源頭為 Oracle 推出 MySQL Heatwave 服務, 並且一些功能只在 MySQL Heatwave 增加,MySQL 社群版或者是企業版都不具備這些在 MySQL Heatwave 增加的功能, 同時 Oracle 也降低了對 MySQL 的開發重視度,這導致了 MySQL 社群版或者是企業版在 MySQL Heatwave 服務推出後其發展開始停滯, 並且遂漸跟不上使用者的需求。

MariaDB 使用與 MySQL 相同的通訊協定,一般而言可以作為 MySQL 的替代,其目標之一就是儘量維持與 MySQL 的相容, 雖然 MariaDB 與 MySQL 隨著二個開發團隊的各自開發而會有小地方的不同,但是目前仍然大多數的 MySQL 工具都可以直接使用。

在 openSUSE 安裝的指令:

sudo zypper in mariadb

使用下列的指令啟動 MariaDB server:

sudo systemctl start mariadb

使用下列的指令查詢 MariaDB server 的狀態:

sudo systemctl status mariadb

使用下列的指令停止 MariaDB server:

sudo systemctl stop mariadb

在安裝後啟動 MariaDB server,再使用下列的指令進行安全性設定:

sudo mysql_secure_installation

使用下列的指令驗證是否安裝正確(如果有設定密碼 password,輸入密碼):

mariadb -u root -p

在 MariaDB 中,若要完整支援 Unicode(包含 Emoji、特殊中日韓字元),應使用 utf8mb4 編碼, 而非舊的 utf8 (即 utf8mb3),因為舊版只支援 3 位元組,而 utf8mb4 支援 4 位元組。

修改 MariaDB 設定檔 /etc/my.cnf

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
character-set-client-handshake=FALSE

使用下列的指令重新啟動 MariaDB server:

sudo systemctl restart mariadb

重啟 MariaDB 服務後,登入並執行以下指令檢查:

SHOW VARIABLES LIKE 'character_set%';
SHOW VARIABLES LIKE 'collation%';

接下來建立一個新的資料庫以及新的使用者。

CREATE DATABASE `danilo`;

新增一個 MariaDB 資料庫使用者 danilo(Local access only),並將密碼設定為 danilo:

CREATE USER 'danilo'@'localhost' IDENTIFIED BY 'danilo';

給予 danilo 帳號在 danilo 資料庫上面的所有權限,讓 danilo 可以對 danilo 資料庫進行任何操作:

GRANT ALL PRIVILEGES ON danilo.* TO 'danilo'@'localhost';

執行下列的指令,讓修改確定有生效:

FLUSH PRIVILEGES;

檢查是否資料無誤:

SHOW GRANTS FOR 'danilo'@'localhost';

使用 GRANT 設定好帳號的權限後,接著就可以使用新的帳號登入使用:

mariadb -u danilo -p

MariaDB 採用可插拔儲存引擎架構,這意味著同一資料庫中的不同資料表可以使用不同的引擎,每個引擎都針對特定的工作負載進行了最佳化。 預設且最常用的通用引擎是 InnoDB。 MariaDB 可以使用 RocksDB 作為儲存引擎(稱為 MyRocks),只能在 x86_64 下使用,並不支援 32 位元的架構。 要注意的是,如果使用 MyRocks 作為儲存引擎,雖然寫入的速度獲得提升,但是 RocksDB engine 並不支援 FOREIGN KEY!

修改 MariaDB 設定檔 /etc/my.cnf

[mariadb]
plugin-load-add = ha_rocksdb

重啟 MariaDB 服務後,登入並執行以下指令檢查:

SHOW ENGINES;

在啟用後,建立資料表時指定儲存引擎就可以使用 RocksDB 作為儲存引擎。 下面是一個例子:

CREATE TABLE sensor_data (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    timestamp DATETIME NOT NULL,
    sensor_id SMALLINT UNSIGNED NOT NULL,
    value FLOAT NOT NULL
) ENGINE = RocksDB;

也可以先建立資料表,再使用下列的指令指定要使用的儲存引擎

ALTER TABLE sensor_data ENGINE=RocksDB;

如果要讓 RocksDB 成為預設的儲存引擎,需要修改 MariaDB 設定檔 /etc/my.cnf。 注意:在一般的情況下使用預設的 InnoDB 是不錯的主意, 因此需要的時候才在建立資料格的時候設定儲存引擎或者使用 ALTER TABLE 修改是一個不錯的做法。 這裡只是記錄如果要修改預設的儲存引擎應該怎麼做。

[mysqld]
#default-storage-engine=InnoDB
default-storage-engine=rocksdb

重啟 MariaDB 服務後,登入並執行以下指令檢查:

SHOW VARIABLES LIKE 'default_storage_engine';

MariaDB 可以使用 Mroonga 作為儲存引擎, Mroonga 支援包含 Chinese, Japanese, and Korean (CJK) 在內的全文搜尋功能,只能在 x86_64 下使用,並不支援 32 位元的架構。

修改 MariaDB 設定檔 /etc/my.cnf

[mariadb]
plugin-load-add = ha_rocksdb
plugin-load-add = ha_mroonga

也可以使用 SQL 指令啟用:

INSTALL SONAME 'ha_mroonga';

重啟 MariaDB 服務後,登入並執行以下指令檢查:

SHOW ENGINES;

相關連結

2026/04/14

C++ Crow

C++ 並不是網頁開發(Web Development)的首選語言, 但是在對效能十分要求或者是需要在資源略為受限的環境執行時,可以考慮使用 C++。 就目前而言,C++ 較為有名的選擇為效能極高並且支援多項功能的 Drogon, 不用安裝依賴函式庫的 Oat++, 以及設計上較為輕量但是功能也較少的 Crow。 還有一個選擇是 Wt, 但是就我個人而言,我認為 Wt 的策略,也就是使用 C++ 撰寫 UI 然後函式庫再轉譯為 HTML/CSS/JavaScript 的方式並不是一個好的做法。

Crow 是一套 C++ micro web framework,採用 Header Only 的設計,其靈感來自於 Python's Flask, 支援 HTTP 1.1 以及 Websocket,使用 C++ ASIO library 構建,特別適合建立 RESTful API 或 Web 服務。 Crow 的原作者在 2017 年停止維護, 不過之後自由軟體社群有人複製出來一份新的分支接手進行維護,目前仍然持續開發中。

在安裝前需要已經先安裝 ASIO development files,下面是在 openSUSE 的安裝指令:

sudo zypper in asio-devel

我使用 source code 安裝:

git clone https://github.com/CrowCpp/Crow.git
mkdir build; cd build; cmake .. -DCROW_BUILD_EXAMPLES=OFF -DCROW_BUILD_TESTS=OFF
sudo make install

(在不編譯範例以及測試程式的情況下,Crow 只會安裝 CMake 相關檔案以及 header files,所以不用執行 make, 只需要使用 make install 安裝)

Crow 預設的靜態檔案資源放置在 static 目錄,但是可以透過巨集設定目錄。接下來寫一個簡單的靜態網頁伺服器驗證可以正確編譯與使用。

main.cpp

#define CROW_STATIC_DIRECTORY "public"
#define CROW_STATIC_ENDPOINT "/<path>"
#include "crow.h"

int main()
{
    crow::SimpleApp app;

    CROW_ROUTE(app, "/")
    ([](const crow::request&, crow::response& res) {
        res.set_static_file_info("public/index.html");
        res.end();
    });

    app.port(18080).run();
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(Simple)

set(CMAKE_CXX_STANDARD 17)

# Search for Crow and required dependencies
find_package(Crow REQUIRED)

add_executable(simple main.cpp)

# Link the Crow library to your executable
target_link_libraries(simple PRIVATE Crow::Crow)

Crow 使用 Mustache 作為 template engine language, 接下建立一個簡單的網頁進行測試。 使用 Mustache 撰寫的網頁需要放在 templates 目錄下。

templates/fancypage.html

<!DOCTYPE html>
<html>
  <body>
  <p>Hello {{person}}!</p>
</body>
</html>

main.cpp

#include "crow.h"
// #include "crow_all.h"

int main() {
    crow::SimpleApp app;

    CROW_ROUTE(app, "/<string>")([](std::string name) {
        auto page = crow::mustache::load("fancypage.html");
        crow::mustache::context ctx({{"person", name}});
        return page.render(ctx);
    });

    app.port(18080).multithreaded().run();
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(Simple)

set(CMAKE_CXX_STANDARD 17)

# Search for Crow and required dependencies
find_package(Crow REQUIRED)

add_executable(simple main.cpp)

# Link the Crow library to your executable
target_link_libraries(simple PRIVATE Crow::Crow)

編譯成功後執行,使用瀏覽器瀏覽 http://localhost:18080/Bob 進行測試。

參考連結