Skip to content

Zeroplex 生活隨筆

軟體開發、伺服器和生活瑣事

小 縮小字型大小。 中 重設字型大小。 大 放大字型大小。

分類: 未分類

在 Linux 建立 SWAP 用檔案

Posted on 2023 年 7 月 14 日2023 年 7 月 16 日 By 日落 在〈在 Linux 建立 SWAP 用檔案〉中尚無留言

以下範例,會建立一個 4GB 的 SWAP 用檔案,並 mount 起來。

建立 4GB 的檔案供 SWAP 使用:

sudo fallocate -l 4G /swapfile
sudo dd if=/dev/zero of=/swapfile bs=1G count=4

# 注意權限必須是 600
sudo chmod 600 /swapfile

檔案格式化為 swapfile:

sudo mkswap /swapfile

到這邊都沒有遇到問題的話,就可以使用 swapon 來讓 Linux mount 起來使用:

sudo swapon /swapfile

如果希望開機以後讓 Linux 自動 mount 起來,可修改 /etc/fstab 檔案:

# <file system>  <mount point>   <type>  <options>   <dump>  <pass>
/swapfile        none            swap    sw          0       0
Tags:Linux

OpenVPN 自訂路由 (route)

Posted on 2023 年 7 月 7 日2023 年 12 月 11 日 By 日落 在〈OpenVPN 自訂路由 (route)〉中尚無留言

OpenVPN 連線成功時,預設會將所有網路流向都導向新建立的 VPN。

若 OpenVPN client 是在 server 上面跑,僅特定連線走 VPN、不應該修改 default gateway,使用 --pull-filter 來忽略 gateway 設定:

sudo openvpn --config connect.cong --pull-filter ignore redirect-gateway

連線以後僅需要特定網段走 VPN,可以在設定檔中加上 push route :

auth-user-pass auth.conf
client
auth SHA1
ignore-unknown-option cipher data-ciphers
....

# 僅 10.3.0.* 的封包改走 VPN
push "route 10.3.0.0 255.255.255.0"

<ca>
-----BEGIN CERTIFICATE-----
Tags:Linux, OpenVPN

cloudbuild.yaml 格式錯誤

Posted on 2023 年 7 月 3 日 By 日落 在〈cloudbuild.yaml 格式錯誤〉中尚無留言

Google Cloud Build error:

failed unmarshalling build config cloudbuild.yaml: json: cannot unmarshal array into Go value of type string

設定檔中並沒有 JSON config,查了半天才知道是 YAML 格式有誤 (I hate YAML)

正確的 cloudbuild.yaml 檔案格式,可以參考 Google Cloud Build configure file schema。

Tags:GCP

在 Eloquent chunk() 刪除資料

Posted on 2023 年 7 月 2 日2023 年 7 月 2 日 By 日落 在〈在 Eloquent chunk() 刪除資料〉中尚無留言

在 Eloquent 中,假設要刪除某使用者的資料:

User::select(['name'])->chunk(100, function ($users) {
    foreach ($users as $user) {
        if ( condition ) {
            $user->delete();
        }
    }
}

以上的寫法,在 $user->delete(),即使 Model 回傳刪除成功,但實際上資料庫的資料不會被刪除。

原因是 Eloquent 刪除資料是以 id 欄位為準,若 select 不包含 id 則會刪除失敗。

在 select() 中加入 id 即可正常刪除資料:

User::select(['id', 'name'])->chunk(100, function ($users) {
    // ....
}

ps. 文件沒寫,fu …..

Tags:Laravel, PHP

apt upgrade 時不詢問

Posted on 2023 年 6 月 27 日 By 日落 在〈apt upgrade 時不詢問〉中尚無留言

原本以為使用 DEBIAN_FRONTEND=noninteractive 參數就可以:

sudo DEBIAN_FRONTEND=noninteractive apt upgrade

後來發現還有個套件叫做 needrestart,預設會在 apt upgrade 完成後詢問哪一些服務要重新啟動:

which services should be restarted

先檢查一下是否有安裝 needrestart,有的話可以看到 /etc/needrestart 目錄。

再去修改設定檔 needrestart.conf:

# Restart mode: (l)ist only, (i)nteractive or (a)utomatically.
#
# ATTENTION: If needrestart is configured to run in interactive mode but is run
# non-interactive (i.e. unattended-upgrades) it will fallback to list only mode.
#
$nrconf{restart} = 'a';

參考資料:

  • How do I ask apt-get to skip any interactive post-install configuration steps?
  • apt-get upgrade auto restart services
Tags:Linux, Ubuntu

文章分頁

上一頁 1 ... 12 13 14 ... 318 下一頁

其他

關於我  (About me)

  文章 RSS Feed

  留言 RSS Feed

Apache AWS Bash C/C++ Docker FreeBSD GCP Git Google Java JavaScript Laravel Linux Microsoft MSSQL MySQL Nginx PHP PHPUnit PostgreSQL Python Qt Ubuntu Unix Vim Web Windows WordPress XD 作業系統 分享 好站推薦 專題 攝影 新奇搞笑 新聞 旅遊 生活雜記 程式設計 網路架站 網頁設計 資訊學習 資訊安全 遊戲 音樂


創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權.