Thursday, July 16, 2009

website log analysis for website which host on www.net.cn

1. Download the website log file follow the downloading instruction from www.net.cn
[管理主机] 通过控制面板,配置WebLog日志下载说明 [客服中心][2006年3月16日][6920]
简介:无
内容:
当 您想查看站点的详细的WebLog日志时,可以通过此功能将您想查看的一段时间内日志文件先拷到您站点的wwwlogs目录下,您可以通过FTP的方式将 日志文件下载到您本地进行查看。  注意:  1、由于日志文件较大,当您将日志文件下载到本地后,将您站点的wwwlogs目录下的文件删除,以便节省 您的Web空间。  2、我们只提供一周内的日志文件下载。……
2 Download and install weblog expert from the link blow

http://www.weblogexpert.com/files/WLELiteSetup.exe

3. run the weblog expert. In software window. press new button and input the profile name with any thing you like, domain with your website address, index with the main page of your website. And than press next

4. Press browse button and select the log file which you just download from net.cn and press finish

5 select the profile which you just created and press analyze button now a analysis report would show on your default browser.


Friday, July 10, 2009

Linux NIC bonding

Configuration files:
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth1
/etc/sysconfig/network-scripts/ifcfg-bond0
/etc/modprobe.conf
/proc/net/bonding/bond0

Files contant:
  • /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    USERCTL=no
    ONBOOT=yes
    MASTER=bond0
    SLAVE=yes
    BOOTPROTO=none
    ETHTOOL_OPTS="speed 1000 duplex full autoneg on"
  • /etc/sysconfig/network-scripts/ifcfg-eth2
    DEVICE=eth2
    USERCTL=no
    ONBOOT=yes
    MASTER=bond0
    SLAVE=yes
    BOOTPROTO=none
    ETHTOOL_OPTS="speed 1000 duplex full autoneg on"
  • /etc/sysconfig/network-scripts/ifcfg-bond0
    DEVICE=bond0
    IPADDR=192.168.100.20
    NETMASK=255.255.255.0
    NETWORK=192.168.100.0
    BROADCAST=192.168.100.255
    ONBOOT=yes
    BOOTPROTO=none
    USERCTL=no
  • /etc/modprobe.conf
    alias eth0 e1000
    alias eth1 tg3
    alias bond0 bonding
    options bond0 miimon=100 mode=5
Bonding mode:
mode=0 (balance-rr)
Round-robin policy: Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.

mode=1 (active-backup)
Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.

mode=2 (balance-xor)
XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.

mode=3 (broadcast)
Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.

mode=4 (802.3ad)
IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification.
 Pre-requisites:  1. Ethtool support in the base drivers for retrieving  the speed and duplex of each slave.  2. A switch that supports IEEE 802.3ad Dynamic link  aggregation.  Most switches will require some type of configuration  to enable 802.3ad mode.
mode=5 (balance-tlb)
Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave.
 Prerequisite:  Ethtool support in the base drivers for retrieving the  speed of each slave.
mode=6 (balance-alb)
Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server.

The most used are the first four mode types...

Also you can use multiple bond interface but for that you must load the bonding module as many as you need.
Presuming that you want two bond interface you must configure the /etc/modules.conf as follow:
 alias bond0 bonding  options bond0 -o bond0 mode=0 miimon=100  alias bond1 bonding  options bond1 -o bond1 mode=1 miimon=100

Thursday, July 09, 2009

Install vmware tool on the ubuntu 9.04

Command list:
sudo aptitude install build-essential linux-headers-generic
sudo touch /usr/src/linux-headers-`uname -r`/include/linux/config.h

cp /media/cdrom/VMwareTools-*.tar.gz ~\Desktop\

cd
~\Desktop\

tar xf VMwareTools-*.tar.gz

cd vmware-tools-distrib/

sudo ./vmware-install.pl
-d

Reference:
Ubuntu community document about vmware https://help.ubuntu.com/community/VMware

How To Install VMware Tools on Ubuntu 8.04 Guests https://help.ubuntu.com/community/VMware

Tuesday, July 07, 2009

Linux hard disk operation

LVM
Create LV process
  • Initializing disks or disk partitions

    fdisk - fdisk /dev/sd? press p to list the partition table, press n to create a new partition, press e to create extended partition, press p to create a primary partition(maximum 4 per disk) input the number of the partition if create a primary partition, input fisrt cylinder number, input last cylinder number or +sizeM eg: +100M. Change the partition's system ID by use the fdisk command t, input the partition number after the popup Selected Partition, input desired Hex code of the system id here input 8e which for linux LVM. Use the fdisk command w to write the new partition table to the hard disk.

  • Assign the disks or disk partitions as physical volume
  • Create volume group on one or more PVs
  • Use space from a VG as Logical Volume
  • Format the LV.

Friday, July 03, 2009

Linux harddisk and NIC test command

hdparm -Tt /dev/hd* test the hdd read speed and system cache speed.

ethtool is used for querying settings of an ethernet device and changing them.

Thursday, May 28, 2009

Reduce The Size Of SQL Server Transaction Log

Introduction
To stop the nightmare of low disk space which cased by huge transaction log file. There three things to do. First truncate the inactive items in the transaction log. However it does not reduce the size of the log file. Secondly shrink the transaction log file. Finally, If possible set a fix maximum size of the transaction log file.

Truncate the inactive items in the transaction log
There are two ways to truncate the transaction log. Doing backup transaction log in the enterprise manager and truncate the transaction log by using T-SQL command.

Using SQL server enterprise manager to backup the transaction log will automatically truncate the inactive transactions after the backup. By doing this you need:
* Open the enterprise manager from the desktop shortcut or start menu.
* In the enterprise manager expend following items in the Console Root tree one by one: Microsoft SQL Servers, SQL Server Group, The database server which need perform backup task, Databases.
* Right click the database name and point to All Tasks, and then select Backup Database.
*Fill in the task name and description
* Click the radio button in front of the Transaction Log which in the backup section.
*In the Overwrite section choose Append to media or Overwrite existing media.
* Go to the Option tab make sure Remove inactive entries from transaction log has been selected.

If there are no enough space on the backup device or the backup of transaction log is not necessary. Executing truncate command in SQL Query Analyzer could be more straightforward.
* Open SQL Query Analyzer from start menu or executing the isqlw utility
* Select database which need truncate transaction log.
* Type in following T-SQL command:
use database name
BACKUP LOG WITH TRUNCATE_ONLY
* Press the execute button.

Shrinking the transaction log

Execute following command in the SQL Query Analyzer.

USE DatabaseName
DBCC SHRINKFILE(transaction log file name,desired shrink size in MB)


Fix the maximum size of the transaction log so you do not need worry about it again.

Open the enterprise manager from the desktop shortcut or start menu.
* In the enterprise manager expend following items in the Console Root tree one by one: Microsoft SQL Servers, SQL Server Group, The database server which need perform backup task, Databases.
* Right click the database name and point to Properties.
* Go to Transaction Log tab in the Database Properties window.
* Select Restrict file growth(MB): and fill in the size.

Thursday, March 12, 2009

Eclipse Code Template

In eclipse we can input a template name and than press a key combination to quickly input big code block. For example we can type in "sysout" and press the default content assist key "Ctrl + space" to input "system.out.println()".

To do this you need check what template eclipse have by click window -> preference.






Tuesday, September 16, 2008

Linux Network management

/etc/modprobe.conf -- contain a list of alias name for each NIC
dmesg | grep "NIC name" and ifconfig can display the hardware address of NIC.
mii-tool - view and config negotrated speed of NIC, but it not support all the NICs. "mii-tool -v" can tell wheather the NIC support mii-tool.
ifdown and ifup
kudzu
netconfig - can create ifcfg-*** file. "netconfig --device eth1" config eth1 NIC.
system-config-network
/etc/sysconfig/network-scripts/ifcfg-*** - configuration file for each NIC *** represent NIC alias name.

/etc/resolv.conf contain DNS setting

Monday, September 08, 2008

Linux Kernel

Kernel Modules
Kernel Modules are locate in /lib/modules directory.

lsmod, list current mounted modules.
modprobe , mount specific modules and dependencies.
/sbin/modinfo , module examination
insmod, mount module
rmmod, unmount module
depmod, list module dependencies.

Configure Kernel Modules by modify /etc/modprobe.conf which structure is aliases, kernel parameters, Module mount actions.

Module dependencies record in modules.dep

/proc/sys

Saturday, September 06, 2008

Linux Installation

type in "linux askmethod " and Enter after "boot:" will let installer ask for install method (from CD, harddisk, NFS, FTP or HTTP)

Partition:

Note:
  • /etc, /lib, /sbin, /dev and /(root directory) must in one partition.
  • swap directory is normally two times of the size of the RAM.
  • /boot, /home, /usr, /var, /tmp, /urr/local, /opt could be used as mount points for directory. /boot need no more than 100MB
Create software RAID or LVM in Linux installer:

In the partition page of the installer, pressing New button will create a new partition. " In the File system type" chose software RAID or physical volume to setup the special partition. After create software RAID or physical volume, RAID or LVM button can be used to create RAID device or volume group. Moreover when create RAID device, chose physical volume in the file system type will create a physical volume over a RAID device.

Software RAID, RAID principles-http://en.wikipedia.org/wiki/RAID#Principles
LVM Resource Page http://sourceware.org/lvm2/

Tuesday, August 26, 2008

Verbs with down

bring down:to cause someone in a position of power to lose their job: This scandal could bring down the government.
come down:
hold sb/sth down: to keep someone or something in a particular place or position and to stop them from moving: He was struggling so much that it took three police officers to hold him down.
knock sb/sth down: to cause someone or something to fall to the ground by hitting them
See picture
go down:
put down:
take sth down: 1. (REMOVE) to remove something that is on a wall or something that is temporary, or to remove a structure by separating its different parts: I've taken the pictures down. 2. (WRITE) to write something that another person has just said: He took down my address and phone number and said he'd phone back.

turn sb/sth down: to refuse an offer or request: He offered her a trip to Australia but she turned it/him down. He turned down the job because it involved too much travelling.

Monday, August 25, 2008

Cron in Linux

  • Check Cron whether installed in linux: rpm -qa | grep cron
  • Start cron service in RHEL, service crond start
  • Edit tasks: crontab -e, the task configure structure is
    [Minute] [Hour] [Day of the month] [Month of the year] [Day of the week] [command]
    "*" represent any number. "/" means every. "-" means to. "," separate more than one value eg: */2 2-4 2,5,7 * * means every 2 mins between 2 o'clock and 4 o'clock in the second, fifth and seventh day in each month.
  • Del tasks: crontab -r
  • List tasks: crontab -l

Wednesday, August 20, 2008

网吧如何彻底摆脱机器狗的困扰

转自:http://www.ixpub.net/thread-734897-1-2.html

当网吧中的电脑中了机器狗后,机器狗会穿透还原感染userinit.exe文件。重启后userinit.exe文件就会下载大量木马病毒并运行,其所下载的木马病毒大部分为网游盗马木马。而且机器狗会穿透还原卡,重启后还在,所以十分可恶。

要清除机器狗,要做的就是恢复被机器狗感染的文件。可以使用超级巡警的机器狗专杀来穿透还原修复被感染的文件。以下是专杀工具的简介:
引用:
本工具可检测并查杀机器狗病毒,可穿透机器狗所能穿透的还原系统来修复被感染的文件。本工具还具有免疫的功能,针对已知机器狗变种进行免疫,防止再次感染。另外,可使用命令行方式进行杀毒,便于自动化操作,建议网吧等场所设置为开机自动杀毒,减少重复作业。
在使用本专杀后,强烈建议安装超级巡警最新版,用以即时监控机器狗病毒,防止重复感染!
命令行参数:
(建议使用“>”将结果输出到文件中):
/k 命令行自动杀毒
/i 需要免疫
>result.txt 将结果输出到result.txt文件中
例子:
KillRodog /k /i > c:\kill_result.txt
简介中说,可以穿透还原卡修复文件,还可以使用命令行功能自动修复。其实这两个功能是特别为网吧设计的。

使用超级巡警的机器狗专杀来穿透还原修复被感染的文件,修复文件后重启一下就可以了。因为机器狗下载的木马并不会穿透还原,当你重启机器后那些木马就不存在了。查杀效果如下图。


可是中毒后去手动查杀还是麻烦。这里就要使用超级巡警专门为网吧用户设计的命令行杀毒功能来完成开机自动杀毒修复文件了。我们可以写一个批处理调用超级巡警机器狗专杀杀毒。批处理就用下面这个文件
引用:
KillRodog /k /i > c:\kill_result.txt
其实就是简介中的示例。将以上代码保存到一个文本文件中,改后缀为bat就可以了。然后将批处理和机器狗专杀放到同一个目录里,如下图:


创建一个批处理的快捷方式,把快捷方式到到启动目录里就可以了。


这样在开机的时候批处理就会自动调用专杀工具查杀机器狗病毒恢复文件。你就永远不用担心机器狗了,当有人中毒后,重启两次就可以了(因为专杀没有 userinit.exe启动的早,所以第一次已经把文件恢复了,但是木马已经下载回来了,所以需要再重启一下)。呵呵。祝广大网管工作顺利。

专杀下载地址:http://www.sucop.com/download/29.html

Tuesday, August 19, 2008

verbs with into

bump into:
burst into: to suddenly start sth. burst into tears - to suddenly start to cry
come into:
If someone comes into money, property or a title, they receive it as a result of the death of a relative:
come into:
If a particular emotion or quality comes into a situation, it influences that situation:
She married for money - love didn't come into it. NOTE: This sense is usually used in negative sentences.
crowd (sth) into sth : If people crowd or are crowded into a place, they fill it completely:
fling yourself into sth : to do something with a lot of enthusiasm: Tom has really flung himself into his work this year.
fly into : to suddenly become very angry: I asked to speak to her boss and she just flew into a rage.
go into sth (START): 1 to start doing a particular type of work: My son's planning to go into journalism. 2 to start an activity, or start to be in a particular state or condition: The drug is still being tested and will not go into commercial production for at least two years.
go into sth (DISCUSS): to discuss, examine, describe or explain something in a detailed or careful way. I'd rather not go into that now. Can we discuss it later?
go into sth (BE USED) MAINLY UK. If time, money or effort goes into a product or activity, it is used when producing or doing it: A considerable amount of time and effort has gone into this exhibition.
pull in or pull into :
pull in/pull into somewhere (MOVE) phrasal verb
If a vehicle pulls in or pulls into somewhere, it moves in that direction and stops there.
rush into: If you rush into something such as a job, you start doing it without having really decided if it is the right thing to do or having considered the best way to do it.
shock into:
slip into sth: (ALSO slip sth on) to quickly put on a piece of clothing: If you could wait two minutes, I'm just going to slip into a smarter dress. You don't need to go into the changing rooms - just slip the jacket on over your sweater.
talk sb into sth: to persuade someone to do something:He's against the idea, but I think I can talk him into it.
walk into sth: to get a job very easily: She walked straight into a well-paid job after leaving university.

Thursday, July 31, 2008

DNS server

DNS functions
  • Forward Lookup - hostname to IP
  • Reverse Lookup - IP to hostname
  • Logically group computer by domain
  • Email routing information - MX record
DNS Zone, Domains and Delegation
  • A domain is a DNS scope that responsible for name resolution
  • A zone is the name resolution scope that managed by one specific server
  • DNS server can delegate sub-domains into additional zones which managed by other server or servers
Name Server Hierarchy
  • Master name server contains the master copy of data for a zone
    • Master name server files:
      • Domain forward lookup zone file
      • Domain reverse lookup zone file
      • named.ca - Root server information file
      • localhost.zone - local forward lookup file
      • named.local - local reverse lookup file
  • Slave name server provides a backup of the master DNS server and automatically synchronize with the master DNS server.
    • Slaver name server file:
      • named.ca
      • localhost.zone
      • named.local
    • DNS zone transfer - The action of slaver name server copying the "Domain forward lookup zone file" and "Domain reverse lookup zone file" from master server called DNS zone transfer
Name resolution procedure:
  1. Received name resolution request from client.
  2. If the requested name is in the local database, DNS serve would send the IP address back to the client. The name resolution action will finished. If the requested name is not in the local database, DNS server would forward the request to the root server.
  3. If the root server has not the requested name, it will response the IP address of the DNS serve which mange the second level domain of the requested name. Otherwise the root server will response the IP of the requested name and then DNS server will send it back to client.
  4. DNS serve will continually repeat step 3 until resolved the Requested name.
  5. DNS server will save the resolution in the catch file and send it back to client
Berkeley Internet Name Domain (BIND)

BIND is the most widely used DNS server on the internet. It provides a stable and reliable infrastructure on which to base a domain's name and IP address associations. It runs in a chrooted environment to provide max security. Chrooted redirect the root directory to other directory which is /var/named/chroot/var/named/db.* in RHEL

BIND on RHEL
  • Service type - system V
  • Packages - bind, bind-utils, bind-chroot
  • Daemons - named, rndc
  • Script - named which can start or stop DNS service
  • Ports - named on port 53, rndc on port 953
  • Files - all under /var/named/chroot directory
    • /etc/named.conf - main configuration file include zones, options, access control lists and etc
    • /var/named/* - DNS database
    • /etc/rndc.* - DNS security file
  • Related - caching-nameserver - used to quickly setup a caching only DNS, openssl encrypt the DNS communication.
Master and Slave Zones
  • Master zone - the DNS data which sorted in the master DNS server. The data on master zone can be added, deleted or modified.
  • Slaver zone - the DNS data which sorted in the slave DNS server. The data inside Slaver zone are transfered from the master DNS server. So that the data on slaver zone can not be modified , deleted and added.
Reverse Loolup Zones

DNS configurations
  • bind-chroot - change ROOTDIR = directory_name in /etc/sysconfig/named. Put a # in front of ROOTDIR will stop chroot function.
  • Zone files directory - directory=var/named so all DNS zone files are in the /var/named/chroot/var/named
  • Global Options (each line must finish by ";", sting need inside " ") (in named.conf)
    • options{

      directory "/var/named"; # set root directory of all related paths specified in named.cong. That means all the root directory of all the DNS database file.
      forwards {10.0.01.254;}; # define the server to which DNS queries will be sent when the queries can be resolved locally. If the queried DNS server can not answer, it will try root DNS server unless the forward-only option is set too.
      allow-query {192.068.2/24;}; #White list of the querier. If this option is not set the DNS can be queried from every where.
      allow-transfer {192.068.2/24;}; #Only the listed DNS can copy the DNS database.

      }
  • Access Conrol Lists (acl) (in named.conf)
    • acl "list_name" {192.168.1/24;192.168.1/24};
  • Master and Slave Zones Note: zone file name must contain zone name
    • zone "example.com"{
      type master;
      file "example.com.zone" #it stored in the path which defined in directory option
      };
    • zone "kernel.org"{
      type slaver;
      masters {192.168.1.1;};
      file "slaves/kernel.org.zone";
      };
  • Reverse Loolup Zones must have follows three records
    • SOA record
    • NS records
    • PTR records
    Create one reverse lookup zone by create the 192.168.1.zone in the /var/named/chroot/var/named directory. Type in the following lines.

    $TTL 86400
    @ IN SOA example.com. root.example.com. (
    2001101100 ; serial number
    10800 ;refresh
    3600 ;retry query
    604800 ;expire
    0 ;negative TTL
    )
    ; Resource Records
    @ IN NS ns.example.com.
    3 IN PTR ns.example.com.

    After created the zone file, the owner and owner group of the file need to be change to named by using command "chown named:named 192.168.1.zone".

    zone "192.168.1.in-adde.arpa"{
    type slave;
    masters {192.168.1.3;};
    file "slaves/192.168.1.zone";
    }
    Note: zone name must end with .in-adde.arpa


  • Root Zone and Loopback Zone
    • Root zone "."
      zone "." {
      type hint;
      file "named.ca";
      }
    • Lookback zone "0.0.127.in-adde.arpa"
      zone "0.0.127.in-adde.arpa" {
      type master;
      file "named.local";
      }
  • Forward lookup zone must have follows three records
    • SOA record
    • NS record
    • A records
    Create one forward lookup zone by create the example.com.zone in the /var/named/chroot/var/named directory. Type in the following lines.

    $TTL 86400
    @ IN SOA example.com. root.example.com. (
    2001101100 ; serial number
    10800 ;refresh
    3600 ;retry query
    604800 ;expire
    0 ;negative TTL
    )
    ; Resource Records
    @ IN NS ns.example.com.
    ns IN A 192.168.1.3

    After created the zone file, the owner and owner group of the file need to be change to named by using command "chown named:named example.com.zone".
Zone file
  • Begins with $TTL(Time to live) - Determines the default length of time in seconds which you want resolving servers to cache your zone's data.
  • First resource record is zone's start of authority(SOA)
  • Zone data in additional resource records
  • Resource Records(RR)
    • [domain] [ttl] [clase]
    • [domain] - specify domain or use current
    • [ttl] - how long record will be cached, if it has not been specific the record will use the ttl which in the first line for the zone file.
    • [clase] - record classification(usually IN means Internet)
    • - record typ (SOA, MX, A, etc)
    • - specific data for record
  • SOA(Start of Authority) - Every zone file must have one. Following is a example SOA record.
    @ IN SOA example.com. root.example.com(
    2001101100 ; serial number
    10800 ;refresh
    3600 ;retry query
    604800 ;expire
    0 ;negative TTL
    )

    In the first line, example.com. - The domain name of the DNS server which manage this zone. root.example.com - The administrator of this zone. Serial number will be increase when every time of change. Therefor the slave servers can know whether the zone file has been changed.

    In the Second line, The number meas 10800 second which determined slaver servers check the zone file whether has been changed every 10800 second(3 hours)

    In the third line, The number is 3600 second which determined slaver servers will retry connect the master server every 3600 second when the refresh was failed.

    In the fourth line, Slaver server would delete the zone file if it can not refresh with in the expire time 604800 seconds.

    In the fifth line, negative TTL specify how long the DNS server cache the unfound record.
  • NS (Name Server) - designate name servers to use for this domain
    There should be an NS record for each master of slave name server serving your zone. NS records point to any slave servers that should be consulter by the client's name server if the master should fail

    example.com. IN NS ns.example.com.
    example.com. IN NS ns1.example.com.
    @ IN NS ns2.example.com.

    That is domain name, internet, Name server, DNS server's domain name. @ represent the default domain name.

    If there are more than one DNS point to one domain the first one would be the master DNS others would be slave DNS.
  • A records map host name to IP address
    mail IN A 192.168.0.2
    ns.example.com. IN A 192.168.0.3
    Note: If the hos tname not finished with "." system would think it is a host inside the default domain. System will add the default domain name behind the host name. In this case the host full domain name is "mail.example.com.".
  • CNAME records map address aliases
    www IN CNAME ns1
    dns IN CNAME ns.example.com.
    The first line means if someone look for www.example.com the DNS server will response the IP address of the host ns1.example.com. So that As the host name usage in the A record, if the host name not finish with "." system will add default domain name behind it.
  • PTR records map IP address to hostname
    3.0 IN PTR ns.example.com.
    Note 3.0 not finish with "." so it represent "3.0.168.192.in-addr.arpa."
  • MX records map mail servers for a domain
    example.com. IN MX 5 mail.example.com.
    example.com. IN MX 10 mail1.example.com.
    Note: the number represent priority, less number means higher priority
  • Round Robin Load Sharing Through DNS
    Load balancing can be achieved through the simple use of multiple A records:
    www 0 IN A 192.168.2.101
    www 0 IN A 192.168.2.102
    www 0 IN A 192.168.2.103
    AS TTL is set to 0 so that everyone need access host www, need to request IP from the DNS server. And the DNS server will reponse the ip one by one in the list. Therefor www users can be redirect to different servers for load balance implementation. However DNS traffic will increase as a TTL of 0 means never cached.





Tuesday, July 29, 2008

Send mail setting

Email Process,
  • MSP(Mail Submission Program)
  • MTA(Mail Transport Agent)
  • MDA(Mail Delivery Agent)

Configuration file,

  • /etc/mail/sendmail.cf - the main configuration file for sendmail
  • /etc/mail/sendmail.mc - sendmail macro configuration file
  • /etc/mail/submit.cf - configure sendmail operation when connected by MSP(email client software)
  • /etc/aliases - configure local user aliases and need use newaliases command to hash to aliases.db before using.
  • /etc/mail/local-host-names - lists the aliases and domain, which the mail server will accept in an incoming e-mail address for local delivery
  • /etc/mail/access - after modification need run "make" in /etc/mail folder
  • /var/named/chroot/var/named/db.domain DNS setting file
  • Log file: /var/log/maillog
Configuration
  • set in sendmail.cf
    • Get host ip address,
    • Set DNS server IP in /etc/resolv.conf and make sure search follow with correct domain name
    • example db.domain file
      domain.com. IN NS example.domain.com.
      example.domain.com. IN A 192.168.1.12
      domain.com. IN MX 10 example
    • Allow other PC sent email though the smtp server(by default sendmail only allow user send email on the server) by set line DaemonPort0ptions=Port=smtp,Addr=127.0.0.1, Name=MTA to notes in the sendmail.cf file
    • netstat -tupln | grep :25 - display on the port 25 which program listen on which address t - tcp, u - udp, P - program name, L - listening port, n
    • service sendmail restart - active the above setting
  • set in sendmail.mc
    • Back up sendmail.mc and sendmail.cf
    • put dnl in front of DAEMON_OPTIONS('Port=smtp,Addr=127.0.0.1, Name=MTA')
    • m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
    • diff /etc/mail/sendmail.cf /etc/mai/sendmail.cf.bak - compare the new and old sendmail.cf file

Saturday, July 26, 2008

Linux Filesystem

Partitions
  • Formating is the operation that separating partition into several blocks which normally is 4 K big. Block is the least storage unit to sort files. If a file is 11k it would use 3 blocks which is 4 k*3=12 k.
Inodes
  • An inode is a data structure used in typical unix liked file system. There is an inode table which contains metadatas of all files and directories sorted on an ext2 or ext3 file system. Inode number equals the number of files and directories which sorted in the file system. So that the mix inode number is the max number of files and directories can be sorted in the system.
    I-
    number
    File TypePerm
    ission
    Link CountUIDGIDsizeTime Stamp......pointer
    1
    -
    644
    1
    500
    500




    2
    d
    755
    1
    0
    0




    I-number is the inode number. File type: "-" present file, "d" present directory. Link count record hard links. Time stamp include access time, modify time and change time. Modify time is the last time user change the file content. Change time is the last time the change of inode data. Pointer is the address of the blocks which sort the file of directory on the disk.
  • Directory is a mapping between the file name and the inode number. The kernel must search a directory looking for a particular filename and then convert the filename to the correct corresponding inode number if the name is found.
  • Filetypes
    • - regular file
    • d directory
    • l symbolic link
    • b block special file eg: /dev/sda1
    • c character special file eg: /dev/mice
    • p named pipe
    • s socket
Checking Free Space
  • df - reports disk space usage
    • non parameter - report total kilobytes, kilobytes used, kilobytes free per file system
    • -h - displays sizes in easier to read units
  • du - Reports disk space usage
    • Report kilobytes used per directory
    • Includes subtotals for each subdirectory
      • -s option only reports single directory summary
    • Also takes -h option
Mount removable dives (cd/dvd rom/writer, floppy, usb dives.)
  • floppy
    • mount /dev/fd0 /media/floppy/
    • format low level format fdformat /dec/fd0H1440 and high level format mkfs -t ext2 /dev/fd0 or mke2fs /dev/fd0 or mkfs -t vfat /dev/fd0
  • cd/dvd rom/writer
  • usb dives
Archive
tar - standard Linux archiving command. It will archive files with their inode table but do not compress files without specific parameter.
  • Syntax - tar [option] archive_name files
    • Create Archive - "tar cvf archive_name files..."
      • c - creates a new archive
      • v - produces verbose messages
      • f - archive_name is name of new file
    • Compress Archives
      • z - for gzip compression
      • j - for bzip2 compression
    • Inspect Archive
      • "tar tf archive_name" display a list of all files in the archive
      • "tar tvf archive_name" the v causes a long listing (like 'ls -l') of each file in the archive
    • Extract Archive - "tar xvf archive_name" The archive will be extracted in the current directory. So that extract command need execute in the target folder. Files maintain their hierarchy relative to the current directory.
    • Save the archive to removable use parameter M follow with the dives path
File Compression Utilities
  • gzip, gunzip - "*.gz" standard Linux compression utility which has over 75% compression for text files. gzip can only compress files. It will pop error when trying to compress directory
    Compress - "gzip filename" the compressed file will replace original file or "gzip -vc filename > archive_name.gz" -c indicate gzip keep the original file.
    Extract - "gunzip filename.gz"

  • bzip2, bunzip2 - "*.bz2"Newer Linux compress tool which generally perform better compress than gzip



Printing in Linux

Printing Utilities
  • enscript - Converts text to PostScript
  • ggv - PostScript and PDF viewer
  • ps2pdf - PostScript to PDF converter
  • pdf2ps - PDF to PostScript converter
  • mpage - Prints multiple pages per sheet

Vi Tips

Command Mode:


  • Cursor Movement:
    • w - word ahead
    • b - word back
    • ( - sentence back
    • ) - sentence forward
    • { - paragraph above
    • } - paragraph below

  • Searching for Text:

    • /test - search downwards for "test"
    • ?test - search upwards for "test"
    • n/N - continue search the same/opposite direction

  • Undoing Changes:

    • u - undo most recent change
    • Ctrl + r redo last "undo" change
    • U - undo all changes to the current line

  • Change, Delete and Yank


      ChangeDeleteYankPaste
      Lineccddyyp blow cursor
      P above cursor
      Lettercldlylp after cursor
      P beofer cursor
      Wordcwdwywp after cursor
      P beofer cursor
  • Tricks:
    • dtx - delete from cursor to the letter x
    • rx - replace a character with x
    • x - delete a character
    • 5dd - delete 5 lines
    • 5yy - copy 5 lines
    • 5x - delete 5 charactersR - replace character-for-character until
Entering Insert Mode
  • a - appen after the cursor
  • i - insert before the cursor
  • A - append to end of line
  • I - insert at beginning of line
  • o - open a line below
  • O - open a line above