3月 11, 2025

Google Cloud 災難復原

最後處理方式:手動重建 instance

前幾天突然想到 GCP 上跑的機台很舊了(Debian9, 2018),嘗試升級 Debian 10 後就炸了!無法遠端連線(SSH)而且資料庫主程式損毀無法動啟,幸好有留下資料庫檔(.frm/.ibd)。

1. 先到「GCP Compute Engine / 磁碟」複製一份原本的磁碟檔,避免破壞既有資料

2. 建立新的執行個體,主系統選 Debian12 並且額外連接現有磁碟(上述複製碟)

3. 開機掛載分割區,安裝與置換 MariaDB 資料夾
# 新機台安裝資料庫系統並嘗試匯出資料
# apt-get install mariadb-server
# lsblk
# mount /dev/sdb1 /mnt/rescue
# /etc/init.d/mariadb stop
# mv /var/lib/mysql /var/lib/_mysql
# cp -R /mnt/rescue/var/lib/mysql /var/lib/ -R
# chown -R mysql:mysql mysql 
# /etc/init.d/mariadb start
#
# 匯出資料庫檔案
# mysqldump -u db_user -p --default-character-set=utf8 mydb > mydb_backup.sql
4. 維持使用 Debian9 系統 --
「Compute Engine / 映像檔」顯示已淘汰的映像檔,可選擇過期映像檔(debian-9-stretch-v20220621)並建立執行個體

5. 最初掛載 Debian12 到原本 instance 時顯示錯誤訊息 UEFI setting must be the same for the instance and the boot disk. 所以最後只能停留在舊的 Debian9 映像檔;使用 GCP 好處就是 instance 與 disk 是分開的,可以隨意配接取出資料。

12月 26, 2024

Java 透過 Oracle Wallet 連線資料庫

1. 需要準備 Oracle JDBC Drivers full版 (Wallet會用到oraclepki.jar等套件)

2. 編譯方式
D:\jdk17\bin\javac.exe -cp .;D:\ojdbc17-full\ojdbc17.jar OraDBConn.java
D:\jdk17\bin\java.exe  -cp .;D:\ojdbc17-full\ojdbc17.jar OraDBConn
3. 範例程式碼 (OraDBConn.java)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.Statement;

public class OraDBConn {
  public static void main(String[] args) {
    // Database connection information
    String host = "10.18.1.1";
    String port = "1522";
    String serviceName = "SNAME";
    String db_user_id  = "TESTID";
    String db_user_pwd = "2wsx3edc";
    String jdbcUrl = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=" +
                     "(PROTOCOL=TCPS)(HOST=" + host + ")(PORT=" + port + ")))" + 
                     "(CONNECT_DATA=(SERVICE_NAME=" + serviceName + ")))";    
    // Need [cwallet.sso] file for SSO authentication
    System.setProperty("oracle.net.wallet_location", "D:\\wallet");    
    try 
    {
      // Establish a connection using the Oracle Wallet
      Connection connection = 
        DriverManager.getConnection(jdbcUrl, db_user_id, db_user_pwd);     
      System.out.println("Connection established successfully!");
      
      Statement stmt    = connection.createStatement();
      String    sqlcode = "SELECT * FROM OWNER.Table13 WHERE ROWNUM <= 3";
      ResultSet rs      = stmt.executeQuery(sqlcode);           
      while(rs.next())  System.out.println(rs.getString(5) + "\t");
      
      connection.close();
    } 
    catch (SQLException e) { 
      e.printStackTrace(); System.out.println("Failed connect."); }
  }
}

12月 02, 2024

開源遠端桌面閘道(Apache Guacamole)

Apache Guacamole

A clientless remote desktop gateway. It supports standard protocols like VNC, RDP, and SSH. We call it clientless because no plugins or client software are required. Guacamole is installed on a server, all you need to access your desktops is a web browser.

遠端桌面閘道(RD Gateway)支援 RDP 及 SSH 協定;使用者透過瀏覽器可直接存取遠端桌面,無需設定。

11月 26, 2024

新眼鏡 2024

新眼鏡給個版面,跟之前框型好像差不多但輕了一些(眼鏡市場, $4500)

9月 18, 2024

自建 Uptime Kuma 監測平台

安裝 Node.js 與 PM2(Process Management)
# apt-get -y update
# apt-get install -y nodejs npm git
# npm install pm2 -g
# pm2 install pm2-logrotate
安裝 Uptime Kuma
# git clone https://github.com/louislam/uptime-kuma.git
# cd uptime-kuma
# npm run setup
# pm2 start server/server.js --name uptime-kuma
進行初次設定 http://localhost:3001

8月 28, 2024

moto g34 5G 手機

小時候認識的摩托羅拉是 Motorola, Inc.,而現在 (2014 起) 則為聯想集團的全資子公司 Motorola Mobility LLC。雖不若以往強盛,但偶有佳作。

Motorola Moto G34

moto g34 5G 規格

  • 處理器 Snapdragon® 695 5G
  • 作業系統 Android™ 14
  • 儲存空間 64GB、記憶體 4GB
  • 螢幕 6.5 吋、重量 179g、電池 5000mAh
  • 具備 NFC、側邊指紋辨識器、3.5mm 耳機孔

聯想並沒投注太多心力在風格打造,手機介面幾乎就是原生安卓 (Stock Android),這點意味能夠體驗精簡設計,用戶依自身需求安裝軟體。相較於 Pixel 手機而言,除了相機平庸之外,其餘 (CPU 與售價) 皆完美。

7月 13, 2024

Cookies Having Independent Partitioned State (CHIPS)

Cookie 分區儲存,第三方 Cookie 只允許讀取同網域下的內容,無法跨站存取。 

Cookies Having Independent Partitioned State (CHIPS) allows developers to opt a cookie into partitioned storage, with separate cookie jars per top-level site, improving user privacy and security.

Without partitioning, third-party cookies can enable services to track users and join their information from across many unrelated top-level sites. This is known as cross-site tracking.

停用方式:

[Chrome]
在 chrome://flags/ 中更改設定 Third-party Storage Partitioning = Disable

[Firefox]
在 about:config 中更改設定 network.cookie.cookieBehavior 改成 4

愈來愈嚴格!

4月 29, 2024

在 GitHub Codespaces 中運行 CodeIgniter v4.5

因為 CodeIgniter v4.5 需要 PHP 8.1 及 PHP-intl 元件才能運作,原生 GitHub Codespaces 運作 Ubuntu 20.04 LTS 版本,快速解法是直接透過 Personal Package Archives(PPA) 補齊新版套件,並把環境鏈結刪除(current),最後再用 composer 把 CodeIgniter 裝起來。

[啟用第三方套件庫]
# add-apt-repository ppa:ondrej/php
# apt install php8.3-{cli,intl,curl,mbstring,mysql,sqlite3,gd} phpunit

[確定當前PHP呼叫路徑]
# which php
# 可能是 /home/codespace/.php/current/bin/php
# 或者是 /usr/local/php/current/bin/php

[重新建立鏈結(current),最新版位於 /usr/bin/php8.3]
# rm /home/codespace/.php/current
# rm /usr/local/php/current
# ln -s /usr /home/codespace/.php/current
# ln -s /usr /usr/local/php/current
# 執行 php --ini 或 php -m 驗證環境

[安裝資料庫]
# apt install mariadb-server
# /etc/init.d/mysql start
# mysql_secure_installation

4月 15, 2024

Redmi Note 13 Pro 5G

Redmi Note 13 Pro 5G ($8,990)

  • 處理器:Qualcomm Snapdragon 7s Gen 2
  • SIM卡:5G + 5G
  • 螢幕:6.67 吋
  • 重量:187g
  • 螢幕指紋辨識、支援 NFC、3.5mm 耳機孔

1月 04, 2024

常用 git 指令與自建 Gitea Server

在 Windows 環境下
  • git 個人設定值存放於 C:\Users\account\.gitconfig
  • ssh 個人公私錀存放於 C:\Users\account\.ssh\
如果要產生公私錀,可以透過 PowerShell 執行 ssh-keygen

初始資訊設定(作者名與郵件)與查看設定值:
git config --global user.name "Foo Bar"
git config --global user.email foo@bar.com

git config --global --list
git config --global --list --show-origin
git 上傳方式有 HTTPS 與 SSH 兩種:

1. 透過 HTTPS 傳輸相對簡單,直接將帳號密碼附在 URL 內即可,但因有密碼外露問題,所以 GitHub 採用 Personal access tokens 作為取代;這是一個短天期的通關碼(token),讓共同參與成員可以對源碼庫進行操作,首次上傳會出現提示要求輸入通關碼
2. 使用 SSH 應當是較為安全的管道,在原始碼上傳前,需預先部署公鑰在遠端伺服器(GitHub或Gitea),本地端推送(PULL)時則出示私鑰進行授權。所以記得使用 ssh-keygen 產生公私鑰放在家目錄 [.ssh] 資料夾。

[HTTPS]
git init
git checkout -b main                                   // 建立並切換到 main 分支
git add .                                              // 加入檔案到 staging
git commit -m "first commit"                           // 加到本地 repository
git remote add origin https://example.com/user/foo.git // git remote add [remote-name] [remote-url]
git push -u origin main                                // 推送本地分支(main)到遠端位址(origin)
[SSH]
git init
git checkout -b main
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:user/foo.git      // 透過 SSH 上傳需佈建公鑰(id_rsa.pub)在遠端
git push -u origin main
[其他常用指令]
git log  // 列出提交歷史
git status  // 列出狀態
git remote -v  // 列出遠端位址
git remote set-url origin   // 更改遠端倉庫位址對應