使用 shell script 刪除 cloudflare 上的快取

1.先取得 domain name 的 ID

curl -X GET "https://api.cloudflare.com/client/v4/zones?name=網址" \
# -H "X-Auth-Email: test@gmail.com" \
# -H "X-Auth-Key: 7b9fb4xxxxxxxxxxxxxxxxxxxxxxxxxx" \
# -H "Content-Type: application/json" \

X-Auth-Email: 使用帳號
X-Auth-Key: API KEY 在 My settings 裡面可以查看

2.執行後會取得一連串的 json 字串、可以用線上 JSON檢視工具 直接看

3.取得後寫成shell script執行就好了

curl -X DELETE "https://api.cloudflare.com/client/v4/zones/e74b73xxxxxxxxxxxxxxxxxxxxxxxxxx/purge_cache" \
-H "X-Auth-Email: test@gmail.com" \
-H "X-Auth-Key: 7b9fb4xxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'

linux error . : backlog limit exceeded

此文完整連結 http://n.zipko.info/601.html
文章歡迎轉載,請尊重版權註明連結來源。

linux 的 audit 服務

Linux 的 audit (in Redhat, Suse) 服務是什麼?以前我也不會去注意,直到有一天系統 crash,不知道為什麼,打開 Monitor,只出現一堆這樣的訊息:

audit: audit_backlog=326 > audit_backlog_limit=320
audit: audit_lost=39095317 audit_rate_limit=0 audit_backlog_limit=320
audit: backlog limit exceeded

這也許不是 crash 的主因,不過先解決吧,下面是 FedoraForum 的建議:

It means that you are getting flooded with audit events. You can increase the audit daemon’s priority to make sure it has enough run time to empty its
queue or lengthen the backlog.

才引起我的注意,因此來研究一下 audit。

1. 什麼是 audit ?

Linux 系統中已經 syslog 了,syslog 會記錄系統狀態、如硬體的警告或應用軟體的記錄等。但是syslog屬於應用層,且僅只於此一應用而已,沒辦法記錄太多資訊。因此,audit 誕生以取代 syslog 的責任,來記錄核心層的事件:檔案的讀寫、系統呼叫、權限的狀態等。

2. 來看看 audit 運作的流程(圖片取自參考資料4)

Audit Daemon 運作和一般的daemon 一樣,運作後會引入selinux的系統。

3. audit 有三個操作的工具

audit 可用的三個指令:

=> auditctl – 控制 kernel audit system,能取得狀態,增或刪除rules、設定某個檔案的「檢視」(watch)。

=> ausearch – 用來查詢 audit logs 的工具。

=> aureport – 產生 audit 系統簡報的工具。

4. 設定檔

audit 的設定檔為 /etc/audit/audit.rules,主要分為三種類別:

• Basic audit system parameters
• File and directory watches
• System call audits

# basic audit system parameters
-D    (刪除舊記錄,預設-D)
-b 8192  (buffer大小,預設256,改為8192)
-f 1  (失敗控制旗標,可設為 0 (silent), 1 (印出錯誤,預設), and 2 (panic, 把系統關閉—非正常關閉,所以會有資料遺失的風險).
-e 1 (生失效,0為失效,1為生效(預設)
# some file and directory watches
-w /var/log/audit/   (觀查目錄 /var/log/audit/)
-w /etc/auditd.conf -p rxwa    (觀查檔案 /etc/auditd.conf,-p 設定權限為rxw及a屬性變更)
-w /etc/audit.rules -p rxwa
-w /etc/passwd -p rwxa
-w /etc/sysconfig/
# an example system call rule
-a entry,always -S umask

對於設定檔有幾點要說明:
• 目錄觀察的詳細度比檔案觀察低
• 無法使用任何的pathname globbing,如?或*
• 只能設定已存在的檔案,若設定觀察目錄而有新增檔案,新檔案只會在下次 audit 重啟後才會加入

利用 -k 產生 key string,以供ausearch 直接索引
-w /etc/var/log/audit/ -k LOG_audit

5. 操作實務

重啟 auditd
# service auditd restart

更新 auditd
# yum update audit

檢查檔案及系統的更動狀態
# aureport –start today –event –summary -i

查詢單一檔案
# ausearch -f filename

利用 -ts 指定日期 -k 指定 key string,其中password-file 使用 auditctl -k 來產生。
# ausearch -ts today -k password-file
# ausearch -ts 3/12/07 -k password-file

-ui 來指定 user name (UID),例如找出  (uid 506) 的操作
# ausearch -ts today -k password-file -x rm -ui 506
# ausearch -k password-file -ui 506

[參考資料]

1. FedoraForum.org http://forums.fedoraforum.org/showthread.php?t=213680

2. 檢查誰修改檔的動作 http://www.cyberciti.biz/tips/linux-audit-files-to-see-who-made-changes-to-a-file.html

3. Linux Audit Quick Start SUSE Linux Enterprise 10 SP1 http://www.novell.com/documentation/sled10/pdfdoc/auditqs_sp2/auditqs_sp2.pdf

4. The Linux Audit Subsystem Deep Dive http://linuxvm.org/present/SHARE113/S9203sw.pdf

 

http://note-end.zipko.info/601.html

YUM错误:ERROR: XZ COMPRESSION NOT AVAILABLE

今天在一台新的CentOS6服务器上配置PHP环境,用yum的方式安装,碰到问题了:

Error: xz compression not available

问题是这样来的,我参照我之前的博文安装步骤执行:《CentOS7下yum安装PHP5.6》,直到出现错误,才想起原来我当前的系统是CentOS6的!都是粗心惹的祸:-(

网上找到了解决的方法,即移除新版的epelrelease:

最好执行clean,有一次就是没执行,留有了缓存,被摆了一道。然后重新再安装6.x版本的epelrelease