2012/11/18

昨天逛書局看書的時候看到一個不錯的p2v的軟体
winimage
http://www.winimage.com/download.htm
檔案很小
可以直接把硬碟轉成VHD或VMDK的格式
速度很快

PS 這個工具只能轉整個硬碟 而不能針對分割區來轉 有點不方便 

20121129後記
這個看起來也不錯 改天來測測
http://technet.microsoft.com/en-us/sysinternals/ee656415.aspx
再用qemu-img轉成raw
qemu-img convert source.vhd -O raw destination.raw

2012/11/06

今天的需求是希望在rsyslog的server上以不同的來源ip來分別存放不同的file
在/etc/rsyslog.conf裡加上以下

:fromhost-ip,isequal,"X.X.X.X" /var/log/isg2000/isg_log

注意logrotate也要加

http://slv922.pixnet.net/blog/post/34655421-centos-5.6-%E4%BD%BF%E7%94%A8rsyslog%E6%8E%A5%E6%94%B6%E5%A4%96%E9%83%A8%E8%A8%AD%E5%82%99%E7%9A%84%E9%80%A3%E7%B7%9Alog

2012/11/04


mysql 預設會使用replicaion的選項
所以會在/var/lib/mysql產生很多mysql-bin.000001.....的檔案
但如果不使用replication
產生這些檔案是沒有意義的,而且會占用相當大的空間
因此
如果要清除這些 log
可使用如下指令
mysql> reset master
Query OK, 0 rows affected (3.56 sec)

若不需使用replication,可在my.cnf內把log-bin=mysql-bin mark掉
#log-bin=mysql-bin

2012/11/02

今天有人提到網站rtt的問題
找了一下資料
可以使用hping這個工具

http://backdrift.org/how-to-ping-a-tcp-port

2012/10/26

昨天升級完proxmox 2.2後
有一台机器reboot後所有的guest os都沒起來
到官網問了一下
沒什麼答案
不過有人回應


/etc/init.d/cman restart
/etc/init.d/pve-cluster restart

如果下次重開再沒起來再來試試


http://forum.proxmox.com/threads/11584-guest-os-no-boot-after-host-reboot

2012/10/20

如何在ibus的倉頡輸入標點符號

打入zx然後按上下鍵就可以選了

http://www.arthurtoday.com/2010/08/ubuntu-ibus.html#.UIJE77QQS0w

2012/10/19

mysql query大量資料時出現

ERROR 2008 (HY000): MySQL client ran out of memory

解決方法
在connect時要加上 -q 的參數

mysql -q -u root -p

加上 -q 的目的是query到的資料不放cache直接show出來
這樣才不會塞爆記憶体
從snort 的mysql 中撈出所需的資料

select signature.sig_name,event.timestamp,inet_ntoa(iphdr.ip_src),inet_ntoa(iphdr.ip_dst) FROM iphdr,event,signature where inet_ntoa(iphdr.ip_dst)="1.1.1.1" and iphdr.cid=event.cid and event.signature=signature.sig_id;

snort table schema



2012/10/12

剛check了一下snort的版本
snort 2.9.3.1
並且發現官方已經不再提供 snort-mysql的rpm了
google了一下 snort以後也不會再對mysql支援
所以必須自己想辦法
必須利用
barnyard2
http://www.securixlive.com/barnyard2/index.php
來把snort 的log再轉入mysql
正在try
http://gsxbinary.blogspot.tw/2010/07/snort-barnyard2-mysql-base-intro.html

2012/10/15 補充

安裝 snort-2.9.3.1-1 這個版本有一個特別要注意的地方就是

white_list.rules 及 black_list.rules 一定要touch二個空檔出來
否則preprocesser會自動停掉 導致之後的rule都不能跑 切記

另外要注意的地方就是在產生unified2 log file的地方在config裡一定要這樣下

output unified2: filename snort.u2, limit 128

開机啟動的script放在/etc/rc.local如下


/usr/sbin/snort -c /etc/snort/snort.conf -i eth1 -l /var/log/snort -D

/usr/bin/barnyard2 -c /etc/barnyard2/barnyard2.conf -d /var/log/snort -f snort.u2 -w /etc/barnyard2/barnyard2.waldo -D

2012/10/17 補充

升級後在BASE的畫面中看到的特徵就只有snort alert 如下


爬了一下文
發現是/etc/barnyard2/barnyard2.conf裡沒設好
要改成如下(路徑要設對)

config reference_file:      /etc/snort/rule/etc/reference.config
config classification_file: /etc/snort/rule/etc/classification.config
config gen_file:            /etc/snort/rule/etc/gen-msg.map
config sid_file:            /etc/snort/rule/etc/sid-msg.map

重開机後就正常了

2012/10/07

自從nas升級完後導致proxmox各個client都怪怪的
嚴重的node從console看到都變成紅色 而且看不到裡面的clinet 雖然所有的clinet都過運作正常
本來之前是都重開机處理
但因為重開机要shutdown所有的host
所以到官網爬了一下文
工程師提供一個指令

service pvestatd restart

執行後回復正常

nas不知到還要搞多久
XD

2012/10/01


今天因為nas重開 導致client的nfs出問題
出現以下error

df: `/mnt/bck': Stale NFS file handle

使用以下使用先強制umount  再重新mount就可以了(系統原則上會自己mount回來)

umount -f /mnt/bck



之前更新了mldokney的版本之後
search的非英文檔名都沒問題
可是下載後全部變成 "_" (底線)
google了很多方法都沒用
最後是改了
.mldonkey裡的downloads.ini的
filenames_utf8 = true
(預設為false)
才搞定
執行user的LANG無需做任何更改

2012/09/25

移机時使用rsync -av 可以保留檔案的 使用者及權限的屬性

2012/09/20

今天從某個user拿到一封詐騙mail
竟然是中文的喔
有史以來第一封中文的

點下link後

還是英文的 真不夠用心
另外偽造的發信人也不對
應該要用敝校的email比較像
查了一下log 
mail從芬蘭發來
link是連到米國

2012/09/16

netstat -antp 就可以看出那個程式使用那一個port

2012/09/12

最近新買了一hp dl380 g8 要做web server的備援机
要考慮的就是資料同步的問題了
不考慮HA即時同步 只在一台出問題時 另一台改完ip後能暫時運作
所以預計每天晚上同步資料一次
檔案資料可以用rsync
但db就要考慮lock的問題了
查了一下資料

mysql可以用mysqldump來備份執行中的db而不用shutdown 但當量大時時間過久而且restore更久 不考慮

另外就是mysqlhotcopy(mysql自帶工具)
這個是直接copy mysql的資料檔案,所以復原時直接copy檔案就可以了 速度快又方便 但只能備份myisam的資料庫 無法在innodb上使用

語法如下
mysqlhotcopy -u root -p password --addtodest dbname /backup/path

若要備份全部db 語法如下
mysqlhotcopy -u root -p password --addtodest --regex . /backup/path

若要備份innodb(也可以備份myisam)
可以使用http://www.percona.com/doc/percona-xtrabackup/
操作方法可參考
http://blog.chinaunix.net/uid-20728886-id-138116.html
http://ezerg.iteye.com/blog/1029826

2012/09/02

最近被java搞的很頭痛
因為在ubuntu 12.04上使用proxmox來開guest時需要使用到java
但用openjdk 7及icedtea不是無法開就是打開後browser就當了
google了一下才知道ubuntu從10.04後就沒再買java的授權了
應該是因為sun被oracle買走後的關係
而使用openjdk
但有很多程式無法使用openjdk來跑
後來找到這個

https://sites.google.com/site/easylinuxtipsproject/java

目前看來是ok

2012/08/31

最近發生一個問題
就是有一台proxmox的backup都要做十多個小時才能完成
這會影響到正常工作
host os一直都會有 2% - 5% 的 i/o wait
不知道是不是這個影响的
再去看有二台win 2k3 guest的 i/o一直都很高 降不下來
用工作管理員找了一下
發現除了avguard外另外就是cisvc.exe這個process i/o使用夭壽的高
google了一下

http://blog.xuite.net/coke750101/coketech/30863137

發現cisvc是win用來index用的
建議可以關掉
關了後 guest的cpu使用馬上下降
再觀察看看有沒有什麼影响

所以win 的 guest os
請務必在服務中把"Indexing Service"(索引服務)右鍵單擊,選取“停止”

2012/08/30

在win中使用putty時有個很方便的功能就是使用mouse左鍵選取文字後
直接按右鍵就可以貼到想要的地方
而在ubuntu中則必需按下滾輪來達到相同的目的
這個做法不只是在putty中可用
在所有的視窗都適用

2012/08/29

使用ubuntu預設的file roller時會有亂碼
找了一下


File Roller中文亂碼
Ubuntu 中預設安裝的壓縮管理員程式是File Roller

完全移除rar或unrar

sudo apt-get remove rar
sudo apt-get remove unrar

安裝p7zip和p7zip-rar

sudo apt-get install p7zip
sudo apt-get install p7zip-rar


http://pcm543.blogspot.tw/2010/09/file-roller.html

2012/08/24

最近試怎麼在ubuntu 12.04把tftpd打開
記一下過程

apt-get install tftpd-hpa

俢改/etc/default/tftpd-hpa
TFTP_OPTIONS="--secure"

TFTP_OPTIONS="-l -c -s"

chmod -R 777 /var/lib/tftpboot

service tftpd-hpa restart

2012/08/15

在ubuntu 12.04中的中文輸入還是用倉頡第三代比較習慣
但又沒有取 首*尾 的選字功能
所以必需要再安裝速成

apt-get install ibus-table-quick

就有速成輸入法可以選了
用速成古典版比較ok

2012/08/08

工作上常常需要用到反向的vnc
由user連到我的電腦
今天找到在ubuntu要如何操作
記錄一下


sudo apt-get install x11vnc

vncviewer -listen 81


查詢反向連結的語法

inurl:nkuht.edu.tw -site:nkuht.edu.tw

link:nkuht.edu.tw
之前測linux的bond
在L2 8 ports小型的switch上直接接都沒問題
可是接到 cisco 3750上都會有不定時斷線的狀況
放著好久沒再試
今天再去查了一下
才知道cisco 3750上要再下指令才能正常


cisco-3750(config)#interface range GigabitEthernet 1/0/1, GigabitEthernet 1/0/2
cisco-3750(config-if-range)#channel-group 1 mode active


http://www.geego.com.tw/tech_support/techdocs_easy-to-increase-network-bandwidth

http://backdrift.org/howtonetworkbonding

http://blog.webdir.bg/ubuntu-linux-and-cisco-switch-link-aggregation-load-balancing-bonding/

2012/08/01

最近在測gfs
http://www.howtoforge.com/high-availability-storage-with-glusterfs-3.2.x-on-ubuntu-12.04-automatic-file-replication-across-two-storage-servers
架設簡單快速又方便
而且二台server做HA的空間也不一定要一樣大
還滿好用的
而且client端還可以再把mount進來的檔案用nfs share出去
好物一個


20121111後記

昨天在看document的時侯發現glusterfs3以後原生就支援nfs了
http://gluster.org/community/documentation/index.php/Gluster_3.2:_Manually_Mounting_Volumes_Using_NFS

要注意的就是在server上必須要把rpcbind或portmap這個daemon起起來
完全不需掛載後再來分享
真是太方便了


20121110後記

今天把gfs client直接起在一台gfs server上
再把gfs share的目錄mount進來
之後再把mount進來的目錄使用nfs export出去
完全沒問題
/etc/exports要記得把fsid=0加上去 否則client mount不上


2012/07/28

測 i/o並計算時間的shell


#!/bin/bash
i=1
while [ $i -gt 0 ]
do
start=$(date +%s)
/bin/rm /mnt/test/1/test.iso
/bin/cp /mnt/test/test.iso /mnt/test/1/
end=$(date +%s)
i=$(($i+1))
echo $i > /tmp/test_nas_count
echo $((end-start))"s" >> /tmp/test_nas_count
done

2012/07/22


win7內建show 出ap資訊的指令


netsh wlan show networks mod=bssid



2012/07/17

今天在設定 brocade ICX6450-24P時碰到一些問題
做個記錄

1.這台的sfp支援到10G 當插上1G的sfp後必須要改config才能work
conf t
int e 1/2/1  
speed-duplex 1000-full-master


2.這台是poe switch 但預設沒開 要下指令打開
conf t
int e 1/1/1 to 1/1/24
inline power
這二天使用putty的com來config switch時出現backspace無法作用的情況
查了一下資料 要在config改一個地方 如下圖所示


2012/07/06

mldonkey之前都是用dropbox來輸入bt種子
但最近一直怪怪的
查了一下
只要把種子傳到主机上
之後在web介面上下指令就可以了
startbt /tmp/abc.torrent
觀察 LV目前資訊的指令

pvdisplay
pvs

lvdisplay
lvs

2012/07/03

為了brocade lldp的功能無法在fluke linkrunner AT上使用花了好久的時間
今天在工程師回的mail中提到fws624也支援cdp
找了一下文件
只要下cdp 就可以
但下完後
還是沒看到訊息 而且連cisco 7609的訊息都擋掉了
再查了一下
還必須把fdp打開
fdp run

這樣就可以在linkrunner AT看到硬体訊息了

總結二個指令
cdp run
fdp run
缺一個都不行
預設所有的port都會開

http://community.brocade.com/thread/5072?start=0&tstart=0

PS.繼續等待brocade對lldp的回應
最近有個朋友的電腦只要開啟有avi檔案的資料夾
就會出現explorer.exe錯誤
查了一下
有人說是預覽功能的問題
下指令關了

regsvr32 /u shmedia.dll

沒再發生

2012/07/01

最近在使用mldonkey時一直出現 to many open file的問題

查了一下

# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 147456
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 147456
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

然後把open file改為10240

ulimit -n 10240

再觀察看看
昨天上課的時候才知道win有個好用的指令
pathping
找了一下linux有沒有相關的
發現mtr功能更強大

2012/06/30

最近把所有pc上的vm全部轉到 HP DL380 G7 上
而guest os全部放在server的肚子裡 這樣就可以方便用 snapshot來進行backup 而不用停機
(建議使用外接的storage跑iscsi 這樣也可以用snapshot備份)
但最近發現備份總是備不完
原因是卡在其中的一個guest
找了好久 發現應該是snapshot滿了
因為vzdump預設只會開1G的snapshot 而當snapshot滿了後 整個備份就會停住 卡在當時備份的guest  這時就要把這個process kill掉才能再接下去 而kill 掉的這個備份也就不會成功
早上又發生了
用lvs看了一下


 proxmox#lvs
  LV                 VG   Attr     LSize  Pool Origin Data%  Move Log Copy%  Convert
  data               pve  owi-aos-  1.25t                                      
  root               pve  -wi-ao-- 40.00g                                      
  swap               pve  -wi-ao-- 70.00g                                      
  vzsnap-proxmox78-0 pve  swi-aos-  1.00g      data     100


果然是滿了

再到forum找找如何增加sanpshot的size


Re: Backup vzdump hanging at vmtar
its only 1 gb, increase to 2 gb (see below).

as you did not answer to my question regarding vzdump.conf I assume you do not have any settings there.

just create the file and enter:
Code:
nano /etc/vzdump.conf
Code:
size: 2048

為了省麻煩
這裡直接加到10G

再觀察看看囉

2012/06/25


今天在找利用python 來傳gtalk訊息的方法
並不困難
程式碼如下

import xmpp

login = 'abcde' # @gmail.com
pwd   = '123456'

cnx = xmpp.Client('gmail.com')
cnx.connect( server=('talk.google.com',5222) )

cnx.auth(login,pwd, 'botty')

cnx.send( xmpp.Message( "defghi@gmail.com" ,"Hello World from abcde!!!" ) )

==========================================================

加上測port變成一個監控机器人


import xmpp
import socket

address='1.1.1.1'
port = int(80)
p = str(port)
mes=address+' port '+p+' ok'

s = socket.socket()
try:
        s.connect((address,port))
        print s

        login = 'abcde' # @gmail.com
        pwd   = '123456'

        cnx = xmpp.Client('gmail.com')
        cnx.connect( server=('talk.google.com',5222) )

        cnx.auth(login,pwd, 'botty')

        cnx.send( xmpp.Message( "defghi@gmail.com" ,mes ) )
except:
        print "fail"



2012/06/24

最近有一個需求是想把小主機放在螢幕後
取代原電子看板
os使用ubuntu 12.04
這樣只要固定開特定網頁就可以了
但只要把keyboard mouse拆下來再重開後
過不了多久螢幕還是會進入保護模式而變黑
測了好久
發現是xwindows的問題
就算在設定上都把螢幕保護及電源管理關了
還是會發生
最後找到下列的指令
加到預設登入user的.profile後
就沒再發生了

export DISPLAY=:0.0 && /usr/bin/xset dpms 0 0 0

export DISPLAY=:0.0 && /usr/bin/xset -dpms
export DISPLAY=:0.0 && /usr/bin/xset s 0 0
export DISPLAY=:0.0 && /usr/bin/xset s noblank
export DISPLAY=:0.0 && /usr/bin/xset s noexpose

要看所有設定的話用
xset -q
今天開chrome時出現無法讀取設定檔的錯誤
查了一下資料
關閉chrome
把home目錄下 .config裡的google-chrome這個目錄砍了
再重開chrome就ok了

2012/06/23

之前用openfiler來測iscsi給proxmox用
測完把openfiler拿掉後
proxmox的機器上就一直出現


/dev/sdh: read failed after 0 of 4096 at 0: Input/output error
/dev/sdh: read failed after 0 of 4096 at 10234036224: Input/output error
/dev/sdh: read failed after 0 of 4096 at 10234093568: Input/output error
/dev/sdh: read failed after 0 of 4096 at 4096: Input/output error

這樣的error
應該是雖然iscsi拿掉
但os捉到的disk卻還掛著
本來是想不理他
等下次升級kernel再reboot應該就會解決了
但最近的排程backup一直出問題
不知道是不是因為這個原因
所以查了一下資料
要怎麼在不reboot的情況下把disk拿掉
只要一行指令

echo offline > /sys/block/sdh/device/state

雖然在/proc/scsi/scsi還是有看到


Host: scsi9 Channel: 00 Id: 00 Lun: 00
  Vendor: OPNFILER Model: VIRTUAL-DISK     Rev: 0
  Type:   Direct-Access                    ANSI  SCSI revision: 04
Host: scsi10 Channel: 00 Id: 00 Lun: 00
  Vendor: OPNFILER Model: VIRTUAL-DISK     Rev: 0
  Type:   Direct-Access


但i/o error的訊息不會再跑出來了



2012/06/22


用 sed 刪除包含某字串的行
sed -e /searchString/d -i filename

2012/06/13

使用proxmox備份時
如果image是放在local 或 iscsi 可以使用snapshot的方式來進行backup
如此就不會有downtime
但要注意
因為LVM會在/mnt/vzsnap0產生一個原image的snapshot
所以/mnt/vzsnap0所在的磁碟空間必須要大於或等於欲備份image的大小
否則備份就會不成功
只能使用suspend來備份

20120615 修正

應該是進行snapshot備份時會先把原來的檔案lock住
之後的變動先寫到暫存區
備份完成後再unlock
再把暫存區中的資料寫到檔案上
所以只要時間不長
用來放暫存資料的空間不需要很大

2012/06/09

今天一直在找串流的解決方案
目前比較方便的方法是直接使用html5的video tag
再把檔案轉成webm 或 mp4放上去
以下是可以轉檔,合併,裁切的軟体
還不用
http://www.freemake.com/tw/

2012/05/29

升到 1204 後每次開chrome都會出現“存取預設鑰匙圈"的對話視窗
查了一下資料
執行 seahorse
把"預設" 那筆資料刪除就ok了

2012/05/28

一般crontab都是在背景執行
但有個需求是在圖形介面下要執行chrome
就必需要借用xterm了
指令如下

1 1 * * * /usr/bin/xterm -display :0 -e /usr/bin/google-chrome http://udn.com

2012/05/27


要在ifame裡讓網頁能refresh
只要在原始的網頁加上meta就可以了
如下

test.html

<html>
<body>
<Iframe src="1.html"; width="800" height="25" scrolling="no" frameborder="0"></iframe>
</body>
</html>
=====================================================

1.html


<html>
<head>
<meta http-equiv="refresh" content="2" />
</head>
<body>
ifram 8888
</bdoy>
</html>

如此只要修改1.html的內容 test.html 2秒後就會自動更新

如何讓chrome 一執行就進入全螢幕並且開啟 http://www.hinet.net

chrome.exe --kiosk http://www.hinet.net
今天想到一個需求
要將youtube的影片自動並重複播放


新版iframe內嵌程式碼
新版因為採用新的技術來播放影片,而YouTube也尚未釋出新的自動播放參數,所以只需修改一下新版iframe內嵌程式碼 就可以達成我們自動播放YouTube嵌入影片的目的!
原理是把新版iframe內嵌程式碼的影片網址改成舊版embed內嵌程式碼的影片網址就可以重新使用舊版的YouTube嵌入影片的自動播放參數。

首先必須把藍色的embed

<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/pY5jko0w8PQ" frameborder="0" allowfullscreen></iframe>

改成v
<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/v/pY5jko0w8PQ" frameborder="0" allowfullscreen></iframe>

然後同樣地把自動播放參數
&autoplay=1

重複播放參數為
&loop=1

加在綠色的影片ID後面
<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/v/pY5jko0w8PQ&autoplay=1&loop=1" frameborder="0" allowfullscreen></iframe>

http://happy-yblog.blogspot.com/2011/03/youtube_28.html

===================================================================
建立公開播放清單後也可以使用

<iframe width="853" height="480" src="http://www.youtube.com/embed/videoseries?list=PL79665B85A32A6DC1&amp;hl=zh_TW" frameborder="0" allowfullscreen></iframe>

改為

<iframe width="853" height="480" src="http://www.youtube.com/embed/videoseries?list=PL79665B85A32A6DC1&autoplay=1&loop=1" frameborder="0" allowfullscreen></iframe>

用BlueGriffon編輯時以上的語法會顯示有錯誤

要改成如下


<iframe width="560"
          height="315" frameborder="0" src="http://www.youtube.com/embed/videoseries?list=PL79665B85A32A6DC1&amp;autoplay=1;loop=1;hl=zh_TW"
          allowfullscreen="1"></iframe>


還沒找到去除廣告的方法

2012/05/25


今天使用了openfiler測了一下iscsi
感覺還不錯用
iscsi應該是未來考慮的方向
但iscsi無法用來backup
所以backup還是要用nfs

LVM Groups with Network Backing

In this configuration, network block devices (iSCSI targets) are used as the physical volumes for LVM logical volume storage. This is a two step procedure and can be fully configured via the web interface.
  1. First, add the iSCSI target. (On some iSCSI targets you need to add the IQN of the Proxmox VE server to allow access.)
    • Click 'Add iSCSI Target' on the Storage list
    • As storage name use whatever you want but take care, this name cannot be changed later.
    • Give the 'Portal' IP address or servername and scan for unused targets
    • disable 'use LUNs direcly'
    • Click save
  1. Second, add LVM group on this target.
    • Click 'Add LVM Group' on the Storage list
    • As storage name use whatever you want but take care, this name cannot be changed later.
    • For 'Base Storage', use the drop down menu to select the previously defined iSCSI target.
    • For 'Base Volume' select a LUN
    • For 'Volume Group Name' give a unique name (this name cannot be changed later).
    • Enable shared use (recommended)
    • Click save


http://pve.proxmox.com/wiki/Storage_Model#LVM_Groups_with_Network_Backing
這個方法是開win7分享比較快的方法


控制台/ 網路和網路時間 / 網路和共用中心

點 網路共用設定 遵守以下開放設定

開放網路探索

開啟檔案及印表機共用

開啟共用,只獨取具有網路存取的人員讀取和寫入公用資料夾中的檔案

關閉以檔案保護共用

使用使用者帳戶和密碼連線到其他電腦    <<我這個剛好沒設定到!

在資料夾 按 鼠標 右鍵

共用對象 / 特定人員

選擇 Guest 點 新增(A) 後 按下 共用(H) 離開 其他作業系統 網路芳鄰 就可進入
這是要在名稱那設個Guest這個名稱,再按照過程設定!


http://tw.myblog.yahoo.com/jw!s3sQQxaBGw6A8aLmgO3xCzgU/article?mid=290&prev=291&next=289

2012/05/22

今天把snort 升到2923
有點小麻煩

首先需要再上
libdnet-1.11-1.2.el6.rf.i686.rpm
才能安裝
裝完改完config
執行
 /usr/sbin/snort-mysql -i eth1 -D -c /etc/snort/snort.conf
出現找不到 libdnet.1這個檔
明就有裝 Orz
找了一下

/usr/lib/libdnet.so.1.0.1
/usr/lib/libdnet.so.1


但沒有libdnet.1
算了
link給牠
ln -s libdnet.1 libdnet.so.1.0.1
再執行
/usr/sbin/snort-mysql -i eth1 -D -c /etc/snort/snort.conf

搞定!!

PS. oinkcodes還是不能下載 已經一個多星期了 效率有夠差的 還收錢

2012/05/21

之前把python轉成exe時在轉完後都要用7z壓縮後再轉成exe檔
今天找到一個方法
直接就可以用了

把setup.py改成如下就可以了

from distutils.core import setup
import py2exe
 
setup(
    options = {"py2exe": {"compressed": 1, "optimize": 0, "bundle_files": 1, } },
    zipfile = None,
    console=["test.py"]
)

再執行

c:\python27\python.exe setup.py py2exe


2012/05/18

今天有必須在win上使用sftp來備份的需求
找到了這一篇
還不錯用
winscp可以下載portable的版本 不用安裝


@echo on (將執行中的訊息印出來)
cd c:\program files\winscp (再把工作目錄轉到 winscp的安裝目錄)
winscp.com /command "option transfer automatic" "option echo on" "open sftp://username:password@11.22.33.44:22" "synchronize remote -mirror -delete -criteria=both d:/somedir /myhome/remotedir" "close " "exit"

其中一對quotation mark代表一個指令
前面兩個option設定transfer mode(option transfer automatic), 並印出執行間的訊息(option echo on)
再來用ssh的帳號(e.g. username)密碼(password,請用你自己的) 走sftp,port22登入 (open sftp://username:password@11.22.33.44:22)
最後 "synchronize remote -mirror -delete -criteria=both d:/somedir /myhome/remotedir"
做synchronize 採單向備分(參數remote),如果有檔案在遠端 (/myhome/remotedir)目錄下,卻不在local (d:\somedir) 裡,就將其刪除 (參數 -delete)
完成以後利用 "close" 關閉這一個session,再利用 "exit"離開 winscp
最後再排程執行即可


http://freegroupon.blogspot.com/2012/03/winscpsftp.html

2012/05/14


升到ubuntu 12.04後snmpwalk取得的值也變了
變為都是iso開頭
所以這部分程式也要改

原 /usr/bin/snmpwalk -c test -v 2c 1.1.1.1 enterprises.26104.1.1.1.3 已不能用


要改成如下

/usr/bin/snmpwalk -c test -v 2c 1.1.1.1 iso.3.6.1.4.1.26104.1.1.1.3

不知為什麼 :(
升到12.04後
mysql_db_query已不再支援
所以程式做了一點修正


$link=mysql_connect(localhost,test,test);//先連上資料庫
$sdb=mysql_select_db(cacti,$link);//再選擇使用那一個db(cacti)
$sqlins="select hostname,status,status_fail_date from host where status = 1;";
//$res=mysql_db_query(cacti,$sqlins,$link);//已不再支援
$res=mysql_query($sqlins,$link);//改用mysql_query
今天把cacti的机器由8.04升到12.04
目前看來應該是ok
再觀察看看

2012/05/13

openvas 2012/5/10出了 5版
原來安裝的4版會自動升級
但升級完後不能用
重新跑了
openvas-setup
重開机後ok

2012/05/10

最近買了一台Fluke LinkRunner AT Network Auto-Tester
廠商建議把L2 switch的lldp打開
在brocade上只要進config
下 lldp enable即可

後記
設了之後fluke還是看不到switch的訊息
詢問原廠中
還沒下文


2012/05/06

為了要備份mail
選擇使用rsync
但因為資料資料將近1T
而且都是小檔案(maildir格式)
一開始要全部rsync時總會做到一半就斷了
只好再次rsync
前後好几次
終於完成第一次全部的rsync
接下來每次只要rsync異動的部分
約半小時
使用crontab每天二點來做

指令如下

if [ -d /mnt/mail ]; then

        #echo "ok"
        /usr/bin/rsync -av --delete --size-only /home /mnt/mail > /root/rsync_log
fi

使用if來check的原因是為了避免如果nas沒mount到
會把/mnt塞爆

2012/05/03

最近有個需求就是user的proxmox机器是不上internet的
但硬体上的時間卻一直不準 差了好几天
唯一能上網的是一台win 7
本來是想用win 7內建的 w32time來當ntp
但試了好久就是不行
查了一下資料
win預設的ntp是不能提供linux對時的
找到了以下的軟体
http://www.meinberg.de/english/sw/ntp.htm#ntp_nt_stable
裝上後在win 7上加一條 f/w的規則
把udp 123打開
搞定

2012/05/02


今天測了一下rsync
參數不管怎麼下
結果好像都差不多

time rsync -v -u --inplace /var/lib/vz/images/204/vm-204-disk.qcow2 /mnt/pve/nfs_49/dns_dos/
vm-204-disk.qcow2

sent 5921015635 bytes  received 31 bytes  43061932.12 bytes/sec
total size is 5920292864  speedup is 1.00

real    2m16.284s
user    0m47.094s
sys     0m22.522s

=======================================================================

 time rsync -avy /var/lib/vz/images/204/vm-204-disk.qcow2 /mnt/pve/nfs_49/dns_dos/
sending incremental file list
vm-204-disk.qcow2

sent 5921015639 bytes  received 31 bytes  37593750.29 bytes/sec
total size is 5920292864  speedup is 1.00

real    2m37.259s
user    0m49.275s
sys     0m24.471s

=======================================================================

time rsync -av /var/lib/vz/images/204/vm-204-disk.qcow2 /mnt/pve/nfs_49/dns_dos/
sending incremental file list
vm-204-disk.qcow2

sent 5921015639 bytes  received 31 bytes  41844633.71 bytes/sec
total size is 5920292864  speedup is 1.00

real    2m20.808s
user    0m45.490s
sys     0m21.791s
今天發現了一個不錯用的工具

mirrordir

可以用來做mirror的備份
因為rsync在檔案數多的時候會有問題

用法

mirrordir dira dirb

http://pkgs.repoforge.org/mirrordir/

2012/04/28

今天把 11.04 升到 12.04
因為是fresh install
所以wireless的driver要重裝
因為目前使用的wireless nic沒有linux driver
所以必須使用windows的driver
ubuntu提供了ndiswrapper 可以直接使用windows的driver
記一下過程
apt-get install ndiswrapper
ndiswrapper -i driver.inf

到ndiswrapper 捉source回來make
產生ndiswrapper.ko
先放一份到/root 因為之後升kernel都會用到
再copy 到 /lib/modues/xxxxxxxx.generic-pae裡

vi /etc/modules
加上
ndiswrapper


以下二個步驟之後只要kernel更新都要再做一次
depmod -a (重要)
modprobe ndiswrapper

2012/04/26

2012/04/22

2012/04/20

vm移機減少down time的方法

在開机狀態先使用exdupe備份一次
exdupe z:\ backup.full

關机後再使用exdupe進行差異備份
exdupe -D z:\ backup.full backup.diff1

接下來進行還原
exdupe -RD backup.full backup.diff1 z:\

2012/04/18

自從nessus被source fire買走後
就只有二個版本 一個企業 一個home
而home版限制很多
而且學校使用home版也不合法
因此找到了 opanvas 這個號稱是nessus的分支來使用
安裝方式如下

http://blog.sina.com.cn/s/blog_6eee5308010129n2.html
 
但裝完後原來的 openvas-administrator 無法啟動 必須downgrade


yum downgrade openvas-administrator






而且gsad無法啟動 必須手動啟動 
 
gsad --port 9392 -f -v --http-only 

以下是加user的指令

openvas-adduser
 
win版的client不好用 問題一堆
建議使用web介面操作 
 
以上是在centos 5 x32的情況
大致上是這樣  
============================================================== 
重新在centos 6 x64安裝
完全沒問題
一次搞定
建議使用centos 6 x64 

2012/04/14

今天在snort的log發現來自外部的dns query ddos

所以寫了一支程式來block
要把query log打開
在/etc/named.conf裡加上



logging {


              channel query_log {


                      file "query.log" versions 1 size 20m;


                      severity info;


                      print-time yes;


                      print-category  yes;


              };


              category queries {


                      query_log;


              };


      };


restart dns


2012/04/12

因為大table 效能的問題想把mysql 的 innodb 開起來

找了半天要如何把mysql innodb enable的方法

除了在/etc/my.cnf把innodb的相關參數設好之外

還要以下的動作

/etc/init.d/mysql stop
mv /var/lib/mysql/ibdata1 /var/lib/mysql/ibdata1_bck
mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bak
mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bak

/etc/init.d/mysql start

mysql innodb myisam 轉換的方法

http://phorum.study-area.org/index.php?topic=27865.0


2012/04/11

今天在開console時一直出現
authentication failed
查了一下
原因是時間沒有對準
把ntp server重改
ntp restart
ok

2012/04/09

查看bond 0 的工作狀態

cat /proc/net/bonding/bond0
升到cacti 0.8.8之後的每次更新都必須執行rebuild poller cache的動作

升cacti 0.8.8問題還真不少
升完後rra file一直沒update導致圖出不來
查了半天
本來以為是path_rra出問題
因為這一版要去定義cacti的path
後來查了一下
竟然是poller cache的問題
真是無言
解決方法如下

以系統管理員登入後

點 左边 system utilities 再 點右边 Rebuild poller cache

Subject: Re: How do I alter path_rra? - msg#00063
List: network.cacti.user
Mail Archive Navigation:
by Date: Prev Next Date Index by Thread: Prev Next Thread Index
On Fri, 2004-02-20 at 13:26, Steve Ferguson wrote:
> I had to move my Cacti installation from /opt/software to /usr/local.
> cactid keeps trying to update the rra files in the old location. How do
> I change the path_rra setting? I can't find it anywhere in the GUI and
> I've tried grepping through various files and the database to no avail.

Just go to "Utilities" and clear your poller cache. Everything should
automatically update to the correct (new) path.

Ian


http://osdir.com/ml/network.cacti.user/2004-02/msg00063.html
今天在升到cacti-0.8.8的時候
必須在include/config.php內多改一個東西才能運作


/*
   Edit this to point to the default URL of your Cacti install
   ex: if your cacti install as at http://serverip/cacti/ this
   would be set to /cacti/
*/
//$url_path = "/";
$url_path = "/html/cacti-0.8.8/";

記錄一下 以免忘記

2012/04/02

最近打算要把proxmox 1.9升為2.0
資料檔不用動
但config有二個地方要注意

1. name不能使用 _ 必需使用 -

2.有關network的部分要修改如下
1.9
vlan0: rtl8139=2E:68:52:14:61:99

2.0
net0: rtl8139=2E:68:52:14:61:99,bridge=vmbr0

改完後直接boot就好了

2012/04/01

mysql tunning


MySQL Performance Tuning Primer Script
網站網址:http://www.day32.com/MySQL/
Script下載:http://www.day32.com/MySQL/tuning-primer.sh
執行方式:chmod +x tuning-primer.sh ; ./tuning-primer.sh

MySQLTuner
網站網址:http://blog.mysqltuner.com/
Script下載:http://mysqltuner.pl/mysqltuner.pl
執行方式:chomd +x mysqltuner.pl ; perl mysqltuner.pl


http://portable.easylife.tw/2074

2012/03/28

最近碰到一個問題很怪
user一直反應使用word 2007編輯檔案
使用doc的格式會一直出現記憶体不足的error
改用docx後到目前為止沒再發生
不知如何解釋

2012/03/24

2012/03/22

2012/03/21

今天在設定route-map
因為久沒下
所以有點忘了
記錄一下

1. 一定要先下
sdm prefer routing
這是隱藏指令 很重要

2. 再來設定 access-list
ip access-list extended 101

deny ip 192.168.0.0 0.0.255.255 host 10.0.0.3 (4786696 matches)
permit ip 192.168.0.0 0.0.255.255 any



3.設定route-map
 route-map test permit 10
 match ip address 101
 set ip next-hop 10.0.0.1

4. 再把指令下到port 上或vlan上

ip policy route-map test


http://harlemhsu.pixnet.net/blog/post/20501380-%E8%A7%A3%E6%94%BE-cisco-3560-%E7%9A%84-ip-policy-route-map-(%E7%AD%96%E7%95%A5%E6%80%A7%E8%B7%AF%E7%94%B1)-

2012/03/18

今天在找用批次檔寫一個迴圈
語法如下

for /L %%e IN (1,1,3) do e:\test.bat

2012/03/11


python 印出程式執行時間

import time

# 記錄開始時間 Record start time
tStart = time.time()

# 記錄結束時間 Record stop time
tStop = time.time()

print(tStop - tStart)

http://whhnote.blogspot.com/2010/10/python.html
在python中""" """中的為段落註解
"""
.......
......
.....
這是註解
.....
.....
.....
"""

2012/03/10

想研究一下python 畫圖
先安裝
http://my.opera.com/taiwanmonkey/blog/2012/02/19/python-2

範例

# -*- coding: cp950 -*-
import matplotlib.pyplot as plt

#以直線畫出一個三角形
plt.plot([1,20,20,1],[1,1,20,1],color="green",linewidth=5)
#畫點 r表示紅色 o表示圓形
#詳細在http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.plot
for i in range(10):
    plt.plot([2],[i*2],'ro')
    #plt.plot([i],[i*2],'r1')
    #plt.plot([i],[i*3],'r2')
    #plt.plot([i],[i*4],'r3')
    #plt.plot([i],[i*5],'r4')
    #plt.plot([i])
plt.axis([-10,30,-10,30])
plt.xlabel('x numbers')
plt.ylabel('y numbers')
plt.show()



http://blog.rexzhao.com/category/matplotlib

2012/03/08

使用python寫了一個校外KMS認証的程式
但在64位元上一直有問題
後來請朋友幫忙
發現在32位元上編譯的執行檔在64位元執行有問題
只好在64位元上再重編一次 一切正常
原始碼一個字都沒改
希望這個問題不要碰到太多

2012/03/03


今天在找要如何用python登入apache的認証網頁

找到httplib2

http://code.google.com/p/httplib2/

範例如下

import base64
import httplib2
h = httplib2.Http()
auth = base64.encodestring( 'id' + ':' + 'password' )
resp, content = h.request(
        'http://10.0.0.56/all/',
        'GET',
        headers = { 'Authorization' : 'Basic ' + auth }
    )

print resp        #傳回html的標頭

print content   #傳回html的內容

2012/03/02

7z 建立自解檔順便可以執行程式

http://teejee2008.wordpress.com/7-zip-sfx-maker/

2012/03/01

今天一台vm出現disk空間不夠的問題
參考以下的資料
搞定
改完後記得再用gparted 調整分割大小

修改虛擬機鏡像大小(qcow2/raw resize)
不多說,直接看
創建一個鏡像文件,大小1G,格式是qcow2

muxueqz@muxueqz /tmp $ qemu-img create -f qcow2 t.qcow2 1G
Formatting 't.qcow2', fmt=qcow2 size=1073741824 encryption=off cluster_size=0

查看鏡像文件實際佔用空間
muxueqz@muxueqz /tmp $ ls -alh t.qcow2
-rw-r--r-- 1 muxueqz muxueqz 193K 8月31 13:18 t.qcow2

查看qcow2信息
muxueqz@muxueqz /tmp $ qemu-img info t.qcow2
image: t.qcow2
file format: qcow2
virtual size: 1.0G (1073741824 bytes)
disk size: 136K
cluster_size: 65536

加1G(resize +)
muxueqz@muxueqz /tmp $ qemu-img resize t.qcow2 +1G
Image resized.

再查看qcow2信息
muxueqz@muxueqz /tmp $ qemu-img info t.qcow2
image: t.qcow2
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 140K
cluster_size: 65536

減1G(resize -)
muxueqz@muxueqz /tmp $ qemu-img resize t.qcow2 -- 2G
qemu-img: This image format does not support resize

!!!qcow2只能加不能減!
再查看qcow2信息
muxueqz@muxueqz /tmp $ qemu-img info t.qcow2
image: t.qcow2
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 140K
cluster_size: 65536

果然沒變
再試試改變raw格式的大小(resize raw)
同樣先創建1G大小的raw
muxueqz@muxueqz /tmp $ qemu-img create -f raw t.raw 1G
Formatting 't.raw', fmt=raw size=1073741824
muxueqz@muxueqz /tmp $ qemu-img info t.raw
image: t.raw
file format : raw
virtual size: 1.0G (1073741824 bytes)
disk size: 1.0M

可以看出raw要比qcow2多佔一些空間。
加1G
muxueqz@muxueqz /tmp $ qemu-img resize t.raw -- +1G
Image resized.
muxueqz@muxueqz /tmp $ qemu-img info t.raw
image: t.raw
file format: raw
virtual size: 2.0G (2147483648 bytes )
disk size: 2.0M

減1G(resize -)
muxueqz@muxueqz /tmp $ qemu-img resize t.raw -- -1G
Image resized.
muxueqz@muxueqz /tmp $ qemu-img info t.raw
image: t.raw
file format: raw
virtual size: 1.0G (1073741824 bytes )
disk size: 1.0M


http://www.linuxzh.org/Linux/qemu_resize.html

2012/02/26


今天在用mail.py使用hinet發信時
一直出現以下訊息

Traceback (most recent call last):
  File "send_chk_mail.py", line 5, in ?
    smtp = smtplib.SMTP("168.95.4.10")
  File "/usr/lib/python2.4/smtplib.py", line 258, in __init__
    addr = socket.gethostbyname(socket.gethostname())
socket.gaierror: (-2, 'Name or service not known')

查了半天
最後的解決方法是
把 hostname 加到 /etc/hosts

127.0.1.1       abc.com       abc

2012/02/10

今天為了要把 \ 這個特殊字元加入變數
所以查了一下資料
必須使用二個 \\ 才行
ex:

a = "c:\\"
print a
c:\

2012/02/08

在/etc/raddb/users 裡加入

blacklist_user_name Auth-Type := Reject

即可禁止user認証

2012/02/07

這個問題存在很久了
linux從vmware server轉到proxmox時
如果原來是用scsi 而proxmox也選了scsi
這是開机就會出現
kernel panic - not syncing attempted to kill init
解決方式是在proxmox中選用ide
正常boot

2012/02/06

為了要測試机櫃內加排風扇有沒有作用
有一個新的需求  要知道cpu的溫度
查了一下資料
可以使用lm-sensors來得到資料
步驟如下
apt-get install lm-sensors
(yum install lm-sensors)

#sensors-detect
一直按Enter直到看到

#----cut here----
#...................................
#....................
i2c-i801
# Chip drivers
# no driver for Winbond W83L785R/G yet
lm85
#----cut here----


在二個cut here 中間找到的就是必需insert的module
以上為例

# modprobe i2c-i801
# modprobe lm85

接下來輸入

# sensors

就會出現cpu溫度之類的監控訊息

adm1027-i2c-3-2e
Adapter: SMBus I801 adapter at e000
V1.5: +1.31 V (min = +0.00 V, max = +3.32 V)
VCore: +1.49 V (min = +0.00 V, max = +2.99 V)
V3.3: +3.30 V (min = +0.00 V, max = +4.38 V)
V5: +5.08 V (min = +0.00 V, max = +6.64 V)
V12: +11.97 V (min = +0.00 V, max = +15.94 V) ALARM
CPU_Fan: 3941 RPM (min = 0 RPM)
fan2: 0 RPM (min = 0 RPM)
fan3: 0 RPM (min = 0 RPM)
fan4: 1882 RPM (min = 0 RPM)
CPU Temp: +48.8°C (low = -127.0°C, high = +127.0°C)
Board Temp: +46.0°C (low = -127.0°C, high = +127.0°C)
Remote Temp: +45.5°C (low = -127.0°C, high = +127.0°C)
cpu0_vid: +1.525 V

但在hp的机器中出現的是

#----cut here----
# You must also install and load the IPMI modules
ipmi-si
# Chip drivers
# Warning: the required module ipmisensors is not currently installed
# on your system. For status of 2.6 kernel ports check
# http://www.lm-sensors.org/wiki/Devices. If driver is built
# into the kernel, or unavailable, comment out the following line.
ipmisensors
#----cut here----
但無法使用
modprobe ipmisensors
會有error

但使用

modprobe coretemp

接下來輸入
#sensor
出現
coretemp-isa-0000
Adapter: ISA adapter
Core 0:      +30.0°C  (high = +85.0°C, crit = +95.0°C)  

coretemp-isa-0001
Adapter: ISA adapter
Core 1:      +37.0°C  (high = +85.0°C, crit = +95.0°C)  

coretemp-isa-0002
Adapter: ISA adapter
Core 2:      +33.0°C  (high = +85.0°C, crit = +95.0°C)  

coretemp-isa-0003
Adapter: ISA adapter
Core 3:      +38.0°C  (high = +85.0°C, crit = +95.0°C)
就可以看到了


2012/02/04


http://lccnetvip.pixnet.net/blog/post/33921210-%E8%81%AF%E6%88%90%E9%9B%BB%E8%85%A6%E8%AC%9B%E5%B8%AB%E5%B0%88%E6%AC%84%EF%BC%9A%E8%AB%87-linux-%E7%B3%BB%E7%B5%B1%E7%92%B0%E5%A2%83%E5%BF%AB%E9%80%9F%E5%BB%BA

談 Linux 系統環境快速建立大量的使用者帳號
分享:      
文、小州老師

§章節:

前言
使用者帳號清單的格式
設定使用者帳號本身的密碼
開始寫 shell script
其他使用技巧作法
總結
§前言:

對於有用過 linux 的人來說,使用者帳號的建立應該是很常見的操作,比方如下的操作方式:

         # adduser jonhy

         # passwd jonhy

      當要建立的使用者帳號很少時候可以簡單用命令列快速敲入幾個指令即可。不過若是要建立的帳號數量很多時候,手動命令輸入的方式會顯得很不方便也容易出錯。所以下面來簡單介紹一下如何寫個 shell script 達成該需求。

§使用者帳號清單的格式:

要大量建立使用者帳號,前提當然是需要有一份帳號清單資訊,所以暫定格式規劃如下:

         username:password

 其中 username 表示帳號名稱,password 表示該帳號應對的密碼。該兩個欄位使用 : 為分隔即可。比方一份清單內容如下:

         peter:hello123

           allen:cvs1211oz

實際上可能會有人在 windows 上的 excel 建立帳號與密碼資訊,那可以匯出成為 csv 等格式。不過 csv 格式是以逗點為分隔字元,所以下面要使用的話只要適當改一下程式碼就可以直接使用。

§設定使用者帳號本身的密碼:

    傳統使用者新增用 adduser 命令後,還需要用 passwd 設定密碼。不過使用 passwd 設定密碼通常需要輸入兩次確認,若是要用於 shell script 非交談的環境,可能不是很方便,所以得找個方式應對。







方式1:



        passwd 命令在大多的 linux 發行版本內,有支援 --stdin 的參數可以使用。





        [root@linux ~]# passwd --help

        Usage: passwd [OPTION...] <accountName>

          -k, --keep-tokens       keep non-expired authentication tokens

          -d, --delete            delete the password for the named account (root only)

          -l, --lock              lock the named account (root only)

          -u, --unlock            unlock the named account (root only)

          -f, --force             force operation

          -x, --maximum=DAYS      maximum password lifetime (root only)

          -n, --minimum=DAYS      minimum password lifetime (root only)

          -w, --warning=DAYS      number of days warning users receives before

                                  password expiration (root only)

          -i, --inactive=DAYS     number of days after password expiration when an

                                  account becomes disabled (root only)

          -S, --status            report password status on the named account (root only)

              --stdin             read new tokens from stdin (root only)



實際使用方式如下:

         # passwd --stdin peter

 這時候只要輸入密碼按下 enter 後即可完成密碼的異動。不過考慮於 shell script 非交談環境使用,轉向用管線方式導入:

         # echo "hello123" | passwd --stdin peter

方式2:





linux 發行版本內可以找到 chpasswd 命令,該命令可以透過 stdin 讀取一對使用者帳號與密碼,最後完成密碼的異動。使用方式如下:

         # echo "peter:hello123" | chpasswd

要注意的是,chpasswd 預設使用 des 的密碼加密格式,所以若要使用 md5 或者是其他密碼加密格式,要看一下自己系統該命令的參數支援。



[root@linux ~]# chpasswd --help

Usage: chpasswd [options]



Options:

  -c, --crypt-method        the crypt method (one of DES MD5 SHA256 SHA512)

  -e, --encrypted   supplied passwords are encrypted

  -h, --help                display this help message and exit

  -m, --md5         use MD5 encryption instead DES when the supplied passwords are not encrypted

 §開始寫 shell script:

 這邊開始動工寫 shell script,程式碼很單純沒有考慮太多很細部問題,先要求可以工作為主:



        #!/bin/bash





        DATA_FILE="account.txt"



        while read line

        do

                username=$(echo "$line" | cut -d : -f 1)

                passwd=$(echo "$line" | cut -d : -f 2)

                adduser $username

                echo "$passwd" | passwd --stdin $username

        done < $DATA_FILE



程式碼透過迴圈來完成讀入檔案每一行內容,然後透過 cut 命令以逗點為分隔字元取出第 1,2 個使用者帳號與密碼欄位,最後呼叫 adduser 與 passwd 命令完成使用者新增的動作。若是要改成呼叫 chpasswd 命令設定密碼,程式碼如下一份:

         #!/bin/bash

         DATA_FILE="account.txt"

         while read line

        do

                username=$(echo "$line" | cut -d : -f 1)

                passwd=$(echo "$line" | cut -d : -f 2)

                adduser $username

                echo "$username:$passwd" | chpasswd    # 這邊同 echo "$line" | chpasswd

        done < $DATA_FILE

§其他使用技巧作法:



除了剛剛方式之外,這邊順便補充幾個額外的東西可以看情況使用。大多發行版本內使用者新增都有 adduser 與 useradd,adduser 命令各家使用方式會有點差別,不過 useradd 命令應該都差不多使用方式。在 useradd 命令有個 -p 參數可用:



[root@linux ~]# useradd

Usage: useradd [options] LOGIN

Options:

  -b, --base-dir BASE_DIR       base directory for the new user account home directory

        ......

  -p, --password PASSWORD       use encrypted password for the new user account



依據說明來看可以在新增時候直接把密碼套用進去,不過密碼需要是 DES/MD5 等等這類已經加密過可用的格式,那剛好可以透過 openssl 套件包提供的 openssl 命令達成該需求。

         [root@linux ~]# openssl passwd --help

        Usage: passwd [options] [passwords]

        where options are

        -crypt             standard Unix password algorithm (default)

        -1                 MD5-based password algorithm

        -apr1              MD5-based password algorithm, Apache variant

        -salt string       use provided salt

        -in file           read passwords from file

        -stdin             read passwords from stdin

        -noverify          never verify when reading password from terminal

        -quiet             no warnings

        -table             format output as table

        -reverse           switch table columns為 hello123 的話,可以這樣使用:

     # openssl passwd -crypt "hello123"             (這是 DES 加密演算法格式)

     # openssl passwd -1 "hello123"                    (這是 MD5 加密演算法格式)

     # echo "hello123" | openssl passwd -1 -stdin     (這是 MD5 加密演算法格式,密碼由標準輸入讀入)

不過很可惜這個版本的 openssl 命令還找不到如何產生 SHA256 等更高級的演算法加密格式.... 最終程式碼改改如下:



        #!/bin/bash



        DATA_FILE="account.txt"



        while read line

        do

                username=$(echo "$line" | cut -d : -f 1)

                passwd=$(echo "$line" | cut -d : -f 2)

                passwd2=$(openssl passwd -1 "$passwd")

                useradd -p "$passwd2" $username

        done < $DATA_FILE

§總結:

    這篇簡單談到 linux 上面如何大量新增使用者帳號的方式,過程中談到幾個小指令的應用,也可以簡單了解到熟悉 shell script 對於系統管理的優點,提供給有需要的朋友們參考。
今天再試了一下
在/etc/raddb/users裡加上
"test" Auth-Type := System
就可以使用OS帳號來認証了
必須要在OS裡建立 test 這個user帳號
之後就可以使用usermod -e 來限制user登入的時間(天為單位)
ex:
usermod -e 20120204 test

如果要修改密碼
可以使用perl

perl -e 'print crypt("abc", "AB"),"\n"'

這樣就可以列出 abc 加密後的值
saV4ITPuYyp8M
再以
usermod -p saV4ITPuYyp8M test 來改密碼了

2012/02/02


因為要測試設備的關係
而新設備無法輪詢不同的認証主机
所以想到用radius來處理
但試了很久
發現改users卻無法同時使用LDAP及OS的帳號
所以直接把user加在user裡試是ok的
範例如下

#test
"test" Auth-Type := Local, User-Password == "test"

加完後radius要重啟

2012/02/01

firefox 10 release囉