2024年6月7日 星期五
ESXi find what process lock file
ESXi 檔案刪不掉,出現 Device or resource busy
若檔案名稱是 windows-10-flat.vmdk
下此指令就可以知道那邊佔用
ps | grep `lsof | awk '/windows-10-flat.vmdk/ {print $1}'`
另外這個指令可以顯示機器名稱與 datastore 的檔案對應,
vim-cmd vmsvc/getallvms
改機器名稱,datastore 的檔案不會跟著改名,有可能出現與目錄名稱不一致的情況
2024年4月28日 星期日
Eazy way to install OpenWrt
隨便找一片 Linux ISO 開到 rescue 模式
fdisk -l 看一下硬碟位置,如果是 /dev/sda
curl https://repo.jing.rocks/openwrt/releases/23.05.3/targets/x86/generic/openwrt-23.05.3-x86-generic-generic-ext4-combined.img.gz | zcat > /dev/sda
一行解決,然後重開就可以了
上面的網址是 Japan Mirror 的網址,其他可參考 OpenWrt Downloads
Codeit repo for EL8/EL9
用這個 repo 的主要是要使用最新版的 Apache 或 nginx
dnf -y install https://repo.codeit.guru/codeit-repo-release.el8.rpm
or
dnf -y install https://repo.codeit.guru/codeit-repo-release.el9.rpm
dnf -y module reset httpd
dnf -y module enable httpd:codeit
若是從舊版升級上來,ssl error log 可能看到這樣的錯誤,服務起不來
AH01898: Unable to configure permitted SSL ciphers
SSL Library Error: error:0A0000B9:SSL routines::no cipher match
需要調整 ssl.conf 這兩行的設定
SSLCipherSuite "EECDH+AES128:EECDH+AES256:+SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RSA+3DES:!DSS"
SSLProxyCipherSuite "EECDH+AES128:EECDH+AES256:+SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RSA+3DES:!DSS"
原本是
SSLCipherSuite PROFILE=SYSTEM
SSLProxyCipherSuite PROFILE=SYSTEM
ref. CodeIT Technical blog
2024年4月21日 星期日
Stunnel
Stunnel 有點像 SSH tunnel,可以建立加密通道
原本未加密的協議,讓它走 Stunnel,就可以達到不改變協議,數據有加密的效果
以下用一個實例說明:
A 要 telnet B,IP 12.34.56.78,因 telnet 協議本身未加密,
若要讓 A 到 B 的傳輸數據加密,此時就可以用 Stunnel
建立憑證
cd /etc/stunnel
openssl req -new -x509 -days 9999 -nodes -out stunnel.pem -keyout stunnel.key
把 stunnel.pem 及 stunnel.key copy 到另一台
A 要配置 Stunnel client
/etc/stunnel/stunnel.conf 內容如下
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.key
client = yes
[telnet]
accept = 23
connect = 12.34.56.78:2323
B 要配置 Stunnel server
/etc/stunnel/stunnel.conf 內容如下
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.key
client = no
[telnet]
accept = 2323
connect = 127.0.0.1:23
配置後兩邊啟動服務
systemctl enable stunnel --now
在 A 就可以 telnet localhost (取代直連 telnet 12.34.56.78),
然後封包加密,送到 12.34.56.78:2323,
B 收到封包後解密,再送給 localhost:23
2024年4月16日 星期二
OpenVPN disconnect after 3.4.0
狀況是連上又斷線,一直重複 (repeat connect and disconnect)
我的環境 RouterOS 6.49.14 及 7.14.2 都遇到此狀況
很可能就是以下原因
OpenVPN Client 在 3.4.0 新增了一個功能 Security Level
Settings / ADVANCED SETTINGS (at bottom)
預設值是 Legacy
如果本來可以連,升版後不能連,把這邊改成 Insecure 可能就能連了
此功能將一些已不安全的協定禁用,若 Server 端暫時沒有新的支援,
Workaround 只能選 Insecure,不然就使用 3.3.7 版 ,意思一樣。
2024年4月4日 星期四
Chrome for Testing and Chromedriver
本文主拿它在 Linux 上跑 Chromedriver,當作爬蟲用途,
它是真的執行瀏覽器來跑結果,所以只要是瀏覽器可以看得到的,都爬得到
環境是 Rocky Linux 9,使用預設 GDM
# 建立環境
cd /tmp
wget https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.86/linux64/chrome-linux64.zip
wget https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.86/linux64/chromedriver-linux64.zip
cd /usr/local
unzip /tmp/chrome-linux64.zip
unzip /tmp/chromedriver-linux64.zip
cd /usr/bin
ln -s /usr/local/chromedriver-linux64/chromedriver .
ln -s /usr/local/chrome-linux64/chrome .
# 建立 chromdriver 啟動腳本
echo '#!/bin/bash' > /usr/local/bin/chromedriver.sh
echo 'chromedriver --log-path=/dev/shm/chromedriver.log --verbose --append-log --readable-timestamp --whitelisted-ips >> /dev/shm/chromedriver.output 2>&1 &' >> /usr/local/bin/chromedriver.sh
chmod 755 /usr/local/bin/chromedriver.sh
# 設定 GDM 登入後啟動上面的腳本,這邊的 username 請代換成自己的登入名稱
echo '#!/bin/bash' > /etc/gdm/PostLogin/Default
echo 'export DISPLAY=:0' >> /etc/gdm/PostLogin/Default
echo 'su pank /usr/local/bin/chromedriver.sh > /dev/null &' >> /etc/gdm/PostLogin/Default
chmod 755 /etc/gdm/PostLogin/Default
# 設定 iptables 可以導到 Local Port,for 外部 call API 用
echo net.ipv4.conf.all.route_localnet=1 >> /etc/sysctl.conf
sysctl -p
iptables -t nat -A PREROUTING -p tcp --dport 9515 -j DNAT --to 127.0.0.1:9515
到這邊建立完成,已可以另一台電腦調用上面建立的 Chrome 資源,
這邊使用 php-webdriver 測試,抓取 Bing 的網頁
composer require php-webdriver/webdriver
<?php
require __DIR__."/vendor/autoload.php";
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\WebDriverExpectedCondition;
$serverUrl = 'http://192.168.1.10:9515';
$driver = RemoteWebDriver::create($serverUrl, DesiredCapabilities::chrome());
$driver->get('https://bing.com');
$driver->wait(10,200)->until(WebDriverExpectedCondition::titleIs('Bing'));
echo $driver->getPageSource();
$driver->quit();
?>
2024年3月29日 星期五
Linux ping report no answer
有掉包的話比較清楚
# ping -O 192.168.1.8
PING 192.168.1.8 (192.168.1.8) 56(84) bytes of data.
64 bytes from 192.168.1.8: icmp_seq=1 ttl=64 time=0.347 ms
64 bytes from 192.168.1.8: icmp_seq=2 ttl=64 time=0.237 ms
no answer yet for icmp_seq=3
no answer yet for icmp_seq=4
64 bytes from 192.168.1.8: icmp_seq=5 ttl=64 time=0.224 ms
64 bytes from 192.168.1.8: icmp_seq=6 ttl=64 time=0.213 ms
再加 -D 參數可以在前面印出時間,可惜是 UNIX timestamp 格式,不方便直接讀取
# ping -DO 192.168.1.8
PING 192.168.1.8 (192.168.1.8) 56(84) bytes of data.
[1711724576.274247] 64 bytes from 192.168.1.8: icmp_seq=1 ttl=64 time=0.254 ms
[1711724577.288744] 64 bytes from 192.168.1.8: icmp_seq=2 ttl=64 time=0.225 ms
[1711724578.312747] 64 bytes from 192.168.1.8: icmp_seq=3 ttl=64 time=0.220 ms
若要在前面加入時間,推薦用 ts,在 moreutils 套件內,它是個 Perl 腳本,可搭配任何程式使用
# ping -O 192.168.1.8 | ts
Mar 29 23:08:25 PING 192.168.1.8 (192.168.1.8) 56(84) bytes of data.
Mar 29 23:08:25 64 bytes from 192.168.1.8: icmp_seq=1 ttl=64 time=0.257 ms
Mar 29 23:08:26 64 bytes from 192.168.1.8: icmp_seq=2 ttl=64 time=0.239 ms
Mar 29 23:08:27 64 bytes from 192.168.1.8: icmp_seq=3 ttl=64 time=0.240 ms
iptables hashlimit
iptables -A FORWARD -d 192.168.0.0/16 -m hashlimit --hashlimit-name download --hashlimit-mode dstip --hashlimit-above 2048kb/s -j DROP
iptables -A FORWARD -s 192.168.0.0/16 -m hashlimit --hashlimit-name upload --hashlimit-mode srcip --hashlimit-above 1024kb/s -j DROP
第1行,下載規則,當目的是內網時, 以 dstip 分類,限速 2048kbytes/s = 16Mbps
第2行,上傳規則,當來源是內網時, 以 srcip 分類,限速 1048kbytes/s = 8Mbps
效果: 內網每個 IP 都享有 16Mbps/8Mbps 頻寬。測速會超過一些,誤差在 10% 內,還算滿準的。
ref. man iptables-extensions
2024年3月21日 星期四
RHEL 9 install xrdp
它運作時需要 Xvnc 的 libvnc.so, 所以安裝時需要連同 VNC 一起安裝(只需 minimal)
dnf -y install xrdp tigervnc-server-minimal
systemctl enable xrdp --now
在 Rocky Linux 9 的環境,有遇到登入後立即斷線的狀況,似乎是 gdm 的問題,換成 lightdm 就正常了
dnf -y install lightdm
systemctl disable gdm --now
systemctl enable lightdm --now
2024年3月14日 星期四
DNS negative cache
DNS 也會 cache 這個查不到的結果,其預設的 TTL 跟 DNS 及 Zone 的 SOA TTL 有關
例如 BIND 的 max-ncache-ttl 預設是 10800 秒
當 SOA 中的 TTL 小於 DNS 的 ncache-ttl,會看 SOA 中的 TTL
某些情境,需要比較快速查到最新資料,需要縮短這個值,BIND 的 max-ncache-ttl 可以設 0
也就是 disable negative cache,遇到 NXDOMAIN 都不 cache
這樣設定的話,本來沒設定的域名,設了解析後就可以馬上查到,公用服務的 DNS 不建議這樣設定
2024年2月22日 星期四
Install w3m in Rocky Linux
未啟用前安裝會出現此錯誤
- nothing provides perl(NKF) needed by w3m-0.5.3-60.git20230121.el8.x86_64 from epel
啟用 powertools repo 指令
dnf config-manager --set-enabled powertools
dnf -y install w3m
2024年1月20日 星期六
Han River Running Place 2024 (潭子旱溪大操場)
現在旱溪西路從松竹路口往北,過南興北二路一點點,自行車道就沒了,只有 1.2K。
附圖潭興路以北區塊,就是小一點的潭子旱溪大操場,一圈 3.3K。
地圖的右下角綠色起點右側是聚興福德爺廟,有飲水機可以喝水,也有厠所,需過馬路。
根據台中市政府的公告,會將犧牲掉的自行車道再補回來,期待旱溪大操場早日回歸
「市府觀旅局已將自行車道改道至旱溪東路,目前也積極爭取中央補助計畫,新設自行車道併同人行道整體規劃,
預計建置於旱溪西路堤頂上,透過分階段調整的方式,將原有旱溪西路的道路環境做更完善的規劃。」
ESXi find what process lock file
ESXi 檔案刪不掉,出現 Device or resource busy 若檔案名稱是 windows-10-flat.vmdk 下此指令就可以知道那邊佔用 ps | grep `lsof | awk '/windows-10-flat.vmdk/ {print $1...
-
以前都是用 rp-pppoe 套件裡的 adsl-setup 來設定 PPPoE 現在比較新的 Linux 已經沒有這個套件了,要用 NetworkManager 的 nmcli 來設定 設定也很簡單,準備帳號、密碼及網路卡就行了 以下範例帳號是 xxxx@hinet.net 密...
-
禁止 LINE 電腦版自動或強制更新的方法 LINE 電腦版啟動都會去連這個更新資訊檔 https://desktop.line-scdn.net/win/v1/real/update_info.json 內容大概長這樣 可以看出針對各版本的更新 type 有 force, ...
-
電腦不符合 Windows 11 需求,也可以安裝 Windows 11 安裝流程第一個畫面按 Shift-F10 開啟 CMD 下指令 reg add HKLM\System\Setup\LabConfig /v "BypassTPMCheck" /t RE...
-
openfortivpn 和 FortiClient VPN 相容,若不想用官方的 Client 可以試試 只是它是命令列模式,沒有 GUI 使用很簡單 openfortivpn vpn-gateway:8443 -u username 然後會提示輸入 Password 若憑...
-
RouterOS 的管理工具 winbox,因為還不支援 UTF-8, 雖然可以在 Wireless 設定中文的 SSID,但是實際上會看到亂碼, WiFi 的 SSID 是走 UTF-8 編碼,需要把 UTF-8 中文轉成 HEX 碼,再用指令設定 寫了一個小工具提供大家使用...
-
xrdp 是 Linux 版的 RDP server (遠端桌面) 它運作時需要 Xvnc 的 libvnc.so, 所以安裝時需要連同 VNC 一起安裝(只需 minimal) dnf -y install xrdp tigervnc-server-minimal system...
-
現在自架的 Mail Server 若沒有簽章,寄出的信件有很大的機會被擋或歸類在垃圾信 所以 SPF + DKIM 已經是必要的設定 環境 CentOS + Postfix,文中的域名均以 yourdomain.com 作為範例 安裝所需套件 yum -y install py...
-
比較舊版的電視盒,無法裝新版的 Kodi , Android 4.x 版只能裝到 16.1 這個版本 kodi-16.1-Jarvis-armeabi-v7a.apk
-
禁止 LINE 電腦版傳送連線診斷報告 當把 desktop.line-scdn.net 擋掉時 (ref. Disable LINE desktop force update ), LINE 會傳送連線診斷報告到 nelo2-col.linecorp.com, 內容 body ...
-
Windows 的 NFS Client 從 Windows 7 之後就內建了,但預設沒有開啟, 要到 設定 / 應用程式 / 程式與功能 / 開啟或關閉 Windows 功能 開啟 Client for NFS 但是預設的情況下,遇到中文檔名會有亂碼, 到 設定 / 時間與語言...