PIXNET Logo登入

Hello World

跳到主文

:D

部落格全站分類:生活綜合

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 6月 21 週三 202310:04
  • 透過 docker-compose 重啟單一個container

指令: 
# docker-compose rm -s -v service_name

或是參數合在一起也可以
# docker-compose rm -sv service_name

Options:
  -f, --force     Don't ask to confirm removal
  -s, --stop      Stop the containers, if required, before removing
  -v, --volumes   Remove any anonymous volumes attached to containers

 

舉例

docker-compose.yml 內容

(繼續閱讀...)
文章標籤

helloworld 發表在 痞客邦 留言(0) 人氣(37)

  • 個人分類:系統管理
▲top
  • 5月 24 週三 202310:01
  • 透過 crontab 實現重開機時自動執行 script

以前如果想讓linux 系統在重啟後,自動執行某些程式的話
習慣會把要執行的 scripts 加入 /etc/rc.local
其實crontab 也有相同的功能

crontab -e

加入
@reboot sleep 10 ; date > /tmp/reboot.log

重開機測試
檢查 /tmp 目錄下是否有剛剛產生或異動的檔案
-rw-r--r-- 1 root root   32 May 24 01:55 reboot.log

另外一個情境是,假設你沒有管理員權限
也可以透過 crontab 來自動啟用某些程式
@reboot date >> ~/reboot.log

(繼續閱讀...)
文章標籤

helloworld 發表在 痞客邦 留言(0) 人氣(287)

  • 個人分類:系統管理
▲top
  • 5月 24 週三 202309:28
  • wordpress 不透過安裝 plugin 寄信


修改 ./wp-includes/functions.php

新增
add_action( 'phpmailer_init', 'send_smtp_email' );
function send_smtp_email( $phpmailer ) {
        $phpmailer->isSMTP();
        $phpmailer->Host       = SMTP_HOST;
        $phpmailer->SMTPAuth   = SMTP_AUTH;
        $phpmailer->Port       = SMTP_PORT;
        $phpmailer->Username   = SMTP_USER;
        $phpmailer->Password   = SMTP_PASS;
        $phpmailer->SMTPSecure = SMTP_SECURE;
        $phpmailer->From       = SMTP_FROM;
        $phpmailer->FromName   = SMTP_NAME;
}

修改 ./wp-config.php

新增
define( 'SMTP_USER',   'user@example.com' );    // Username to use for SMTP authentication
define( 'SMTP_PASS',   'smtp password' );       // Password to use for SMTP authentication
define( 'SMTP_HOST',   'smtp.example.com' );    // The hostname of the mail server
define( 'SMTP_FROM',   'website@example.com' ); // SMTP From email address
define( 'SMTP_NAME',   'e.g Website Name' );    // SMTP From name
define( 'SMTP_PORT',   '25' );                  // SMTP port number - likely to be 25, 465 or 587
define( 'SMTP_SECURE', 'tls' );                 // Encryption system to use - ssl or tls
define( 'SMTP_AUTH',    true );                 // Use SMTP authentication (true|false)
define( 'SMTP_DEBUG',   0 );                    // for debugging purposes only set to 1 or 2

透過登入頁的忘記密碼功能可以測試寄信

(繼續閱讀...)
文章標籤

helloworld 發表在 痞客邦 留言(0) 人氣(8)

  • 個人分類:系統管理
▲top
  • 5月 17 週三 202313:53
  • nagios 使用外部MTA 驗證寄信

如果nagios 發現異常要發送警告信給管理者
本機必須要有postfix或sendmail 之類的MTA

如果因為資安考量或其他因素不打算安裝
或是跑在docker 上,預設也沒有MTA,就無法發送信件

幸好nagios 非常地有彈性
可以改觸發其他scripts

以下範例改用 phpmailer 發送


編輯 /phpmailer/example/mail.php
#!/usr/bin/php

(繼續閱讀...)
文章標籤

helloworld 發表在 痞客邦 留言(0) 人氣(4)

  • 個人分類:系統管理
▲top
  • 5月 17 週三 202311:21
  • 解決 Debian 11 找不到 apt-add-repository 指令問題

# apt-add-repository contrib
-bash: apt-add-repository: command not found

# apt-get install software-properties-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  gir1.2-glib-2.0 gir1.2-packagekitglib-1.0 libappstream4 libdw1 libgirepository-1.0-1 libglib2.0-bin libgstreamer1.0-0 libpackagekit-glib2-18 libpolkit-agent-1-0 libpolkit-gobject-1-0
  libstemmer0d libunwind8 libyaml-0-2 packagekit packagekit-tools policykit-1 python3-dbus python3-distro-info python3-gi python3-software-properties unattended-upgrades
Suggested packages:
  gstreamer1.0-tools appstream python-dbus-doc python3-dbus-dbg bsd-mailx default-mta | mail-transport-agent needrestart powermgmt-base
The following NEW packages will be installed:
  gir1.2-glib-2.0 gir1.2-packagekitglib-1.0 libappstream4 libdw1 libgirepository-1.0-1 libglib2.0-bin libgstreamer1.0-0 libpackagekit-glib2-18 libpolkit-agent-1-0 libpolkit-gobject-1-0
  libstemmer0d libunwind8 libyaml-0-2 packagekit packagekit-tools policykit-1 python3-dbus python3-distro-info python3-gi python3-software-properties software-properties-common
  unattended-upgrades
0 upgraded, 22 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,792 kB of archives.
After this operation, 15.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
 

# apt-add-repository contrib
'contrib' distribution component enabled for all sources.
 

(繼續閱讀...)
文章標籤

helloworld 發表在 痞客邦 留言(0) 人氣(12)

  • 個人分類:系統管理
▲top
  • 4月 14 週五 202311:20
  • debian 安裝套件時,跳過對話過程

apt-get -y install 套件名
只會幫你一次安裝好套件
但如果中間出現對話框,還是會卡住

如果要跳過 prompt 過程
可以加上
DEBIAN_FRONTEND=noninteractive apt-get -y install 套件1 套件2


 

(繼續閱讀...)
文章標籤

helloworld 發表在 痞客邦 留言(0) 人氣(10)

  • 個人分類:系統管理
▲top
  • 4月 12 週三 202311:20
  • 使用 mrtg 紀錄 fortigate cpu / memory 使用率

相關 OID
1.3.6.1.4.1.12356.101.4.1.3 : CPU使用率,單位 %
1.3.6.1.4.1.12356.101.4.1.4 : 記憶體使用率,單位 %

首先使用 snmpwalk 工具測試是否可以正常抓到數字
# snmpwalk -v2c -c public 10.1.1.254 1.3.6.1.4.1.12356.101.4.1.3
SNMPv2-SMI::enterprises.12356.101.4.1.3.0 = Gauge32: 0

# snmpwalk -v2c -c public 10.1.1.254 1.3.6.1.4.1.12356.101.4.1.4
SNMPv2-SMI::enterprises.12356.101.4.1.4.0 = Gauge32: 33

編輯 mrtg.cfg

# cpu
Target[CPU]: .1.3.6.1.4.1.12356.101.4.1.3.0&.1.3.6.1.4.1.12356.101.4.1.3.0:public@10.1.1.254
Title[CPU]: Procesor Usage
PageTop[CPU]: <h1>Procesor Usage</h1>
Options[CPU]: gauge, growright, nopercent
MaxBytes[CPU]: 100
YLegend[CPU]: pourcent
ShortLegend[CPU]: %
LegendI[CPU]: CPU usage
LegendO[CPU]: CPU usage
Legend1[CPU]: Total CPU Used
Legend2[CPU]: Total CPU Used

(繼續閱讀...)
文章標籤

helloworld 發表在 痞客邦 留言(0) 人氣(44)

  • 個人分類:系統管理
▲top
  • 4月 12 週三 202308:55
  • 啟用 fortigate snmpd

網路上文章通常只跟你講到第一個步驟
如果還是無法抓到 snmp 資料的話,請試試第二個步驟是否有設定

1. 首先到 系統管理 -> SNMP 
啟動 SNMP 功能,並設定 SNMP v1/v2c 的community string,主機IP外

2. 還要到 網路 > 介面 > 把snmp 服務加入你要監控的介面上

image

(繼續閱讀...)
文章標籤

helloworld 發表在 痞客邦 留言(0) 人氣(5)

  • 個人分類:系統管理
▲top
  • 4月 07 週五 202317:11
  • Ubuntu 20.04.2 LTS 新增 swapfile

系統運作一陣子後
如果發現swap 空間不足,但沒有空的 partition 或是沒有新增硬碟的打算
可以新增一個 swap file 來增加 swap空間

1. 先確認硬碟空間是否足夠
df -h

2. 假設我要把 swap file 建在 /swap/ 下
mkdir /swap
cd /swap
fallocate -l 1G /swap/swapfile01
chmod 600 swapfile01
mkswap swapfile01
swapon /swap/swapfile01

3. 檢查swap 使用狀況
swapon --show

4. 加入 /etc/fstab,下次重開機後自動掛載
/swap/swapfile01        none    swap sw 0 0
 

(繼續閱讀...)
文章標籤

helloworld 發表在 痞客邦 留言(0) 人氣(11)

  • 個人分類:系統管理
▲top
  • 3月 23 週四 202311:56
  • 解決 ufw 無法阻擋連線到 docker container 問題

有些人的解法是修改 docker 的iptables 設定,但可能會衍生出其他問題
所以建議以下作法


編輯 /etc/ufw/after.rules

到檔案下方新增以下內容
# BEGIN UFW AND DOCKER
*filter
:ufw-user-forward - [0:0]
:DOCKER-USER - [0:0]
-A DOCKER-USER -j RETURN -s 10.0.0.0/8
-A DOCKER-USER -j RETURN -s 172.16.0.0/12
-A DOCKER-USER -j RETURN -s 192.168.0.0/16

-A DOCKER-USER -j ufw-user-forward

-A DOCKER-USER -j DROP -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -d 192.168.0.0/16
-A DOCKER-USER -j DROP -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -d 10.0.0.0/8
-A DOCKER-USER -j DROP -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -d 172.16.0.0/12
-A DOCKER-USER -j DROP -p udp -m udp --dport 0:32767 -d 192.168.0.0/16
-A DOCKER-USER -j DROP -p udp -m udp --dport 0:32767 -d 10.0.0.0/8
-A DOCKER-USER -j DROP -p udp -m udp --dport 0:32767 -d 172.16.0.0/12

(繼續閱讀...)
文章標籤

helloworld 發表在 痞客邦 留言(0) 人氣(7)

  • 個人分類:系統管理
▲top
«1...56770»

momo shop

近期文章

    誰來我家

    我的地盤

    helloworld
    暱稱:
    helloworld
    分類:
    生活綜合
    好友:
    累積中
    地區:

    文章分類

    • 資料庫 (392)
    • 工商服務 (864)
    • 吃吃吃 (248)
    • 系統管理 (3,768)
    • 遊記 (224)
    • 未分類文章 (1)

    參觀人氣

    • 本日人氣:
    • 累積人氣:

    pixGoogleAdsense1

    pixGoogleAdsense2

    留言板