2023/01/10

前一陣子發生了一件很OX的事

試了很久 現在做個記錄

因為有幫別的部門架了一台proxmox

而且那個部門也有一台nas

因此我就在那台nas上開了nfs然後用pbs備份

他老兄在某一天竟然進到nas把我備分用的那個nfs裡的資料砍了

然後第二天就出現了如下的error

ProxmoxBackup Server 2.3-2

2022-12-29T00:00:00+08:00: starting garbage collection on store nfs418

2022-12-29T00:00:00+08:00: task triggered by schedule 'daily'

2022-12-29T00:00:00+08:00: Start GC phase1 (mark used chunks)

2022-12-29T00:01:03+08:00: marked 5% (1 of 17 index files)

2022-12-29T00:04:14+08:00: marked 11% (2 of 17 index files)

2022-12-29T00:04:14+08:00: WARN: warning: unable to access non-existent chunk c3fe251560dcd2cc5aef7cfbd6669d0dd9ca7491c455f537efc6d319b09892ec, required by "/mnt/nfs418/vm/108/2022-12-27T15:45:38Z/drive-virtio0.img.fidx"

2022-12-29T00:04:14+08:00: WARN: warning: unable to access non-existent chunk 6dc29793341c20c7c80910a73893501b034a0e29c14a444d214d835ccffc0d16, required by "/mnt/nfs418/vm/108/2022-12-27T15:45:38Z/drive-virtio0.img.fidx"

2022-12-29T00:04:14+08:00: WARN: warning: unable to access non-existent chunk 1f81c244f9b7816ab37d3ef7ffdcd10443eb1bddb3fa44e036186b73f1fee33a, required by "/mnt/nfs418/vm/108/2022-12-27T15:45:38Z/drive-virtio0.img.fidx"

2022-12-29T00:04:14+08:00: WARN: warning: unable to access non-existent chunk 95c7e6747d43b5b516e1768a1f258f352aeb47b23fd46575440dc3d820d1b253, required by "/mnt/nfs418/vm/108/2022-12-27T15:45:38Z/drive-virtio0.img.fidx"

2022-12-29T00:04:14+08:00: WARN: warning: unable to access non-existent chunk 9513a7e5c650245d3344115115b21285cc8f426e5284fa04159ea96e49856535, required by "/mnt/nfs418/vm/108/2022-12-27T15:45:38Z/drive-virtio0.img.fidx"

2022-12-29T00:04:14+08:00: WARN: warning: unable to access non-existent chunk 68b2b40dd3bacba9e649c67862011934bc7f048d8ea2d35fbd95c39f9d5cf7c4, required by "/mnt/nfs418/vm/108/2022-12-27T15:45:38Z/drive-virtio0.img.fidx"

2022-12-29T00:04:14+08:00: WARN: warning: unable to access non-existent chunk 494608d49f57039fd7a8378e1a2a2cf6bb0688773a525addc2f54507a94cd11d, required by "/mnt/nfs418/vm/108/2022-12-27T15:45:38Z/drive-virtio0.img.fidx"

2022-12-29T00:04:14+08:00: WARN: warning: unable to access non-existent chunk 09eab384d5f3cbf657db1c0750ef52be2f1dbdf134f977a24dc095382b6e25ed, required by "/mnt/nfs418/vm/108/2022-12-27T15:45:38Z/drive-virtio0.img.fidx"

2022-12-29T00:04:14+08:00: WARN: warning: unable to access non-existent chunk 9c1208d43242276c75a4f65f41054e4bc0e7e1144a61c951902bb8df94f055c9, required by "/mnt/nfs418/vm/108/2022-12-27T15:45:38Z/drive-virtio0.img.fidx" 

..........................................

後面還一大堆

本來是想說把pbs上的datastore砍了重建應該可以解決問題

forum上也是醬說的

結果不是

我砍了datastore重建

甚至在nas上再開另一個nfs後再重建datastore

過沒几天又會出現如上的錯誤

最後的解決方法是直接重裝一台新的pbs

問題才解決

無言中

2023/01/07

在一台几器上使用mutt寄信時出現

SMTP session failed: 502 5.5.2 Error: command not recognized


到mail server上看log


Jan  7 05:39:01 mail postfix/smtpd[1874477]: improper command pipelining after EHLO from unknown[10.0.01]: hostabc\r\n

感覺好像是hostname的問題

於是在 .muttrc 裡加上一行

set hostname=myhost


就ok了

2022/12/29

最近換了新環控系統

因為是跑在win上資料放在 mssql

所以要去把告警資料撈出來用line傳送

在linux上要先安裝 sqlcmd 

m$官方有提供安裝文件如下

安裝完成後會放在

/opt/mssql-tools/bin/

連線語法如下

/opt/mssql-tools/bin/sqlcmd -S 10.1.2.3 -U sa -P 'passwd' -d dbname

連線成功會出現

1>

指令下完要記得 再下 go 才能執行

一些基本指令

顯示所有資料庫

SELECT Name from sys.databases


使用資料庫

use daname


顯示db的所有資料表

SELECT * FROM Information_Schema.TABLES


顯示table schema

sp_help tablename


只顯示前 n 筆資料

select top n * from alarmhistory


找出最近時間的資料

select max(time_col) from table


備分資料庫

只能備到server本几的HD或UNC 路徑


sqlcmd -S 10.1.2.3 -U sa -P 'password' -Q "BACKUP DATABASE dbname TO DISK = '\\%tmp%\Report.bak' WITH NOFORMAT, NOINIT, NAME = 'dbname-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10"

 

https://learn.microsoft.com/zh-tw/sql/linux/sql-server-linux-setup-tools?view=sql-server-ver16#RHEL

2022/12/27

今天有人問個問題
需要創建大量目錄
但目錄名稱有簡体字
本來想說應該沒什麼
結果一跑才知道在dos模式utf-8顯示會有問題
而無法建立
所以批次檔要加上

chcp 65001

才行

範例如下

%echo off

chcp 65001

for /f %%a in (data) do (
    echo %%a
    md %%a
)


2022/12/21

這几天試了一下 mosh
主要是在網路環境不佳時
使用ssh可以減少lag的情況
尤其是在4G或wifi時
在不特定 client ip 的情況下建議使用 ssh key認証
只要在server 端安裝 mosh 就可以
apt install mosh

client 端連線要選擇支援mosh的軟体

mobaxterm

JuiceSSH

這二個都有支援

client端發起連線就會自動呼叫 server端的 mosh
所以server端不用起daemon或事先執行

2022/12/20

今天更新 debian
直接下完
apt update
apt upgrade -y 後
librenms就打不開了
跑了 ./daily.sh 
出現

Updating to latest codebase                        OK
Updating Composer packages                         FAIL
> LibreNMS\ComposerHelper::preInstall
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.

  Problem 1
    - fgrosse/phpasn1 is locked to version v2.4.0 and an update of this package was not requested.
    - fgrosse/phpasn1 v2.4.0 requires php ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0 -> your php version (8.2.0) does not satisfy that requirement.
  Problem 2
    - fgrosse/phpasn1 v2.4.0 requires php ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0 -> your php version (8.2.0) does not satisfy that requirement.
    - web-token/jwt-core v2.2.11 requires fgrosse/phpasn1 ^2.0 -> satisfiable by fgrosse/phpasn1[v2.4.0].
    - web-token/jwt-core is locked to version v2.2.11 and an update of this package was not requested.
Updated from ae22662c8 to 1ab238a4d                OK
Updating SQL-Schema                                OK
Updating submodules                                OK
Cleaning up DB                                     OK
Fetching notifications                             OK
Caching PeeringDB data                             OK
Caching Mac OUI data                               OK

看來是php不能升到 8.2

只能倒回備分
再排除以下的更新 

php-cli/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]
php-common/bullseye 2:93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:93+0~20221029.44+debian11~1.gbpaae3e9]
php-curl/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]
php-fpm/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]
php-gd/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]
php-gmp/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]
php-json/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]
php-mbstring/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]
php-mysql/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]
php-pear/bullseye 1:1.10.13+submodules+notgz+2022032202-2+0~20221209.38+debian11~1.gbpfd4c1d all [upgradable from: 1:1.10.13+submodules+notgz+2022032202-2+0~20220330.37+debian11~1.gbpfd4c1d]
php-snmp/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]
php-xml/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]
php-zip/bullseye 2:8.2+93+0~20221211.45+debian11~1.gbpdb4dcc all [upgradable from: 2:8.1+93+0~20221029.44+debian11~1.gbpaae3e9]

再來把以上的package hold住 不要更新
指令如下

Hold a package:

sudo apt-mark hold <package-name>
Remove the hold:

sudo apt-mark unhold <package-name>
Show all packages on hold:

sudo apt-mark showhold

指令下完後 apt upgrade 時就不會更新

不過如果是下 apt install 還是會更新 此時就不受 hold影響 要特別注意


2022/12/16

graylog 迎來了5 版的更新

依然還是無法原几升級

記錄一下安裝的過程 以debian 11 為例

依照官方文件的流程 先裝mongodb

由於新版的mongodb需要使用 cpu 的 avx 功能

所以proxmox 上 guest的 cpu type 必須要改成 host 不能使用 預設值 kvm64

光是這個問題就卡關好久

而且mongodb 5版裝完後無法執行 6 版沒問題

接下來新的版本可以選擇使用 

OpenSearch 或 Elasticsearch

我是選擇 Elasticsearch

第三步是安裝 graylog server

安裝後調整參數

/etc/elasticsearch/jvm.options 這個檔

-Xms8g
-Xmx8g

以上的參數依照記憶体進行調整


/etc/default/graylog-server 檔案裡

GRAYLOG_SERVER_JAVA_OPTS="-Xms1g -Xmx1g -server -XX:+UseG1GC -XX:-OmitStackTraceInFastThrow"


-Xms1g -Xmx1g

這二個參數也是依照記憶体進行調整


其他依文件安裝問題不大

不過文件上有些斷行有問題 需要自行調整

例如

wget -qO - https://www.mongodb.org/static/pgp/server-5.x.asc | sudo apt-key add -

echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.x main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.x.list

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -


echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list


另外使用almalinux 8 跟 9 安裝過程沒有出現錯誤 但 graylog server 啟動打開管理介面

出現以下的錯誤



Error Loading active authentication service type failed with status: SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data

不知道是那裡出問題 有空再來試了

找到問題了 firewalld 沒關

systemctl disable firewalld

systemctl stop firewalld


https://go2docs.graylog.org/5-0/what_is_graylog/what_is_graylog.htm


2022/11/24

proxmox mail gateway 把信放入隔離區後預設每天會發報表通知給user











如果不想讓user收到通知

要改成以下的設定



2022/11/20

最近在使用ultravnc single click的時候

發現連線後在client 執行大部分的程式都無法正常操作

試了好几台都一樣

便想說重新再產生一次看看

下載原先的執行程式 

解開後只留下 helpdesk.txt 及 logo.bmp 這二個檔

再來把這二個檔壓縮成zip

例如 jghdfkjg.zip

再利用這個zip上傳產生新的連線程式

https://uvnc.com/products/uvnc-sc/78-ultravnc-sc-online-creator.html

使用網頁最下方的產生器

再使用這個新產生的連線程式連線

目前看來正常

再觀察看看


https://uvnc.com/products/uvnc-sc.html

https://uvnc.com/docs/uvnc-sc/73-howto-create.html

https://uvnc.com/download/custom.zip

https://uvnc.com/products/uvnc-sc/78-ultravnc-sc-online-creator.html


2022/09/30

最近登入librenms時出現以下提示




 




目前使用的這個版本是從官網下載ubunbu 20.04 ova

試著升級但升完後有很多問題

於是打算重裝

選定debian 11 

依照官網的流程一步步順利裝完

再來依照官方FAQ的方式移轉

也順利完成

最後有問題的是weathermap

如果直接copy ubuntu 20.04的目錄過來會發生無法執行的情況

不過官方已有針對php 8.1 進行修改

所以直接 git clone

git clone https://github.com/librenms-plugins/Weathermap.git

再mv目錄 

mv Weathermap /opt/librenms/html/plugins/

把原几的 conf 複制到以下目錄

/opt/librenms/html/plugins/Weathermap/configs


以上就大致完成了

目前觀察中 看看還有沒有其他問題


https://github.com/librenms/packer-builds/releases/tag/21.2.0


https://www.librenms.org/#downloads


https://docs.librenms.org/Installation/Install-LibreNMS/#prepare-linux-server


https://docs.librenms.org/Support/FAQ/#how-do-i-migrate-my-librenms-install-to-another-server

2022/09/10

今天想使用 line 發群組通知

首先申請權杖

 

官方文件範例是使用 curl


$ curl -X POST -H 'Authorization: Bearer <access_token>' -F 'message=foobar' \

https://notify-api.line.me/api/notify

 

但試了半天發現一個問題 就是 message 無法換行 

找了好久才找到 範例如下


第一個方法


curl -X POST      -H 'Authorization: Bearer (your token)'      --data-binary message="%0A中文%0A123%0Aabc%0A456"      https://notify-api.line.me/api/notify


第二個方法

curl -X POST    -H 'Authorization: Bearer (your token)'   -d $'message=123\nabc'  https://notify-api.line.me/api/notify


使用python範例如下

檔名存為 line_notify.py

檔案內容如下


import requests

import sys


f = open(sys.argv[1])

msg = f.read()

f.close


def lineNotify(token, msg):

    url = "https://notify-api.line.me/api/notify"

    headers = {

        "Authorization": "Bearer " + token

    }

    payload = {'message': msg}

    r = requests.post(url, headers=headers, data=payload)

    return r.status_code


token = "your token"

lineNotify(token, msg)


只要指定檔案發送
檔案內是什麼內容
發送就是什麼內容

用法

python line_notify.py /tmp/txt_to_send


https://xenby.com/b/274-%E6%95%99%E5%AD%B8-%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8-line-notify-%E5%B0%8D%E7%BE%A4%E7%B5%84%E9%80%B2%E8%A1%8C%E9%80%9A%E7%9F%A5


https://officeguide.cc/python-line-notify-send-messages-images-tutorial-examples/


https://fm-aid.com/bbs2/viewtopic.php?pid=52815


https://notify-bot.line.me/zh_TW/


https://notify-bot.line.me/doc/en/

2022/08/17

centos 7 升級至 almalinux 8 流程



yum install -y http://repo.almalinux.org/elevate/elevate-release-latest-el7.noarch.rpm

yum install -y leapp-upgrade leapp-data-almalinux

leapp preupgrade

rmmod pata_acpi
rmmod floppy
echo PermitRootLogin yes | sudo tee -a /etc/ssh/sshd_config
leapp answer --section remove_pam_pkcs11_module_check.confirm=True

#check any package need to remove if still error


leapp preupgrade


leapp upgrade

2022/07/29

說明一下如何在almalinux 8 上備分資料到 proxmox backup server(pbs)

先在 pbs 上 建立一個 datastore test

到以下網站下載rpm進行安裝

https://github.com/sg4r/proxmox-backup-client

先安裝相依套件

dnf install fuse3

接下來

rpm -Uhv proxmox-backup-2.2.2-1.x86_64.rpm 


安裝完成後執行以下指令

proxmox-backup-client login --repository root@pam@10.0.0.1:8007:test

匯入 fingerprints


如果要備份 /root

建立以下shell 

#!/bin/bash

export PBS_PASSWORD="password"

proxmox-backup-client backup aaa.pxar:/root --repository root@pam@10.0.0.1:8007:test


列出備份資料

proxmox-backup-client snapshot list --repository root@pam@10.0.0.1:8007:test


復原備分資料

proxmox-backup-client restore  --repository root@pam@10.0.0.1:8007:test host/test-pbs-almalinux8/2022-07-29T06:23:05Z aaa.pxar /tmp/test



https://www.coderstudy.co/zh-Hant/article/19cs1_1anq7.html

pvesh

跨 proxmox node 下指令的好用工具

如果要把其他節點的guest開几 指令如下

pvesh create /nodes/<nodeid>/qemu/<vmid>/status/start


https://pve.proxmox.com/pve-docs/pvesh.1.html

http://blog.jason.tools/2019/02/pve-cli-api.html



2022/07/28

今天早ntop 更新出現以下問題 應該是key 過期了

Failed to fetch https://packages.ntop.org/apt-stable/20.04/x64/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3D84C955924F7599


參考
https://packages.ntop.org/apt-stable/


重新下載再安裝一次
wget https://packages.ntop.org/apt-stable/20.04/all/apt-ntop-stable.deb 

apt install ./apt-ntop-stable.deb

目前正常
再觀察看看

2022/07/27

在raspberry pi 4 上安裝 ubuntu mate 後

聲音預設是從耳几孔輸出

可以安裝一個方便的程式來進行調整由hdmi輸出


sudo apt-add-repository ppa:yktooo/ppa -y 

sudo apt-get update 

sudo apt-get install indicator-sound-switcher -y


https://github.com/yktoo/indicator-sound-switcher

https://www.youtube.com/watch?v=XFNeLzfGB-o

2022/07/13

今天安裝完zeek 一直無法啟動
使用zeekctl
start 後還是不行
接下來使用diag 去看 出現錯誤訊息
查了一下 有人說要先deploy
在 zeekctl 裡下完deploy後就正常了

原來官方說明就有寫了 XD

今天有三台 windows server  在更新完成重開時就一直卡在更新中請勿關閉電腦的畫面
強制重開机也沒用
有朋友說重開在安全模式看看
果然開几按F8重開在安全模式後
顯示更新未成功 進行復原
復原完成再重開回正常模式
之後再手動做一次 windows update
就正常了
同樣的情況發生二次了
目前也找不到原因