2015年5月12日 星期二

lubuntu 15.04 install ntopng

因為要安裝的電腦是舊的筆電Intel Pentium M 1.6GHz
Ntop官網可下載的rpm和deb都是for x64電腦使用的
所以必須下載source code 自行compiler
安裝過程紀錄如下



 ntopng要安裝在i386舊電腦,必須用source重新compiler

先download source file

解壓縮到自訂目錄,例如/home/ntopng-1.2.0

安裝compiler需要的套件
apt-get install build-essential
apt-get install libglib2.0 libxml2-dev libpcap-dev libtool rrdtool autoconf automake autogen redis-server wget libsqlite3-dev libhiredis-dev libgeoip-dev

開始compile

cd /home/ntopng-1.2.0
$sudo  ./autogen.sh
$sudo  ./configure

checking for GeoIP_lib_version in -lGeoIP... yes
checking for nl_handle_alloc in -lnl... no
checking for sqlite3_open in -lsqlite3... yes
FATAL ERROR: svn is not installed on your host
出現錯誤



$sudo apt-get install subversion
重新執行
$sudo  ./configure

You are now ready to compile typing make
Please do not forget to download GeoIP databases doing: make geoip

$ sudo make
make完成後所有產生的檔案都放在/home/franco/ntopng-1.2.0下
$ sudo make install
產生正式系統程式檔案

$sudo make geoip

franco@lubuntu02:/etc/ntopng$ sudo service redis start
Failed to start redis.service: Unit redis.service failed to load: No such file or directory.
啟動ntopng前,要先啟動redis
啟動redis出現問題

從 Chris Lea 的 PPA 安裝 redis-server

$ sudo add-apt-repository ppa:chris-lea/redis-server
$ sudo apt-get update
$ sudo apt-get install redis-server

檢查redis是否啟動
sudo /etc/init.d/redis-server status


啟動ntopng
sudo mkdir /etc/ntopng
cd /etc/ntopng
sudo vi ntopng.start
加入
-G=/var/run/ntopng.pid
--local-networks "10.88.1.0/24"
--interface eth0

sudo ntopng ntopng.start

然後開啟web
http://localhost:3000
default user:admin pwd:admin

2015年5月11日 星期一

lubuntu 15.04安裝wireshark

$ sudo apt-get install wireshark
$ sudo dpkg-reconfigure wireshark-common
$ sudo usermod -a -G wireshark $USER
重新登入
因為使用者加入wireshark群組,必須重新登入,才會生效
否則會出現interface沒有權限使用

2015年5月7日 星期四

curl指令用法

curl

參考來源:
http://evelynnote.blogspot.tw/2011/03/curl.html



curl 是 Linux 下一個很強大的 http 命令列工具
curl 比 wget 強大的地方在於他還能支援上傳

1) 取得網頁內容,螢幕輸出
$ curl http://www.linuxidc.com

2) -o: 取得網頁內容,檔案輸出
$ curl -o page.html http://www.linuxidc.com

3) -x: 指定 http 使用的 proxy
$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com

4) -D: 把 http response 裡面的 cookie 資訊另存新檔
$ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

5)-b: 把 cookie 資訊加到 http request 裡
$ curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com

6)-A: 設定瀏覽器資訊
#Windows 2000上的 IE6.0
$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com
# Linux Netscape 4.73
$ curl -A "Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

7)-e: 設定 referrer
另外一個伺服器端常用的限制方法,就是檢查 http 訪問的 referer。比如你先訪問首頁,再訪問裡面所指定的下載頁,這第二次訪問的 referer 位址就是第一次訪問成功後的頁面位址。這樣,伺服器端只要發現對下載頁面某次訪問的 referer 位址不是首頁的位址,就可以斷定那是個盜連了
$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.linuxidc.com" -o page.html -D cookie0001.txt http://www.linuxidc.com

8)-O: 使用伺服器上的檔案名,存在本地
$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG

9)可使用 Regular Expression 抓取所有 match 的檔案,指定 match 的群組內容為新檔名
$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG
$ curl -o #2-#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG
原來: ~zzh/001.JPG -> 下載後:001-zzh.JPG
原來: ~nick/001.JPG -> 下載後:001-nick.JPG

10)-c: 續傳 (只能用在原本是 curl 傳輸的檔案)
$ curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG

11) -r: 分塊下載
$ curl -r 0-10240 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
$ curl -r 10241-20480 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
$ curl -r 20481-40960 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
$ curl -r 40961- -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3
Linux用 cat zhao.part* > zhao.mp3合併
Windows用copy /b 合併

12) -u: 指定 FTP 帳號密碼
$ curl -u name:passwd ftp://ip:port/path/file
$ curl ftp://name:passwd@ip:port/path/file

13) -T: 上傳檔案
$ curl -T localfile -u name:passwd ftp://upload_site:port/path/
$ curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi
(注意這時候使用的協定是 HTTP 的 PUT method)

14) Http GET 與 POST 模式
GET 模式什麼 option 都不用,只需要把變數寫在 url 裡面就可以了比如:
$ curl http://www.linuxidc.com/login.cgi?user=nickwolfe&password=12345
而 POST 模式的 option 則是 -d
$ curl -d "user=nickwolfe&password=12345" http://www.linuxidc.com/login.cgi
到底該用 GET 模式還是 POST 模式,要看對面伺服器的程式設定。比如 POST 模式下的文件上傳



這樣一個 HTTP 表單,我們要用 curl 進行模擬,就該是這樣的語法:
$ curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi

15) https 使用本地認證
$ curl -E localcert.pem https://remote_server

16) 通過 dict 協定去查字典
$ curl dict://dict.org/d:computer

2015年4月30日 星期四

安裝lubuntu 15.04中文亂碼

下載lubuntu 15.04光碟進行安裝時,原本要安裝繁體中文,但安裝畫面顯示的中文(繁體)是亂碼,只好先安裝英文版再想辦法安裝中文介面


sudo vi /etc/default/locale
修改2行
LANG=”zh_TW.UTF-8”
LANGUAGE=”zh_TW:zh”

存檔後重新開機
登入後會提示是否要改成中文顯示的訊息
按確定後,介面就變成中文了


微軟今天發佈Windows 10 build 10074

微軟今天發佈Windows 10 build 10074

ISO下載連結
http://windows.microsoft.com/en-us/windows/preview-iso-update-1504

CentOS 7 關閉root使用SSH登入


關閉root使用SSH登入
vi /etc/ssh/sshd_config
#PermitRootLogin yes
修改為:
PermitRootLogin no

#systemctl restart sshd.service

整理一下apt-get工具的說明資料

整理一下apt-get工具的說明資料
資料來源:
http://people.debian.org.tw/~moto/debian/DebianLessPain/Debian-Install-Guide-5.html



使用apt-get更新軟體,需要先設定軟體資料來源,資料來源設定檔是/etc/apt/sources.list

/etc/apt/sources.list 內容格式
deb uri distribution [component1] [componenent2] [...]

deb
這一欄只有兩種寫法,分別為 『 deb 』 與 『 deb-src 』,前者表示所指向的為存放 binary 格式 ( 編譯好執行檔的軟體套件 )
軟體套件的伺服器位置,後者則為 sources 格式 ( 包含原始碼的軟體套件 ) 軟體套件的伺服器位置。

簡言之,一般我們只想要安裝該軟體而不想要去重新編譯它時,就在這一欄填入 『 deb 』 ,
如果你想取得某軟體的原始碼 ( sources code ) ,就得加入 『 deb-src 』 , 當然也可以兩行都寫,如下:

deb http://http.us.debian.org/debian stable main contrib non-free
deb-src http://http.us.debian.org/debian stable main contrib non-free

uri
uri 指的就是軟體套件來源位置,這些位置可以為系統內的某個位置 ( file ) 、可以為 CD-ROM ( cdrom ) 、
可以為網路遠端位置 ( http 、 ftp )..等等,當你下 apt-get 指令時,就會到這些位置去搜尋軟體資料庫。
總括來說一共有 file 、 cdrom 、 http 、 ftp 、copy 、rsh 、ssh 等幾個參數,而比較常用的參數如下列:

  file
  可以是你系統上的某個目錄,如下:
  deb file:/home/moto/debian stable main contrib non-free

  也可以是你 mount 到自己系統裡頭的遠端 NFS Server,如下:
  deb file:/mnt/nfs-server stable main contrib non-free

  cdrom
  這裡當然就是指光碟機上光碟片裡的位置囉,例如:
  deb cdrom:/dists stable main contrib non-free

  http
  透過 http 的協定傳送,例如:
  deb http://http.us.debian.org/debian stable main contrib non-free

  ftp 透過 ftp 的協定傳送,例如:
  deb ftp://ftp.us.debian.org/debian stable main contrib non-free
 
distribution
參數可分為 『 stable 』 、『 testing 』 、『 unstable 』,詳細定義請參考 以水平的觀點來看 Debian 特有的三大族群制度:
stable、testing、unstable 一節。

  stable
  由 『 stable 』 這名詞就可以猜到八九分意思了吧,是的!這是 Debian 對外發行的版本,這個版本的最大特色就是穩定,
  但相對的各個軟體套件則通常不是最新版。
  這個版本適用在最需要穩定的 Server 架設環境,所安裝軟體較少也較為固定。

  testing
  『 testing 』 雖名為測試版,實則已經相當接近於 『 stable 』 版本的程度,這個版本的軟體多半是在 『 unstable 』 中經由維護、
  開發人員不斷的測試之後流入,所以在某種程度來說,其實已經做過初步的檢測,這裡頭的軟體大多也是相當穩定的,而且個軟體套件也都會比 『 stable 』 裡頭的新,不過以軟體總量來說則比上 『 stable 』 及 『 unstable 』 中來的完整、來的多。
  筆者強烈建議如果想把 Debian 拿來當作 Desktop 平台,『 testing 』 是個很不錯的選擇。

  unstable
  『 unstable 』對我來說才算是 『 測試版 』,這裡頭最大的特色就是軟體更新速度快,幾乎都與該軟體同步,因為太新相對的使用
  『 unstable 』 的人也必須承擔更高的風險,有時候您可能會遭遇到一早更新完所有軟體後,發現有些軟體不能正常運作的狀況,
  不過慶幸的是這種情形大概只會持續一兩天左右,因為我說過 『 unstable 』 的特色就是更新速度快,一旦有人回報問題,
  維護的人很快就會作修正。


component
參數共分為 『 main 』、『 contrib 』、『 non-US 』、『 non-free 』 詳細定義,
請參考 以垂直的觀點來看 Debian 軟體的分佈:main、contrib、non-free、non-us 一節。

  main
  Debian distribution 最基本及主要且符合自由軟體規範的軟體 ( packages )。

  contrib
  這裡頭軟體雖然可以在 Debian 裡頭運作,即使本身屬於自由軟體但多半卻是相依於非自由 ( non-free ) 軟體。

  non-free
  不屬於自由軟體範疇的軟體。

  non-us
  這個分類裡頭的軟體都來自非美國地區,當中可能有牽扯到專利、加密..等等問題。
 

通常 sources.list會加入testing 和 stable來源,若在 testing找不到,會到stable找
在台灣,可以改用台灣的來源



台灣 debian mirror site 列表
淡江
deb http://ftp.tku.edu.tw/OS/Linux/distributions/debian/ testing main non-free contrib
deb http://ftp.tku.edu.tw/OS/Linux/distributions/debian/non-US testing/non-US main non-free contrib
       
debian 台灣
deb http://debian.linux.org.tw/debian woody main non-free contrib
deb http://debian.linux.org.tw/debian-non-US woody/non-US main non-free contrib
       
中山
deb ftp://ftp.nsysu.edu.tw/Linux/Debian/ testing main contrib non-free
deb ftp://ftp.nsysu.edu.tw/Linux/Debian/debian-non-US testing/non-US main contrib non-free


更新使用apt-get工具

apt-get update
軟體資料庫同步
這是『 apt-get 』指令的起點,在下達任何 『 apt-get 』 相關軟體安裝或升級指令前,一定得先下『 apt-get update 』指令,
這會讓系統依照 『 sources.list 』 設定檔內紀錄的軟體來源伺服器位置,進行軟體資料庫比對動作,
如此才能知道目前系統上安裝的軟體跟伺服器上可抓取的軟體版本是否一致,如不一致表示有更新版的軟體可以升級或安裝,
接下來的 『 apt-get install 、 apt-get upgrade 、 apt-get dist-upgrade..』才能完成後續動作。

apt-get install
軟體安裝
安裝軟體最怕的就是軟體間的相依、相斥關係,在 『 前言 』 裡頭筆者也提到過去使用的其他 GNU/Linux Distribution 的惱人經驗,
但是在 Debian 裡頭安裝軟體是一件非常愉悅的事情,只要 『 apt-get install 』一行指令簡簡單單輕輕鬆鬆即可完成,
所有相依、相斥 Debian 都會幫我們 take care ,您要做的就是 『 Say Yes 』。

apt-get remove
軟體移除
與 install 一樣,Debian 一樣會幫您處理移除軟體時所發生的相依問題。

apt-get upgrade
軟體升級
平常我們很難顧慮到系統上所安裝的數十甚至數百套軟體的版本是否有新版出現,
現在只要下這個指令 Debian 便會自動找出所有有新版的軟體套件並逐一升級。

apt-get dist-upgrade
系統升級
當轉移整個系統時,如 『 stable 』 轉換到 『 testing 』,或是系統運行好一段時間都應該下這個指令,
它會聰明的處理到很多軟體相依、相斥的問題。

apt-get source
如果您想取得某個軟體套件 ( packages ) 的原始碼可以透過這個指令達成。

apt-get clean
我們透過 apt-get 安裝的任何軟體都會先下載到 『 /var/cache/apt/archives/ 』及 『 /var/cache/apt/archive/partial/ 』 目錄底下,
一般預設 apt-get 在安裝完軟體後是不會把上述位置底下的 『 .deb 』 殺除,一段時間後您如果覺得系統空間不足,
您可以下 『 apt-get clean 』讓系統自動清理這個目錄。

apt-get autoclean
類似 『 apt-get clean 』,下此參數時 apt-get 在安裝完畢後會自動刪除該軟體的 『 .deb 』 檔。

apt-get check
apt-get 不是萬能,有時候也是會出現問題,遇到有問題的時候您可以下 『 apt-get check 』來診斷問題所在。

apt-get remove --purge 'deborphan' ( 清除系統多餘的 library )
當您使用 debian 一段時間後,如果您經常安裝、移除軟體一定會出現殘餘 library 在系統的狀況,原因是當您安裝軟體時,
debian 依照軟體相依特性安裝了額外的 library,但是當您移除該軟體時,當初連帶安裝的 library 不見得會一起被移除,
久而久之系統就會出現殘餘的 library,這個時候您便可以下這行指令,為您掃除系統中無用的 library ,確保系統的清潔性。

ubuntu 安裝完kubernetes後做apt-get update會出現錯誤

root@k8s02:~# sudo apt-get update 已有:1 http://tw.archive.ubuntu.com/ubuntu xenial InRelease 已有:2 http://tw.archive.ubuntu.com/ubuntu xenia...