2013年4月1日 星期一

upgrade to CentOS 6.4 from CentOS 6.3/6.2/6.1/6.0

升級失敗

跳版本或升級部份套件, 有時候會有無法升級? , 可以先清除cache

# yum clean all
# yum update glibc* yum* rpm* python*
# yum update

# reboot

確認目前版本
# cat /etc/redhat-release
CentOS release 6.4 (Final)

# lsb_release -a
LSB Version:    :base-4.0-ia32:base-4.0-noarch:core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.4 (Final)
Release:        6.4
Codename:       Final

加快更新速度 (限制在特定 mirror site)

安裝yum外掛套件 yum-plugin-fastestmirror
編緝         /etc/yum/pluginconf.d/fastestmirror.conf
限制在 tw範圍
include_only= .hinet.net, .twaren.net, .tw

2013年3月8日 星期五

linux 刪除超大量檔案目錄

rm on a directory with millions of files
小心使用, 注意權限 





最常用的方法, 刪除整個目錄, 用 ls 無法顯示
rm -rf (dir)

檔案數超過一定數量
find <dir> -type f -exec rm {} \;

刪除超量(用find刪不掉), 目錄大小超過數百M, 甚至數十G, 一般是主機被駭才有機會 >_<
while [ true ]; do ls -Uf | head -n 10000 | xargs rm -f 2>/dev/null; done )

export i=0;
time ( while [ true ]; do
            ls -Uf | head -n 3 | grep -qF '.png' || break;
            ls -Uf | head -n 10000 | xargs rm -f 2>/dev/null;
            export i=$(($i+10000)); echo "$i...";
       done )




命令模式, 自動化將特定網頁轉換為PDF


wkhtmltopdf  http://code.google.com/p/wkhtmltopdf/
 簡單的命令工具, 將HTML轉換為 PDF
 適合將網管上HTML報表轉出


寫個Scripts加入排程, 在固定將資料轉出來(用EMAIL也不錯), 這樣就不用每天做苦工
儲存至 /var/www/html/ntop/Report', 依月份存放至各目錄


[root@cacti ~]# cat /var/www/html/ntop/html2pdf.sh
#!/bin/bash
fileName="ntop-`date +\%Y\%m\%d-\%H`.pdf"
dirName="Report-`date +\%Y\%m`"
savePath='/var/www/html/ntop/Report'
html2pdf='/var/www/html/ntop/wkhtmltopdf-amd64'

if [ ! -d "$savePath/$dirName" ]; then
/bin/mkdir -p "$savePath/$dirName"
fi

$html2pdf "http://ntop.host.ip:3000/sortDataIP.html" "$savePath/$dirName/$fileName"




CACTI 簡單增加一個自行開發頁面, 並加入一個頁簽連結

在PHP 程式碼增加
    include("../cacti/include/global.php");

判斷session 是否存在即可
  $_SESSION["sess_user_id"]
 
安裝 Superlinks 外掛套件, 主要功能快速增加頁簽的超連結
 
 

 在Console > External Links 增加一個頁簽 Session, 連結指向你的PHP程式
 


 按Session , 測試看看
 
 
 

2012年11月5日 星期一

PHP 在APACHE 一些常用設定

不讓上傳的目錄執行PHP

httpd.conf 在網站的上傳目錄設定下
<Directory "/var/www/html/upload">
    AllowOverride None
    php_flag engine off
    Allow from all
</Directory>

.html 也能執行 PHP

# vim /etc/httpd/conf.d/php.conf

AddHandler php5-script .php .html .htm
AddType    text/html .php
AddType    application/x-httpd-php .html .htm

隱藏 Apache server information

# vim /etc/http/conf/httpd.conf
ServerSignature Off
ServerTokens Prod

隱藏 PHP version (X-Powered-By)

# vim /etc/php.ini

expose_php = Off







Prod or ProductOnly – Server sends (e.g.): Server: Apache
ServerTokens Prod

Major – Server sends (e.g.): Server: Apache/2
ServerTokens Major

Minor – Server sends (e.g.): Server: Apache/2.2
ServerTokens Minor

Min or Minimal – Server sends (e.g.): Server: Server: Apache/2.2.4
ServerTokens Min

OS – Server sends (e.g.): Server: Apache/2.2.4 (CentOS)
ServerTokens OS

Full or not specified – Server sends (e.g.): Server: Apache/2.2.4 (CentOS) PHP/5.2.3-Fedroa ServerTokens Full
ServerTokens setting applies to the entire server, and cannot be enabled or disabled on a virtualhost-by-virtualhost basis.


Web 控制 Browser Cache 的方式


 http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
 http-equiv="Pragma" content="no-cache" />
 http-equiv="Expires" content="0" />

Extreme XOS run pyton scripts

XOS run python scripts v15.7 or high 將交換器上的 IP & MAC 往syslog 丟, 簡單將IP資料保留下 ## 編緝Scripts # vi ip2syslog.py #!/usr/bin/python # ...