CentOS 7 docker 防火牆設定

CentOS 7安裝docker之後, 要確認防火牆是否阻擋不需要對外的container

iptables -I DOCKER 1 -i <對外網卡介面名稱>  -p tcp  --dport <埠號碼> -j DROP
# example
# iptables -I DOCKER 1 -i ens19 -p tcp --dport 4822 -j DROP

之前一直以為firewall-cmd 預設都會擋下來, 沒想到docker安裝後,container 似乎都開放了, 看起來還是要小心為妙

2023/09/06

後來發現還是無法阻止外面連到container port 這很奇怪,可能我是早期的docker 20.10.x ,最後追加以下指令直接阻擋container ip

firewall-cmd --direct --add-rule ipv4 filter DOCKER 0 -i eth0 -d 172.0.0.0/8 -j DROP

安裝自己的照片管理軟體-piwigo

這陣子研究清末明初古幣, 於是想起乾脆架設一個照片管理服務器(self hosting), 功能也不用太多, 有hash tag, 搜尋功能也不是很需要, 試用了一款最有名的 https://photoprism.app/ 發現功能太多, 還有AI自動辨識功能, 不符合我的需求.

最後終於找到簡單好用的 https://piwigo.org/ piwigo也有docker版本, 真是太棒了.

我架設了錢幣照片管理網站 – 布書 , 有不輸之意, 古代為錢之意.

安裝piwigo非常簡單

  • 先準備好mysql 這個container, 底下範例,名字叫做 my-mariadb
  • 指令如下, 請注意紅色部分需修改
docker volume create piwigo_config
docker volume create piwigo_gallery

docker run -d  --restart always --name=piwigo --link  my-mariadb:mysql -e PUID=1000 -e PGID=1000 -e TZ=Asia/Taipei -p 2342:80 -v piwigo_config:/config -v  piwigo_gallery:/gallery --restart unless-stopped  lscr.io/linuxserver/piwigo:12.3.0
  • 登入 http://ip:2342
    數據庫輸入mysql , 對應到以上指令中的 –link my-mariadb:mysql
    再輸入該資料庫的帳號密碼, 以及資料庫名稱(這部分我是先創建好資料庫, 沒試過未創建是否自己建立)
    加上 httpd 反向代理, 這樣就大功告成了

更改預設頁面,例如改成tags, docker 進入container, 修改設定檔案

cd /gallery/local/config
vi /gallery/local/config/config.inc.php
############################
$conf['random_index_redirect'] = array(
PHPWG_ROOT_PATH.'tags.php' => 'return true;',
);
############################

2022/10/15

piwigo釋出13.0.0 , 我迫不急待進行升級,結果失敗, 原因應該是我使用非官方的docker版本.
最後只能硬著頭皮,
1. 把舊版(12.3.0) piwigo_images 資料表匯出到新版本(13.0.0)去,
2.並且把舊版本/gallery/_data/i 目錄, 以及/gallery/upload 目錄複製到新版本去, 這樣新版本就告訴你有未處裡的照片, 再自己手動重新建立相本吧, 這也是無可奈何的事情, 希望官方能有解決方案.

使用restic做離線備份, 充滿儀式感,老闆也開心

前陣子發現restic備份的好處, 尤其拿來當離線備份.

IT同事進行離線備份時, 有意無意被老闆路過, 看到滿滿備份畫面咻咻跑來跑去, 充滿了儀式感.
老闆開心, IT同仁也有成就感.


restic指令備份, 不夠自動化, 為了讓IT同事做少少的工作, 又讓IT同事與其他路過的同事覺得好專業, 因此寫了簡單的restic backup script , 可以協助掛載來源目錄, 掛載後,進行restic備份.

檔案請到這裡下載, 下載後請看readme.md檔案

centos 安裝dkim並且自動產生相關文件

先前寫了一篇centos7安裝opendkim+postfix 這只是單一網域, 若要多個網域,實在是很麻煩

google爬文爬到一篇文章,有神人寫了自動產生相關文件的shell script , 我稍微修改一下, 就能很方便產生相關文件.

  • 安裝dkim套件
#centos 7
yum install opendkim
#centos 8 , rocky linux 8
yum install opendkim opendkim-tools
  • 修改 opendkim.conf
    把Mode 改成 sv

postfix寄信認證改用dovecot

一直以來我都讓postfix使用 sasl 方式處裡寄信認證, 但是連結到多網域主控伺服器的時候, 就會出錯, 很麻煩.
經過測試 dovecot 可以使用多組 userdb , 與passdb , 達到一個mail server 支援多個ldap網域主控.

當然也能省下一個sasl的service

  • 修改dovecort的 conf.d/10-master.conf
service auth {
...
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    # Assuming the default Postfix user and group
    user = postfix
    group = postfix
  }
  ...
}

#以下設定為了相容outlook系統
auth_mechanisms = plain login
  • 修改postfix的main.cf
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

# On Debian Wheezy path must be relative and queue_directory defined
#queue_directory = /var/spool/postfix

# and the common settings to enable SASL:
smtpd_sasl_auth_enable = yes
  • 修改postfix的master.cf
submission inet n - n - - smtpd
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_sasl_type=dovecot
  -o smtpd_sasl_path=private/auth
  -o smtpd_sasl_security_options=noanonymous
  -o smtpd_sasl_local_domain=$myhostname
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o smtpd_sender_login_maps=hash:/etc/postfix/virtual
  -o smtpd_sender_restrictions=reject_sender_login_mismatch
 ...

參考:

https://doc.dovecot.org/configuration_manual/howto/postfix_and_dovecot_sasl/

找出當初docker 容器(container)執行的指令(非compose)

 docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro assaflavie/runlike  <容器名稱>
docker run --rm -i -v /var/run/docker.sock:/var/run/docker.sock nexdrew/rekcod <容器名稱>

但是這種方式屬於 reverse 方式, 跟原本會有一些失真,但真的沒留下當初執行的指令, 也只好使用這種方式了

centos 7 啟用NFS server

真真氣死人, 只是使用restic備份, 需要掛載不同性質的資料來源,
從 rclone 到 sshfs 到回歸nfs server, 只有一種感慨, 就是交給專業的來,不要想東想西的, ssh 來掛載目錄, rclone掛載ssh都不切實際,目前都不穩定.

服務器端啟用nfs server

yum install nfs-utils

## 分享目錄
mkdir -p /mnt/docker
vi etc/exports
=================
#只讀ro,  10.192.130.4可使用
/mnt/docker      10.192.130.4(ro,sync,no_root_squash,no_all_squash)
#讀寫rw,  10.192.130.0/24網段可使用
/mnt/docker      10.192.130.0/24(rw,sync,no_root_squash,no_all_squash)
=================

#啟用
firewall-cmd --zone=public --add-service=nfs --permanent

## rockylinux
#firewall-cmd --add-service={nfs,nfs3,mountd,rpc-bind} --permanent

firewall-cmd --reload
systemctl enable nfs 
systemctl start nfs

## rockylinux
#systemctl enable nfs-server rpcbind
#systemctl start nfs-server rpcbind

#查看狀態(windows,linux通用)
showmount -e localhost

用戶端(linux)

mount -t nfs <server ip>:/mnt/docker  <本地要掛載的目錄>
或是
mount -t nfs4 <server ip>:/mnt/docker  <本地要掛載的目錄>

用戶端(windows)

mount -o anon  \\ip\mount_path  z:
1 2 3 4 5 6 ... 14