2016/06/10

在shell 中呼叫 python 可以把變數一起丟給python

#!/bin/bash
var1=a
var2=b
python test.py $var1 $var2


test.py 內容如下

import sys
print sys.argv[0] # prints python_script.py
print sys.argv[1] # prints var1
print sys.argv[2] # prints var2


輸出結果為
test.py
a
b

在shell中 awk是不能直接使用shell定義的變數的
必須在awk的一開頭定義
範例如下

#!/bin/bash
a=3
b=4

awk -v a=$a -v b=$b '$1 == a {print $2}' test_data

2016/05/31

fio 測試範例

# This job file tries to mimic the Intel IOMeter File Server Access Pattern
[global]
description=Emulation of Intel IOmeter File Server Access Pattern

[iometer]
bssplit=512/10:1k/5:2k/5:4k/60:8k/2:16k/4:32k/4:64k/10
filename=PhysicalDrive1:PhysicalDrive2:PhysicalDrive3
size=1G
rw=randrw
#set read 50% write 50%
rwmixread=50
direct=1
runtime=60                  
# IOMeter defines the server loads as the following:
# iodepth=1                    Linear
# iodepth=4                    Very Light
# iodepth=8                    Light
# iodepth=64                    Moderate
# iodepth=256                    Heavy
iodepth=64

修改filename 及 size
其他參數視需要修改

以上存為 test.fio

執行fio test.fio

用shell 重複執行

#/bin/bash
rm /tmp/fio_test_log

while :
do
    fio test.fio -output=/tmp/iolog
    cat /tmp/iolog >> /tmp/fio_test_log
done

http://benjr.tw/93666

2016/05/23

今天早上小測了一下linux mint三個桌面版本的效能
virtualbox 5.0.18
host os : ubuntu 16.04
cpu x 1
ram 2G

單純使用iso開机 不安裝
打開youtube 使用1080p播放 kiss radio直播
各個版本效能擷圖如下
cinnamon





















mate





















xfce





















看來mate的效果最好

2016/05/20

已經使用很久的ipaudit有個scan report 的功能 如下圖






















但使用curl加上html2text捉下來後ip就如圖所示會自動補0
找來找去終於找到一個方便的方法來處理
就是使用expr
整個程式如下

#!/bin/bash
/usr/bin/curl "http://10.123.123.123/~ipaudit/cgi-bin/ipahttp?30min/0traffic+current"|/usr/bin/html2text |sed -n '18,37p'|awk '$3 > 100 {print $1}' > /tmp/ipaudit_in_scan_ip_tmp

rm /tmp/ipaudit_in_scan_ip

for i in `cat /tmp/ipaudit_in_scan_ip_tmp`
do
a=`echo $i|cut -d '.' -f 1`
a1=`expr $a / 1`
a=`echo $i|cut -d '.' -f 2`
a2=`expr $a / 1`
a=`echo $i|cut -d '.' -f 3`
a3=`expr $a / 1`
a=`echo $i|cut -d '.' -f 4`
a4=`expr $a / 1`
echo $a1"."$a2"."$a3"."$a4 >> /tmp/ipaudit_in_scan_ip
done


前几天把wsus換到了vm上
但換過去後卻一直出問題
三不五時服務就會死掉
log顯示如下 每次都是死在wsuspool

May 19 07:38:38 WSUS WAS: 5013: 服務應用程式集區 'WsusPool' 的處理序關閉時超過次數限制。處理序識別碼為 '5192'。
May 19 07:38:38 WSUS WAS: 5117: 服務應用程式集區 'WsusPool' 的背景工作處理序已要求回收,因為它已達到私用位元組記憶體限制。
May 19 08:08:27 WSUS WAS: 5117: 服務應用程式集區 'WsusPool' 的背景工作處理序已要求回收,因為它已達到私用位元組記憶體限制。
May 19 08:10:49 WSUS WAS: 5117: 服務應用程式集區 'WsusPool' 的背景工作處理序已要求回收,因為它已達到私用位元組記憶體限制。
May 19 08:12:19 WSUS WAS: 5138: 服務應用程式集區 'WsusPool' 的工作者處理序 '6184' 無法在指定的時間停止通訊協定 'http' 的接聽程式通道。資料欄位包含錯誤號碼。
May 19 08:12:19 WSUS WAS: 5013: 服務應用程式集區 'WsusPool' 的處理序關閉時超過次數限制。處理序識別碼為 '6184'。
May 19 08:12:19 WSUS WAS: 5117: 服務應用程式集區 'WsusPool' 的背景工作處理序已要求回收,因為它已達到私用位元組記憶體限制。
May 19 08:13:50 WSUS WAS: 5138: 服務應用程式集區 'WsusPool' 的工作者處理序 '5964' 無法在指定的時間停止通訊協定 'http' 的接聽程式通道。資料欄位包含錯誤號碼。
May 19 08:13:50 WSUS WAS: 5013: 服務應用程式集區 'WsusPool' 的處理序關閉時超過次數限制。處理序識別碼為 '5964'。
May 19 08:13:50 WSUS WAS: 5002: 正在自動停止應用程式集區 'WsusPool',因為服務該應用程式集區的處理序中發生一連串的失敗。

找了一下資料 請seek的工程師幫忙
調整了一下記憶体的值 (預設為1G  加大到4G)
過了一天 目前看來正常了
再觀察看看

設定流程如下圖所示


















不過原來在實体机是windows server 2012 沒調過這個值也沒有問題
在vm上的是windows server 2012 R2

2016/05/19

一直以來很困擾在使用vi的編輯模式時按方向鍵會出現英文字的問題
找到解決方法

在家目錄底下,新增檔案「.vimrc」,在檔案中加入下列2行內容:
set nocompatible
set backspace=2

http://www.geego.com.tw/technical-discussion-forum/tech-tips-using-vi-editor-on-ubuntu-%E7%B7%A8%E8%BC%AF-%E6%96%B9%E5%90%91%E9%8D%B5-%E5%80%92%E9%80%80%E9%8D%B5-%E6%93%8D%E4%BD%9C

2016/05/18

因為chrome在之前几個月開始就不再支援32bit的linux
所以家裡使用的電腦就想重灌為64bit
這次選了linux mint
安裝速度滿快的
而且直接捉到我的usb網卡 直是方便
但裝完後裝上chrome卻發現網頁上有些字的字型變的很怪







爬了一下文 發現是字型的問題
因為系統自動多裝了以下二套字型

sudo apt-get remove fonts-arphic-ukai
sudo apt-get remove fonts-arphic-uming

移除後再重開chrome就正常了
firefox並沒有這個問題

2016/05/17

最近因為實體機的wsus出問題
因此把她移到proxmox上
本來是想在win上mount nfs來用
但看來wsus並不支援
後來改用iscsi
但在kvm的硬碟效能看來並不好
想調看看
依據下面的文件做了一下測試
https://pve.proxmox.com/wiki/Performance_Tweaks

使用fio

四個mode的結果分別如下

no cache (proxmox預設)

iometer: (groupid=0, jobs=1): err= 0: pid=4376: Tue May 17 01:14:11 2016  Descri
ption  : [Emulation of Intel IOmeter File Server Access Pattern]
  read : io=839580KB, bw=986.43KB/s, iops=187, runt=851139msec
    slat (usec): min=33, max=12019, avg=135.28, stdev=127.09
    clat (usec): min=863, max=45860K, avg=272726.04, stdev=690206.66
     lat (msec): min=1, max=45860, avg=272.86, stdev=690.21
    clat percentiles (msec):
     |  1.00th=[   14],  5.00th=[   34], 10.00th=[   52], 20.00th=[   85],
     | 30.00th=[  119], 40.00th=[  155], 50.00th=[  198], 60.00th=[  249],
     | 70.00th=[  314], 80.00th=[  392], 90.00th=[  498], 95.00th=[  668],
     | 99.00th=[ 1237], 99.50th=[ 1418], 99.90th=[ 1958], 99.95th=[10683],
     | 99.99th=[16712]
    bw (KB  /s): min=    1, max= 3527, per=100.00%, avg=1031.92, stdev=539.62
  write: io=209006KB, bw=251453B/s, iops=47, runt=851139msec
    slat (usec): min=36, max=9979, avg=144.38, stdev=139.48
    clat (msec): min=1, max=42109, avg=268.91, stdev=674.52
     lat (msec): min=1, max=42109, avg=269.06, stdev=674.52
    clat percentiles (msec):
     |  1.00th=[   13],  5.00th=[   33], 10.00th=[   52], 20.00th=[   85],
     | 30.00th=[  117], 40.00th=[  153], 50.00th=[  194], 60.00th=[  247],
     | 70.00th=[  310], 80.00th=[  388], 90.00th=[  490], 95.00th=[  660],
     | 99.00th=[ 1221], 99.50th=[ 1434], 99.90th=[ 2008], 99.95th=[ 8717],
     | 99.99th=[16712]
    bw (KB  /s): min=    0, max=  976, per=100.00%, avg=257.99, stdev=155.70
    lat (usec) : 1000=0.01%
    lat (msec) : 2=0.01%, 4=0.07%, 10=0.50%, 20=1.59%, 50=7.30%
    lat (msec) : 100=15.26%, 250=35.57%, 500=29.91%, 750=5.77%, 1000=1.93%
    lat (msec) : 2000=1.99%, >=2000=0.10%
  cpu          : usr=1.06%, sys=4.46%, ctx=0, majf=0, minf=0
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.3%, >=64=99.7%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.1%, 32=0.0%, 64=0.1%, >=64=0.0%
     issued    : total=r=159733/w=40419/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0

     latency   : target=0, window=0, percentile=100.00%, depth=64

Run status group 0 (all jobs):
   READ: io=839579KB, aggrb=986KB/s, minb=986KB/s, maxb=986KB/s, mint=851139msec
, maxt=851139msec
  WRITE: io=209005KB, aggrb=245KB/s, minb=245KB/s, maxb=245KB/s, mint=851139msec
, maxt=851139msec


direct sync

iometer: (groupid=0, jobs=1): err= 0: pid=3960: Tue May 17 01:34:28 2016  Descri
ption  : [Emulation of Intel IOmeter File Server Access Pattern]
  read : io=839580KB, bw=990904B/s, iops=184, runt=867621msec
    slat (usec): min=29, max=4295, avg=127.63, stdev=94.92
    clat (msec): min=1, max=3990, avg=278.10, stdev=248.29
     lat (msec): min=1, max=3990, avg=278.23, stdev=248.29
    clat percentiles (msec):
     |  1.00th=[   15],  5.00th=[   39], 10.00th=[   61], 20.00th=[   98],
     | 30.00th=[  135], 40.00th=[  176], 50.00th=[  219], 60.00th=[  265],
     | 70.00th=[  326], 80.00th=[  404], 90.00th=[  529], 95.00th=[  734],
     | 99.00th=[ 1303], 99.50th=[ 1516], 99.90th=[ 1860], 99.95th=[ 2008],
     | 99.99th=[ 2474]
    bw (KB  /s): min=  104, max= 3121, per=100.00%, avg=972.63, stdev=462.35
  write: io=209006KB, bw=246676B/s, iops=46, runt=867621msec
    slat (usec): min=33, max=3792, avg=137.96, stdev=101.21
    clat (msec): min=1, max=3267, avg=273.82, stdev=245.31
     lat (msec): min=1, max=3267, avg=273.95, stdev=245.31
    clat percentiles (msec):
     |  1.00th=[   14],  5.00th=[   37], 10.00th=[   59], 20.00th=[   95],
     | 30.00th=[  131], 40.00th=[  172], 50.00th=[  215], 60.00th=[  262],
     | 70.00th=[  322], 80.00th=[  396], 90.00th=[  523], 95.00th=[  734],
     | 99.00th=[ 1270], 99.50th=[ 1483], 99.90th=[ 1795], 99.95th=[ 1926],
     | 99.99th=[ 2376]
    bw (KB  /s): min=    1, max=  837, per=100.00%, avg=241.81, stdev=139.50
    lat (msec) : 2=0.01%, 4=0.06%, 10=0.43%, 20=1.28%, 50=5.89%
    lat (msec) : 100=13.20%, 250=36.27%, 500=31.53%, 750=6.52%, 1000=2.28%
    lat (msec) : 2000=2.48%, >=2000=0.05%
  cpu          : usr=0.58%, sys=4.26%, ctx=0, majf=0, minf=0
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.1%, >=64=99.9%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.1%, 16=0.0%, 32=0.0%, 64=0.1%, >=64=0.0%
     issued    : total=r=159733/w=40419/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0

     latency   : target=0, window=0, percentile=100.00%, depth=64

Run status group 0 (all jobs):
   READ: io=839579KB, aggrb=967KB/s, minb=967KB/s, maxb=967KB/s, mint=867621msec
, maxt=867621msec
  WRITE: io=209005KB, aggrb=240KB/s, minb=240KB/s, maxb=240KB/s, mint=867621msec
, maxt=867621msec

writethrough

iometer: (groupid=0, jobs=1): err= 0: pid=464: Tue May 17 01:44:14 2016  Descrip
tion  : [Emulation of Intel IOmeter File Server Access Pattern]
  read : io=839580KB, bw=2750.9KB/s, iops=523, runt=305208msec
    slat (usec): min=33, max=3381, avg=148.74, stdev=118.02
    clat (usec): min=525, max=3432.2K, avg=97497.21, stdev=190958.21
     lat (usec): min=608, max=3432.2K, avg=97645.95, stdev=190948.63
    clat percentiles (msec):
     |  1.00th=[    4],  5.00th=[    8], 10.00th=[   11], 20.00th=[   17],
     | 30.00th=[   22], 40.00th=[   28], 50.00th=[   35], 60.00th=[   42],
     | 70.00th=[   57], 80.00th=[   96], 90.00th=[  265], 95.00th=[  465],
     | 99.00th=[  996], 99.50th=[ 1287], 99.90th=[ 1713], 99.95th=[ 1844],
     | 99.99th=[ 2245]
    bw (KB  /s): min=  117, max=10905, per=100.00%, avg=2768.59, stdev=2650.18
  write: io=209006KB, bw=701232B/s, iops=132, runt=305208msec
    slat (usec): min=36, max=2704, avg=157.69, stdev=118.79
    clat (usec): min=643, max=2868.8K, avg=96528.89, stdev=185218.15
     lat (usec): min=730, max=2868.9K, avg=96686.58, stdev=185208.44
    clat percentiles (msec):
     |  1.00th=[    4],  5.00th=[    8], 10.00th=[   11], 20.00th=[   17],
     | 30.00th=[   22], 40.00th=[   28], 50.00th=[   35], 60.00th=[   42],
     | 70.00th=[   57], 80.00th=[   97], 90.00th=[  265], 95.00th=[  461],
     | 99.00th=[  963], 99.50th=[ 1221], 99.90th=[ 1631], 99.95th=[ 1778],
     | 99.99th=[ 2008]
    bw (KB  /s): min=    1, max= 3243, per=100.00%, avg=688.92, stdev=677.96
    lat (usec) : 750=0.01%, 1000=0.02%
    lat (msec) : 2=0.21%, 4=1.13%, 10=8.32%, 20=17.18%, 50=40.00%
    lat (msec) : 100=13.73%, 250=8.92%, 500=6.15%, 750=2.57%, 1000=0.79%
    lat (msec) : 2000=0.96%, >=2000=0.02%
  cpu          : usr=2.95%, sys=11.47%, ctx=0, majf=0, minf=0
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=22.4%, >=64=77.6%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=99.9%, 8=0.1%, 16=0.1%, 32=0.1%, 64=0.1%, >=64=0.0%
     issued    : total=r=159733/w=40419/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0

     latency   : target=0, window=0, percentile=100.00%, depth=64

Run status group 0 (all jobs):
   READ: io=839579KB, aggrb=2750KB/s, minb=2750KB/s, maxb=2750KB/s, mint=305208m
sec, maxt=305208msec
  WRITE: io=209005KB, aggrb=684KB/s, minb=684KB/s, maxb=684KB/s, mint=305208msec
, maxt=305208msec

writeback

iometer: (groupid=0, jobs=1): err= 0: pid=1904: Tue May 17 01:56:37 2016  Descri
ption  : [Emulation of Intel IOmeter File Server Access Pattern]
  read : io=839580KB, bw=2514.4KB/s, iops=478, runt=333921msec
    slat (usec): min=29, max=12023, avg=185.33, stdev=221.12
    clat (usec): min=538, max=13009K, avg=106457.27, stdev=193275.54
     lat (usec): min=670, max=13009K, avg=106642.60, stdev=193264.18
    clat percentiles (msec):
     |  1.00th=[    5],  5.00th=[    9], 10.00th=[   13], 20.00th=[   21],
     | 30.00th=[   29], 40.00th=[   38], 50.00th=[   48], 60.00th=[   68],
     | 70.00th=[   93], 80.00th=[  137], 90.00th=[  265], 95.00th=[  408],
     | 99.00th=[  783], 99.50th=[ 1156], 99.90th=[ 1795], 99.95th=[ 2024],
     | 99.99th=[ 4490]
    bw (KB  /s): min=   70, max=10009, per=100.00%, avg=2528.25, stdev=1930.08
  write: io=209006KB, bw=640934B/s, iops=121, runt=333921msec
    slat (usec): min=32, max=12301, avg=195.26, stdev=240.65
    clat (usec): min=637, max=10893K, avg=106044.70, stdev=199408.62
     lat (usec): min=699, max=10894K, avg=106239.95, stdev=199397.25
    clat percentiles (msec):
     |  1.00th=[    5],  5.00th=[    9], 10.00th=[   13], 20.00th=[   21],
     | 30.00th=[   29], 40.00th=[   38], 50.00th=[   48], 60.00th=[   68],
     | 70.00th=[   94], 80.00th=[  137], 90.00th=[  265], 95.00th=[  404],
     | 99.00th=[  742], 99.50th=[ 1106], 99.90th=[ 1811], 99.95th=[ 2008],
     | 99.99th=[ 7308]
    bw (KB  /s): min=    3, max= 2501, per=100.00%, avg=629.21, stdev=504.36
    lat (usec) : 750=0.01%, 1000=0.01%
    lat (msec) : 2=0.14%, 4=0.75%, 10=5.70%, 20=12.30%, 50=32.48%
    lat (msec) : 100=20.56%, 250=17.35%, 500=7.78%, 750=1.87%, 1000=0.38%
    lat (msec) : 2000=0.62%, >=2000=0.06%
  cpu          : usr=2.10%, sys=12.88%, ctx=0, majf=0, minf=0
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=25.7%, >=64=74.3%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=99.8%, 8=0.2%, 16=0.1%, 32=0.0%, 64=0.1%, >=64=0.0%
     issued    : total=r=159733/w=40419/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0

     latency   : target=0, window=0, percentile=100.00%, depth=64

Run status group 0 (all jobs):
   READ: io=839579KB, aggrb=2514KB/s, minb=2514KB/s, maxb=2514KB/s, mint=333921m
sec, maxt=333921msec
  WRITE: io=209005KB, aggrb=625KB/s, minb=625KB/s, maxb=625KB/s, mint=333921msec
, maxt=333921msec

單純看iops
writeback 和 writethrough 差不多

但文件上針對 writeback有這一句
Warn : you can loose datas in case of a powerfailure

所以看來 writethrough是比較好的選擇



2016/05/11

synology上建完user如果要讓user只能登入家目錄
要再做以下設定

到檔案服務的ftp裡的進階設定












2016/04/17

因為ascenflow GG了
所以把認証移到forti上去
順便想看一下線上人數並記錄
但找了一下forti的mib
並沒有提供這個值
所以只好自行寫程式來撈了

使用python來撈目前online user的所有資料 並從中取出線上人數 在輸出的最後一行
直接使用shell也可以

#!/usr/bin/python

import os
import telnetlib

host="192.168.1.1"
user="admin"
passwd="password"

tn = telnetlib.Telnet(host)

tn.read_until("FG600C login: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(passwd + "\n")
tn.read_until("FG600C # ")
tn.write("diagnose firewall auth filter group auth_user_group(radius_server)" + "\n")
tn.read_until("FG600C # ")
tn.write("diagnose firewall auth list" + "\n")
#tn.read_until("FG600C # ")
tn.write("exit" + "\n")

print tn.read_all()
tn.close()

取出後把值吐給cacti來畫圖

步驟如下

1. 建立data input methods 使用自行寫好的程式










2. 使用步驟1 的資料來新增data templates














3.使用步驟2 的資料來產生 graph templates













4. 在forti上新增步驟3所產生的graph template






等待一段時間後畫出的圖如下












發現有小數出現 雖然說不太會影響判讀 但感覺就是怪怪的
找了一下資料
發現把graph template的gprint type改成exact numbers就可以顯示整數了













改好後如下圖 看起來正常多了









2016/04/06

如何使用python利用telnet指令到網路設備下指令並捉取回傳的資料
範例如下 

#!/usr/bin/python

import os
import telnetlib

host="1.1.1.1"
user="abc"
passwd="password"

tn = telnetlib.Telnet(host)
tn.read_until("login: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(passwd + "\n")

#read_until()到下完password 即可 接下來的指令必須一直下
#不再使用read_until() 否則最後的 print tn.read_all() 會沒有資料

tn.write("ls -al" + "\n")
tn.write("exit" + "\n")
print tn.read_all()

2016/04/02

有台ubuntu好久沒update了
今天要update時出現以下的訊息

W: GPG error: http://tw.archive.ubuntu.com trusty Release: The following signatures were invalid: BADSIG 40976EAF437D05B5 Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>
E: Encountered a section with no Package: header
E: Problem with MergeList /var/lib/apt/lists/tw.archive.ubuntu.com_ubuntu_dists_trusty_main_i18n_Translation-en
E: The package lists or status file could not be parsed or opened.

看來好像是list有問題
找了下一下資料
用以下的方法處理後就ok了

cd /var/lib/apt
sudo mv lists lists.old
sudo mkdir -p lists/partial
sudo apt-get update

2016/03/29

上週認証設備掛點
除了認証失效外
因為流量的計算也在該台上 所以quota的限制也就失效了
本來想直接撈LP的netflow資料來算
但因為會包含內部對內部的流量 所以會造成問題
因此打算用對外port mirror的資料轉成netflow來使用

fprobe
把port mirror的資料轉成netflow格式再吐出來

flow-tools
收集netflow並格式化成所需的資料

在ubuntu上直接apt-get install就好了
centos沒辦法直接yum

相關指令如下

/usr/sbin/fprobe -ieth1 -fip localhost:555
/usr/bin/flow-capture -V 5 -z 6 -n 572 -e 5000 -N -1 -w /tmp/flow 0/0/555

計算流量排名指令如下
取出超過10G下載或上傳量的ip

flow-cat /tmp/flow/`date +'%Y-%m-%d'`/ft*|flow-report -v TYPE=ip-destination-address|grep "192.168.\|10.10."|sort -rnk3 |awk '$3 > 5000000000 {print $1}'|grep -v -f /root/netflow_white_list > /tmp/netflow_quota_download

flow-cat /tmp/flow/`date +'%Y-%m-%d'`/ft*|flow-report -v TYPE=ip-source-address|grep "192.168.\|10.10."|sort -rnk3 |awk '$3 > 5000000000 {print $1}'|grep -v -f /root/netflow_white_list > /tmp/netflow_quota_upload

https://jal.tw/doku.php?id=netflow:fprobe

2016/03/22

為了預先解決centos 5到明天支援到期的問題
今天來把原先提供下載服務的机器升成centos 7
比較難處理的是原本提供kms認証的部分
几個跟原centos 5不同的地方記錄一下

原本apache用來ldap認証的模組換成 mod_ldap

寫法也有一些改變 範例如下 (novell 適用)

<Directory /var/www/html/test>
    AuthName ldap
    AuthType Basic
    AuthBasicProvider ldap
    AuthLDAPURL ldap://test.com.tw:389/o=users?cn?sub?(objectClass=*)
    AuthLDAPBindDN "cn=user01, ou=user, ou=people, o=users"
    AuthLDAPBindPassword password
    Require valid-user
</Directory>

ip forword的寫法也改了

在/etc/sysctl.conf 加上
net.ipv4.ip_forward = 1

重新載入
sysctl -p /etc/sysctl.conf


因為需要使用apche這個身分下iptables的指令
所以要編輯 /etc/sudoers
Defaults    requiretty 改為 Defaults:apache !requiretty apache不需要tty

再加上
User_Alias      APACHE = apache
Cmnd_Alias      FIREWALL = /sbin/iptables

APACHE  ALL = (ALL) NOPASSWD: FIREWALL

原來的firewalld要停掉 改用iptables

systemctl disable firewalld
yum install -y iptables-services
systemctl enable iptables

http://my.oschina.net/fsxchen/blog/134601
http://superuser.com/questions/803741/how-to-enable-ip-masquerading-forwarding-on-centos-7

2016/03/05

最近把從mysql撈資料的程式用python改寫 之前是用php

改完後發生的第一個問題就是中文全變成了???

192.168.105.61 || 2016-03-04 00:05:05 || 2016-03-07 00:05:05 || Flow Checking ????????????(1368>????:700) to Deny this IP cannot access network

原因是從mysql撈出來時中文就亂了 所以不管之後怎麼轉碼 都沒有用了
所以必須在撈時就要指定編碼 加上下方紅色字部分

db = MySQLdb.connect(host="localhost", user="abc", passwd="pwd", db="test", charset='utf8')

但加完後網頁反而出不來了
再查了一下資料 說是要再指定sys的編碼 於是程式內必需再加入以下三行

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

加完後之後的結果變成

192.168.105.61 || 2016-03-04 00:05:05 || 2016-03-07 00:05:05 || Flow Checking �訫�銝餅�����賊�蝬脰楝�輻�(1368>�𣂼��賊�:700) to Deny this IP cannot access network

看來中文有出來了 接下來是顯示的問題了 因為這個os比較久了 所以apache預設的編碼是設為big5 如果要去改會影響到其他東東 所以只能在程式加上指定編碼來處理了 比較新版本os的apache應該都預設為utf8了 應該不會碰到這個問題

print '<html>'
print '<head>'
print '<meta charset="UTF-8">'
print '</head>'
print '<body>'

print '</body>'
print '</html>'

網頁正常 搞定

192.168.105.61 || 2016-03-04 00:05:05 || 2016-03-07 00:05:05 || Flow Checking 違反主機連線數量網路政策(1368>限制數量:700) to Deny this IP cannot access network

完整程式碼如下

#!/usr/bin/python
# -*- coding: utf-8 -*-
print "Content-type: text/html"
print
# 引入 MySQL 模組
import MySQLdb
#引入 sys 並指定sys為utf-8編碼
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
# 連接 MySQL
db = MySQLdb.connect(host="localhost", user="abc", passwd="pwd", db="test", charset='utf8')
cursor = db.cursor()
# 執行 SQL
cursor.execute("select ip from table;")
result = cursor.fetchall()
# 輸出結果
a=0
for record in result:
        if (a%2)==1:
                print "<FONT  COLOR=FF0000>"
        else:
                print "<FONT  COLOR=000000>"

        print record[0]
        print "<br>"
        print "<br>"
        a=a+1
db.close()

最近在ubuntu 32 位元 開啟chrome時都會出現不在支援此版本的作業系統
表示以後不再支援32位元的版本了
今天要update時出現

W: 無法取得 http://dl.google.com/linux/chrome/deb/dists/stable/Release,在 Release 檔案找不到要有的「main/binary-i386/Packages」項目 (sources.list 項目有問題或檔案格式不對)

可是連64位元的os都出現 XD
要修正一下 source list

sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/etc/apt/sources.list.d/google-chrome.list"

2016/03/04

因為python cgi的中文一直有問題出不來
找了好多資料
方法都不同
有的要轉碼
有的要用module
找到以下的方法
覺得是比較簡單的

#!/usr/bin/python
#encoding=utf-8  或  # -*- coding: utf8 -*-

print "Content-type: text/html"
print

print "Hi, Python."
print "中文"

2016/02/29

關於如何在網頁上執行python目前找到二個方法
一個是在apache中載入module
有二個module可以用

http://modpython.org/
https://code.google.com/archive/p/modwsgi/

根據一般的說法是wsgi的效能會比modpython好二倍以上
使用方式是在apache啟動時載入模組

另一個方式是採用cgi
直接把寫好的python放在 /var/www/cgi-bin/下

在程式碼的最前面加上
print "Content-type: text/html"
print

這樣就能直接用了

bash perl 也是相同的方法

目前先採用cgi的方式

http://blog.xuite.net/autosun/study/42871538-%5BUbuntu%5D+%E5%AE%89%E8%A3%9D+Apache2+%2B+Python+%2B+MySQL

2016/02/24

今天有人問到如何把指令的結果同時輸出到螢幕及檔案
使用tee

date | tee -a today