Pages

Saturday 28 December 2013

Mail Gateway with Postfix - amavisd-new - spamassassin - clamav

Domain : salongcuong.com.vn  (and more)
IP Mail server: 116.193.77.64
IP Mail Gateway : 116.193.77.201  (host gateway.salongcuong.com.vn)

<Note : remember stop 'send mail' service first before use postfix>

Step 1 : Install and Configure Postfix

#yum install postfix

==> Configure Postfix: vi /etc/postfix/main.cf

myhostname = gateway.salongcuong.com.vn
mydomain = salongcuong.com.vn
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, $mydomain
relay_domains = salongcuong.com.vn
transport_maps = hash:/etc/postfix/transport
local_recipient_maps =
local_transport = error:local mail delivery is disabled

==> Configure transport file /etc/postfix/transport

#vi /etc/postfix/transport
Add this line into the file:

salongcuong.com.vn      smtp:[116.193.77.64]

#postmap /etc/postfix/transport

==> Configure /etc/postfix/master.cf file


#vi /etc/postfix/master.cf

Put # before (comment out) :

local     unix  -       n       n       -       -       local


Step 2: Setup Amavis-new, Spamassassin and ClamAV

First setup RPM forge
(If you want to know why do we have to setup this please refer this)

#wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
(or you can choose lastest version by manually download that files)
#rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
#rpm -K rpmforge-release-0.5.2-2.el5.rf.i386.rpm
The last line will check the file, result should be OK.

#rpm -i rpmforge-release-0.5.2-2.el5.rf.i386.rpm

===== Done

Edit /etc/yum.repos.d/CentOS-Base.repo

[base] exclude=spamassass* ... [updates] exclude=spamassass* ...


#yum --enablerepo=rpmforge,rpmforge-extras install amavisd-new clamav clamav-devel clamd spamassassin

====================== Configure ClamAV:

### /etc/clamd.conf
#
# Set the LocalSocket for clam
# Note this *MUST* match that set in /etc/amavisd.conf
#
LocalSocket /var/run/clamav/clamd.sock
#
# Comment out the TCPSocket setting:
# TCPSocket 3310


===================== Configure  Amavisd-new   /etc/amavisd.conf

$mydomain = 'example.com';                  # Edit: a convenient default for other settings
$MYHOME = '/var/amavis';                    # Uncomment: a convenient default for other settings, -H
$helpers_home = "$MYHOME/var";              # Uncomment: working directory for SpamAssassin, -S
$lock_file = "$MYHOME/var/amavisd.lock";    # Uncomment, -L
$pid_file  = "$MYHOME/var/amavisd.pid";     # Uncomment, -P
$myhostname = 'mail.example.com';           # Uncomment & Edit: must be a fully-qualified domain name!

And:


Finally, we need to uncomment the section for ClamAV like so:

### http://www.clamav.net/
['ClamAV-clamd',
  \&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd.sock"],
  qr/\bOK$/, qr/\bFOUND$/,
  qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],
# # NOTE: run clamd under the same user as amavisd, or run it under its own
# #   uid such as clamav, add user clamav to the amavis group, and then add
# #   AllowSupplementaryGroups to clamd.conf;
# # NOTE: match socket name (LocalSocket) in clamav.conf to the socket name in
# #   this entry; when running chrooted one may prefer socket "$MYHOME/clamd".


===================== Configure PostFix again to integrate with amavisd-new in master.cf
#vi /etc/postfix/master.cf 

Add below record to this file:

amavisfeed unix    -       -       n        -      2     lmtp
    -o lmtp_data_done_timeout=1200
    -o lmtp_send_xforward_command=yes
    -o disable_dns_lookups=yes
    -o max_use=20


And:

127.0.0.1:10025 inet n    -       n       -       -     smtpd
    -o content_filter=
    -o smtpd_delay_reject=no
    -o smtpd_client_restrictions=permit_mynetworks,reject
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o smtpd_data_restrictions=reject_unauth_pipelining
    -o smtpd_end_of_data_restrictions=
    -o smtpd_restriction_classes=
    -o mynetworks=127.0.0.0/8
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001
    -o smtpd_hard_error_limit=1000
    -o smtpd_client_connection_count_limit=0
    -o smtpd_client_connection_rate_limit=0
    -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_milters,no_address_mappings
    -o local_header_rewrite_clients=
    -o smtpd_milters=
    -o local_recipient_maps=
    -o relay_recipient_maps=


And

===================== Configure PostFix main.cf

Add this line into the last of the file:

content_filter = amavisfeed:[127.0.0.1]:10024


And then run:

#postfix reload


Note : If this step you would see the service amavisd can not start, when check log file (#tail - 50 /var/log/maillog) and see this error : "amavisd dead but subsys locked" or
"
Dec  8 11:26:17 test amavis[28365]: Creating db in /var/amavis/db/; BerkeleyDB 0.43, libdb 4.3
Dec  8 11:26:17 test amavis[28365]: (!!)TROUBLE in pre_loop_hook: config: no rules were found!  Do you need to run 'sa-update'?
Dec  8 11:26:17 test amavis[28365]: (!)_DIE: Suicide () TROUBLE in pre_loop_hook: config: no rules were found!  Do you need to run 'sa-update'?
"

Just run:
#sa-update

This will be OK.



============================== If you want to trust relay server (to allow which server can relay email via this gateway)

#vi /etc/postfix/main.cf

add more record to this file like this:
mynetworks = 127.0.0.0/8, 116.193.77.64/32  //......... add more server IP that you want to trust relay from the gateway (postfix) server

#postfix reload

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

================================ Or if you want Spam assassin mark "Spam" label in front of the email subject, edit :

#vi /etc/amavisd.conf

@local_domains_maps = ( [".$mydomain", ".salongcuong.com.vn", ".domain.what.you.want.to.show.net"] );



================================ And after change information in /etc/postfix/transport file 
Have to recall

#postmap /etc/postfix/transport

Friday 27 December 2013

Window Command (basic)

http://technet.microsoft.com/en-us/library/bb684904(EXCHG.80).aspx
C:\>net use \\116.193.69.26 "qtsc" /user:Administrator
The command completed successfully.

C:\>net use \\116.193.69.26\D$
The command completed successfully.

C:\>net use
New connections will be remembered.

Status Local Remote Network
-------------------------------------------------------------------------------
OK \\116.193.69.26\D$ Microsoft Windows Network
OK \\116.193.69.26\IPC$ Microsoft Windows Network
The command completed successfully.

C:\>nbtstat -A 10.20.254.15 //show netbios name
C:\>nbtstat -A 116.193.69.26
Local Area Connection:
Node IpAddress: [10.20.254.14] Scope Id: []
NetBIOS Remote Machine Name Table
Name Type Status
---------------------------------------------
LAM <00> UNIQUE Registered
MAC Address = 00-50-DA-27-0D-B6


C:\>at 16:01 /INTERACTIVE D:\a.bat // luc 16 gio thuc thi chuong trinh D:\a.bat va hien
ra ngoai cua so nguoi dung, khong chay o che do 
background (khong co /INTERACTIVE)


C:\>net view 10.20.254.30
Shared resources at 10.20.254.30
HOME
Share name Type Used as Comment
-------------------------------------------------------------------------------
game Disk
hinh k gian 3 chieu Disk
vcd Disk
The command completed successfully.


netsh firewall delete portopening /?


Muon thay doi Password Policy cho cac account trong DC, chuot phai vao ten cua DC, chon 
properties, chon TAB Group Policy, chon Policy muon thay doi roi nhan Edit,
Vao muc Computer Setting -> Security Setting -> account policy .... ==> thay doi o day 
trong truong hop gpedit.msc da bi lock
C:\>net use
New connections will be remembered.

Status Local Remote Network
-------------------------------------------------------------------------------
OK \\172.18.31.10\Home Microsoft Windows Network
OK \\172.18.31.10\IPC$ Microsoft Windows Network
The command completed successfully.
C:\>net use /delete \\172.18.31.10\Home
\\172.18.31.10\Home was deleted successfully.

Erase Remember password when connect other clients:
Click Start and select Run and type
rundll32.exe keymgr.dll, KRShowKeyMgr


Uninstall SP2:
%windir%\$NtServicePackUninstall$\spuninst\spuninst.exe

Or
http://support.microsoft.com/kb/875350/


net use \\116.193.64.9 /user:nhieu f3wa4rf5rd0(
sc \\116.193.64.9 stop w3svc
C:\>net use /delete \\116.193.64.9\IPC$




Set quyen cho thu muc
C:\Documents and Settings\Administrator>SetACL.exe -on "F:\a" -ot file -actn ace -ace "n:administrator;p:full"
INFORMATION: Processing ACL of: <\\?\F:\a>
SetACL finished successfully.

Set quyen share cho thu muc
C:\>SetACL.exe -on "\\116.193.64.5\a" -ot shr -actn ace -ace "n:nhieu;p:full;m:grant"

F:\>RMTSHARE.EXE \\10.20.254.166\"a"="F:\a" /GRANT "administrator":F
The command completed successfully.



Linux Command (Basic)

system-config-securitylevel //thay doi thiet lap Firewall
yum --enablerepo=centosplus upgrade php* //upgrade PHP
yum --enablerepo=centosplus upgrade mysql* //upgrade mysql
yum --enablerepo=centosplus install mysql-server-5*
/etc/sysconfig/network-scripts //file config NIC
DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=static
BROADCAST=192.168.10.255
IPADDR=192.168.10.12
NETMASK=255.255.255.0
NETWORK=192.168.10.0
ONBOOT=yes
/etc/init.d/network restart // restart network service
/etc/sysconfig/network //file config network
NETWORKING=yes
HOSTNAME=my-hostname - Hostname is defined here and by command hostname
FORWARD_IPV4=true - True for NAT firewall gateways and linux routers.
False for everyone else - desktops and servers.
GATEWAY="XXX.XXX.XXX.YYY" - Used if your network is connected to another network or the internet.
Static IP configuration. Gateway not defined here for DHCP client.

hostname <new-host-name> //change new hostname
and edit: /etc/sysconfig/network
ifconfig eth1 192.168.10.12 netmask 255.255.255.0 broadcast 192.168.10.255
route add default gw XXX.XXX.XXX.XXX dev eth0
route add -net XXX.XXX.XXX.0 netmask 255.255.255.0 gw XXX.XXX.XXX.XXX dev eth0
Trong Centos, neu add route default ma` khong ke`m theo netmask thi default netmask se la
255.255.255.255. Do do nen kem theo netmask khi add route defaut
route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.20.254.254..


Using vmstat
r -- The average number of runnable kernel threads over whatever sampling interval you have chosen.
b -- The average number of kernel threads that are in the virtual memory waiting queue over your sampling interval. r should always be higher than b; if it is not, it usually means you have a CPU bottleneck.
fre -- The size of your memory free list. Do not worry so much if the amount is really small. More importantly, determine if there is any paging going on if this amount is small.
pi -- Pages paged in from paging space.
po -- Pages paged out to paging space.
CPU section:
us
sy
id
wa
Let's look at the last section, which also comes up in most other CPU monitoring tools, albeit with different headings:
us -- user time
sy -- system time
id -- idle time
wa -- waiting on I/O
Clearly, this system has no bottleneck to speak of. How do you determine this? Let's look at the more important fields to analyze in the vmstat output. Even though this system is running AIX 5.3, you will not see the number of physical processors or the percentage of your consumed entitled capacity because it is not running in a micro-partitioned environment. If it were running in a micro-partitioned environment, you would see these additional fields, as vmstat was enhanced to work in a virtualized and micro-partitioned environment.
If your us and sys entries consistently average over 80 percent, you more than likely have a CPU bottleneck. If they add up to 100 percent, your system is really breathing heavy. If the numbers are small, but wa (waiting on I/O) is high (usually > then 30), this means there might be I/O problems on the system, which can cause the CPU not to work as hard as it could. If more time is spent in sy time rather then us time, this means your system is spending less time crunching numbers than actually processing kernel data. This is also not a good thing.
While the vmstat command is more commonly associated with memory, I have found that it is the quickest and most accurate way to determine what my bottleneck is.
So why did the user complain about the system? Because it really seemed like it was running slow to him. I was only able to get to the root cause after I determined there were no systems problems and his buddy in the adjoining cube had no issues to speak of. So I had him reboot his PC and everything came up clean afterwards. Apparently, something was running haywire on the PC client.



Khi trouble su co, quan trong nhat phai xem dau tien la CPU, disk, hardware ....sau do den log
#cd /var/log
#more messages


full hard disk copy (backup entire hard disk)
dd if=/dev/hdx of=/dev/hdy
dd if=/dev/hdx of=/path/to/image
dd if=/dev/hdx | gzip > /path/to/image.gz
Restore Backup of hard disk copy
dd if=/path/to/image of=/dev/hdx
gzip -dc /path/to/image.gz | dd of=/dev/hdx
MBR backup
In order to backup only the first few bytes containing the MBR and the partition table you can use dd as well.
dd if=/dev/hdx of=/path/to/image count=1 bs=512
MBR restore
dd if=/path/to/image of=/dev/hdx
Add "count=1 bs=446" to exclude the partition table from being written to disk. You can manually restore the table.
// neu thu muc de chua file image la dia USB, ta phai xem lai format cua dia USB, boi vi
neu duoc format duoi FAT32 thi "FAT32 has a limit of 4GB on individual file size"
Xem http://en.wikipedia.org/wiki/File_Allocation_Table . Ta phai chuyen dinh dang cho no'

Format dia theo dinh dang Ext3 cua linux
#mkfs.ext3 /dev/hda5
#mkdir /mnt/hda5
#mount -t ext3 /dev/hda5 /mnt/hda5

Creating a Partition
Warning : Do not attempt to create a partition on a device that is in use (boot into rescue
mode or unmount any partitions on the device and turn off any swap space on the device).
Start "parted", where /dev/hda is the device on which to create the partition:
#parted /dev/hda

#print // view current pattion
#mkpart primary ext3 1024 2048 // Making the Partition with an ext3 file system from 1024
megabytes until 2048 megabytes on a hard drive
#/sbin/mkfs -t ext3 /dev/hdb3 //format
#e2label /dev/hdax /<name>
#vi /detc/fstab
LABEL=/<name> /<mount point> ext3 defaults 1 2

Cai dat RAID 1 cho Linux:
Mot vai chu y :
1) Kernel cua Linux phai support RAID (kernel over 2.4.x is OK, neu < 2.4 thi phai ca`i patch)
2) Raid support phai duoc compile into kener (OK if you see /proc/mdstat exists)
3) If u'r using IDE for raid configure, u should install drives on different IDE ports (controllers)
Very Important
4) The partition that will be used for the raid-1 on the second disk should be about the
same size as first disk, it must be at least as large as the first disk's partition. If the
second disk's partition is larger, the extra space will not be used by raid-1 device.
Xem huong dan http://www.linuxjournal.com/article/5898

Mot vai thao tac quan tri:
#w //Show who is logged on and what they are doing.
#free //show RAM
#du -sh //show capacity of directory
Another way to show capacity of directory with GB
du -h / | grep ^[0-9.]*G // show all directory in / with GB
find / -type d -size +1G // find directory more than 1 GB

mount -t ext3 /dev/<drive's device name> /<home2 or some suitable directory> - Mount the drive


/var/log/messages - system messages
/secure - Logging by PAM of network access attempts
/dmesg - Log of system boot. Also see command dmesg
/boot.log - Log of system init process
/xferlog.1 - File transfer log
/lastlog - Requires the use of the lastlog command to examine contents
/maillog - log from sendmail daemon

//Mot so cau lenh monitor perfomance linux
w - Find Out Who Is Logged on And What They Are Doing (# w username)
uptime - Tell How Long The System Has Been Running (# uptime)
iostat - Average CPU Load, Disk Activity (# iostat)
sar - Collect and Report System Activity (# sar -n DEV | more)
mpstat - Multiprocessor Usage (# mpstat -P ALL)
pmap - Process Memory Usage(# pmap -d PID)
iptraf - Real-time Network Statistics
tcpdump - Detailed Network Traffic Analysis(# tcpdump -i eth1 'udp port 53')
strace - System Calls //http://www.cyberciti.biz/tips/linux-strace-command-examples.html
/Proc file system - Various Kernel Statistics ( # cat /proc/cpuinfo
# cat /proc/meminfo
# cat /proc/zoneinfo
# cat /proc/mounts)
Nagios - Server And Network Monitoring
(Tham khao http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html)

# chkconfig telnet on
# service xinetd reload
Reloading configuration: [ OK ]
# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd: [ OK ]
# ln -s /etc/init.d/vsftpd /etc/rc3.d/S56vsftpd
# ln -s /etc/init.d/vsftpd /etc/rc4.d/S56vsftpd
# ln -s /etc/init.d/vsftpd /etc/rc5.d/S56vsftpd
Configure Telnet for root logins
Simply edit the file /etc/securetty and add the following to the end of the file:
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5
pts/6
pts/7
pts/8
pts/9
This will allow up to 10 telnet sessions to the server as root.

Configure FTP for root logins
Edit the files /etc/vsftpd.ftpusers and /etc/vsftpd.user_list and remove the 'root' line from each file.

OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR
OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR-OR

Linux is configured to run the Telnet and FTP server, but by default, these services are not enabled. To enable these services, login to the server as the root userid and edit the files:
/etc/xinetd.d/telnet
/etc/xinetd.d/wu-ftpd
In both files, find the line for disable and change it from the value "yes" to "no".
After changing the above values, you will need to restart the xinetd deamon. As the root userid, type the following command:
% /etc/init.d/xinetd reload

Configure Telnet for root logins
Simply edit the file /etc/securetty and add the following to the end of the file:
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5
pts/6
pts/7
pts/8
pts/9
This will allow up to 10 telnet sessions to the server as root.
Configure FTP for root logins
First edit the file /etc/ftpaccess and comment out the 'deny-uid' and 'deny-gid' lines.
Also, don't forget to remove the 'root' line from /etc/ftpusers

========================================================
How to MOUNT via network: vi du o day co 2 may A va B, may A co o dia /dev/VolGroup0/disk can mount sang may B
1- Start NFS: (tren may A)
/sbin/service nfs start
2- Mount dia do thanh thu muc (Thao tac tren may A)
A#mount /dev/VolGroup0/disk /tempdisk //mount o dia tren may A thanh thu muc /tempdisk
Tiep theo khai bao trong file /etc/exports
A#vi /etc/exports
/tempdisk 10.200.0.128/255.255.255.192(rw,sync,insecure,no_root_squash)
/tempdisk 116.193.64.0/255.255.255.0(ro,sync,insecure,no_root_squash)
// Cau lenh tren dung de share thu muc /tempdisk tren may A cho cac may trong vung mang nhu tren.
Tiep theo restart lai NFS
A#/sbin/service nfs restart
3- Sang may B thuc hien cau lenh mount
B#mount -t nfs <IP may A>:/tempdisk /<thu muc mount point tren may B>

======================================
multipath -l //show cac LUN tu SAN duoc map vao machine.


1) Plug in the flash drive into one of the USB ports on your computer.
2) Enter the following command:
# lsusb
This will list all usb devices on your system.
3) Go into your /dev directory and look for sdXX where XX is a leter and number ex: sda1.
Some distros will only make a dev for the devices you have and some will not. If there are a lot of sdXX's in there than just start with sda1 and try others if you have no luck.
4) Make a directory to mount your drive, eg. /mnt/usb.
5) Then mount the device:
mount -t vfat /dev/sda1 /mnt/usb



create a temporary directory like /mnt/usb
plug your USB drive.
see the output of `dmesg`
if you see sda
then mkdir /dev/sda1 /mnt/usb
if you see sdb
then mkdir /dev/sdb1 /mnt/usb
and so on...




sorry forgot to paste the link
here it is
http://forums.dreamincode.net/showtopic9989.htm

Khi Mount vùng LUN map tu SAN vào máy xen host, máy chu báo loi :
"mount: you must specify the filesystem type"
Luu ý là do vùng LUN này chua duoc dinh dang trong máy chu xen. Ðe có the mount duoc, ta phai dinh dang cho nó (khi dinh dang, toàn bo du lieu se bi mat):
mkfs.ext3 /dev/mapper/LUN_ID
Sau dó thuc hien lenh mount nhu bình thuong.


Su dung dd de backup full hardisk:
full hard disk copy
dd if=/dev/hdx of=/dev/hdy
dd if=/dev/hdx of=/path/to/image
dd if=/dev/hdx | gzip > /path/to/image.gz
Hdx could be hda, hdb etc. In the second example gzip is used to compress the image if it is really just a backup.
Restore Backup of hard disk copy
dd if=/path/to/image of=/dev/hdx
gzip -dc /path/to/image.gz | dd of=/dev/hdx
MBR backup
In order to backup only the first few bytes containing the MBR and the partition table you can use dd as well.
dd if=/dev/hdx of=/path/to/image count=1 bs=512
MBR restore
dd if=/path/to/image of=/dev/hdx
Add "count=1 bs=446" to exclude the partition table from being written to disk. You can manually restore the table.


Save static route:

The following is a sample route-eth0 file using the network/netmask directives format. The default gateway is 192.168.0.1, interface eth0. The two static routes are for the 10.10.10.0/24 and 172.16.1.0/24 networks. However, as mentioned before, this example is not necessary as the 10.10.10.0/24 and 172.16.1.0/24 networks would use the default gateway anyway:

ADDRESS0=10.10.10.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.0.1
ADDRESS1=172.16.1.0
NETMASK1=255.255.255.0

GATEWAY1=192.168.0.1

Subsequent static routes must be numbered sequentially, and must not skip any values. For example, ADDRESS0, ADDRESS1, ADDRESS2, and so on.

Below is an example of setting static routes to a different subnet, on a machine in the 192.168.0.0/24 subnet. The example machine has an eth0 interface in the 192.168.0.0/24 subnet, and an eth1 interface (10.10.10.1) in the 10.10.10.0/24 subnet:

ADDRESS0=10.10.10.0
NETMASK0=255.255.255.0

GATEWAY0=10.10.10.1


Configure share NFS on Centos:

# mkdir -p /nhuttest
# vi /etc/exports

edit the file with this:

/nhuttest  *(rw,async,no_root_squash)
# exportfs -a
# vi /etc/sysconfig/nfs

Change some parameter as below:

LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
RQUOTAD_PORT=875
STATD_PORT=662
STATD_OUTGOING_PORT=2020

Reboot the services:

# service rpcbind start
# service nfs start
# chkconfig nfs on
# chkconfig rpcbind on
# reboot    

On server we want to mount NFS share, just type:


# mount -t nfs <NFS share server>:/nhuttest <mount point>



Clear cache (or mem cached) or clear memory in Linux:

#sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"


//want to su to system user without type a password 

sudo -u <user> -s

#sudo -u www-data -s



Monitor interface

iftop

IE: sudo iftop -i <interface_name> -f '<port port>'
#sudo iftop -i eth0 -f 'port 8080'


Scan and add new hard drive

echo "- - -" > /sys/class/scsi_host/host#/scan

Show port listening + user + name service

lsof -i:6080

Show linux version

lsb_release -a

Check ext format for disk:

file -s /dev/sda1

Search command:

grep -n '<search string>'  <file> | cut -d<opeator for cut> -f <number>
ex: grep -n '^# Begin Extraction 1:$' KcsSetup.sh
766:# Begin Extraction 1:

grep -n '^# Begin Extraction 1:$' KcsSetup.sh | cut -d: -f 1
766
grep -n '^# Begin Extraction 1:$' KcsSetup.sh | cut -d: -f 2
# Begin Extraction 1
grep -n '^# Begin Extraction 1:$' KcsSetup.sh | cut -d# -f 1
766:
grep -n '^# Begin Extraction 1:$' KcsSetup.sh | cut -d' ' -f 1
766:#


Solaris 9 Command (Basic)

############Cac lenh thuong dung :
/usr/platform/`uname –i`/sbin/prtconfig –v
du -sh // xem current capacity cua thu muc (phai cd vao thu muc, dung tai thu muc do va go du -sh)
(ls -li // )
vi /etc/profile
PATH=/usr/sbin:/usr/bin://bin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/usr/ccs/bin:/usr/local/mysql/bin/:/usr/local/ssl/bin
CPPFLAGS="-I/usr/include -I/usr/local/include -I/usr/local/ssl/include -I/usr/local/BerkeleyDB.4.2/include -I/usr/java/include -I/usr/sfw/include"

#cat /var/sadm/system/admin/CLUSTER //xem coi He dieu hanh nay cai dat loai package na`o
//CLUSTER=SUNWCXall

######
Cac cau lenh search ky tu trong file
grep -c <ky tu> <file> // tra ve so luong ky tu co trong file
grep -l <ky tu> <file> // tra ve ten file

crle -u -v -l /usr/lib:/lib:/etc/lib:/usr/local/lib:/usr/local/ssl/lib:/usr/local/BerkeleyDB.4.2/lib:/usr/share/lib:/usr/xpg4/lib:/usr/sfw/lib:/usr/java/lib:/usr/ccs/lib:/usr/sadm/lib:/etc/security/lib:/opt/csw/lib
export LD_LIBRARY_PATH=/usr/local/lib
ln -s /usr/local/bin/gcc /usr/ccs/bin/cc

uname -r //show version
df -lk //disk space
prtconf //avalaible memory
which <command> //locate position of command
netstat -an | grep LISTEN

Lenh xem cac dia trong he thong : iostat -En
Lenh xem route : route get <net or host>
Set che do graphic cho Solaris :#eeprom console=graphics
#/usr/dt/bin/dtlogin -e
#reboot
##############Cau hinh FTP server voi folder retriction user :
# <tao user, pass>
# useradd -d /export/home/<folder-name> -s /bin/sh <user-name>
# passwd <name>
# cd /etc/ftpd
# vi ftpaccess
# <Them dong sau vao file tren>
# guestuser <name>
# <Update thu muc>
# /usr/sbin/ftpconfig -d /export/home/<foder-name>
# chmod lai thu muc home cua user do'
(<folder-name> va <user-name> ta nen tao giong nhau)
bash-2.05# more /etc/release //show version
#cd var/sadm/patch : show patch
#showrev -p : show patch
#cd /var/sadm/pkg
## /usr/sbin/psrinfo -v : determine the speed of your processor(s)
# /usr/sbin/pkgadd -d /cdrom/cdrom0/directory/Product package_names : add o individual package
in Solaris CD Software
#sys-unconfig // System Undo Config



#####################Change Host Name
For Solaris versions prior to 7, check/edit:
/etc/inet/hosts
/etc/nodename
/etc/hostname.<interface>
where <interface> is the name of the primary interface, e.g. bge0.
/etc/net/ticlts/hosts
/etc/net/ticots/hosts
/etc/net/ticotsord/hosts
Then reboot the system.
For Solaris versions 7 to 9, check/edit:
/etc/inet/hosts
/etc/nodename
/etc/hostname.<interface>
where <interface> is the name of the primary interface, e.g. bge0.
/etc/net/ticlts/hosts
/etc/net/ticots/hosts
/etc/net/ticotsord/hosts
/etc/inet/ipnodes
Then reboot the system.
For Solaris version 10, check/edit:
/etc/inet/hosts
/etc/nodename
/etc/hostname.<interface>
where <interface> is the name of the primary interface, e.g. bge0.
/etc/inet/ipnodes
Then reboot the system.





#################Change IP Address
For Solaris versions prior to 7, check/edit:
/etc/inet/hosts
/etc/hostname.<interfaces>
where <interfaces> are the names of the interfaces, e.g. bge0, bge1, eri0.
/etc/net/ticlts/hosts
/etc/net/ticots/hosts
/etc/net/ticotsord/hosts
If you are moving to a new subnet, check/edit:
/etc/inet/netmasks
/etc/defaultrouter
/etc/resolv.conf
Then reboot the system.
For Solaris versions 7 to 9, check/edit:
/etc/inet/hosts
/etc/hostname.<interfaces>
where <interfaces> are the names of the interface, e.g. bge0, bge1, eri0.
/etc/net/ticlts/hosts
/etc/net/ticots/hosts
/etc/net/ticotsord/hosts
/etc/inet/ipnodes
If you are moving to a new subnet, check/edit:
/etc/inet/netmasks
/etc/defaultrouter
/etc/resolv.conf
Then reboot the system.
For Solaris version 10, check/edit:
/etc/inet/hosts
/etc/hostname.<interfaces>
where <interfaces> are the names of the interface, e.g. bge0, bge1, eri0.
/etc/inet/ipnodes
If you are moving to a new subnet, check/edit:
/etc/inet/netmasks
/etc/defaultrouter
/etc/resolv.conf
Then reboot the system.
########### Change domainname
domainname <domain>
domainname > /etc/defaultdomain

#########################In the ssh configuration files, allow root logins as follows:
# vi /etc/ssh/sshd_config
PermitRootLogin yes
Restart sshd by stopping and starting it.
# /etc/init.d/sshd stop
# /etc/init.d/sshd start


#########################
#ifconfig hme0 plumb



##################################################################################
##Do not connect a keyboard to the Sun machine if you want to use serial console##
##Do not connect a keyboard to the Sun machine if you want to use serial console##
##Do not connect a keyboard to the Sun machine if you want to use serial console##
##Do not connect a keyboard to the Sun machine if you want to use serial console##
##Do not connect a keyboard to the Sun machine if you want to use serial console##
##Do not connect a keyboard to the Sun machine if you want to use serial console##
##################################################################################
To connect to the system console, in the ALOM system controller window, type
sc> console
To return to the ALOM shell prompt (sc>) type #. (pound period).
The chassis serial number is 0547AE81D0 then the default password is:
47AE81D0


###########################
Xem log, config log
#/etc/logadm.conf


###################################################################################
pkggadd -R <installed directory> -a <create admin file> -d <source folder>

pkgadd -R /export/opt/software -d pkg
pkginfo -l <package>

###################################################################################
Error on pkginfo:
bash-2.05# pkginfo -l SUNWxwman
pkginfo: ERROR: bad entry read in contents file
pathname: /platform/SUNW,Sun-Fire-880/kernel/misc/sparcv9/sbdp
problem: unable to read mode/owner/group

Error o pathname nao thi check cai do'.Nhu VD tren thi error tai
/platform/SUNW,Sun-Fire-880/kernel/misc/sparcv9/sbdp , thu hien nhu sau :
Open file :
#cd /var/sadm/install/contents
Vao den do`ng do'
kiem tra loi nhu the nao
Luu lai va reboot

Nho backup lai file nhe'



#############Cac lenh tim kiem ps:
ps - U <user> // tim session cua user
ps -U qmails | grep qmail-se | awk "{print \$4;}" // lenh nay se in ra paramenter thu 4 cua
ket qua 2 lenh truoc

##############Manage command history:
history se duoc luu trong file ~/.bash_history
Neu ta muon sau moi lan logout, may tinh se xoa tat ca history command thi lam nhu sau :
#cd ~
#vi ~/.bash_logout

/bin/rm -f $HOME/.bash_history
clear
wq!
#env
# //logout ra la duoc

Multipathing Command

#if_mpadm -d ce0 //lenh nay dung de deactive card ce0 ra khoi nhom IPMP
#if_mpadm -r ce0 //reactive lai card ce0

######### kiem tra tinh trang he thong
who // xem current user login [-p : hien thi system last reboot] [-m hien thi concurrent reminal] [-r hien thi current system run-level]
prtdiag -v
who -b // he thong duoc boot lai khi nao
who -q // current user login
who -u // giong -q, nhung chi tiet hon.
grep dump /var/adm/m* //tim kiem loi "dump" trong cac file message* (don gian chi la tim
ky tu trong file)
cat /var/adm/messages | grep dump
last <username> //hien thi "history login" ma username nay da login
last reboot //hien thi log cac lan boot
last // neu chi co lenh last khong, he thong se hien thi log cac user da login va cac lan reboot


######### Cac File Log cua he thong
more /etc/syslog.conf



######### Su dung Crontab
crontab -l // de biet cac jobs cua users hien tai
crontab -e // de tao jobs
Cu phap nhu sau
Minute(0-59) Hour (0-23) Day of Month (1-31) Month (1-12 or Jan-Dec) Day of Week (0-6 or Sun-Sat) Command
VD
0 2 12 * 0,6 /usr/bin/find

su dung nhu sau:
export EDITOR=vi
crontab -e //sau do soan thao nhu file vi binh thuong





===========================================
Loi xay ra tren lenh route add

bash-2.05# netstat -rn
Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
202.78.224.129 202.78.224.88 UGH 1 16286
202.78.224.130 202.78.224.88 UGH 1 0
10.254.0.68 10.20.4.254 UGH 1 16047
10.254.0.67 10.20.4.254 UGH 1 14745
192.168.1.209 202.78.224.88 UGH 1 0
202.78.224.64 202.78.224.68 U 1 286104 eri0
202.78.224.128 202.78.224.88 UG 1 1
10.20.254.0 202.78.224.88 UG 1 208544
192.0.2.0 10.20.4.254 UG 1 115384
224.0.0.0 202.78.224.68 U 1 0 eri0
default 202.78.224.90 UG 1 144721
127.0.0.1 127.0.0.1 UH 5929976173 lo0
bash-2.05#
bash-2.05#
bash-2.05#
bash-2.05# route add 10.20.4.0 -netmask 255.255.255.0 10.20.4.31
add net 10.20.4.0: gateway 10.20.4.31: Network is unreachable
Trong khi ping van thay 10.20.4.1 ma` no lai bao loi unreachable
bash-2.05# route add 10.20.4.0 -netmask 255.255.255.0 10.20.4.31 -ifp eri1
add net 10.20.4.0: gateway 10.20.4.31: Network is unreachable
10.20.4.31 la IP cua card mang
bash-2.05# route add -net 10.20.4.0 netmask 255.255.255.0 10.20.4.31 -ifp eri1
netmask: bad value
Nhung no lai thanh cong khi thuc hien lenh sau:
bash-2.05# route add -net 10.20.4.0 -netmask 255.255.255.0 127.0.0.1 -ifp eri1
add net 10.20.4.0: gateway 127.0.0.1
bash-2.05# netstat -rn
Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
202.78.224.129 202.78.224.88 UGH 1 16286
202.78.224.130 202.78.224.88 UGH 1 0
10.254.0.68 10.20.4.254 UGH 1 16047
10.254.0.67 10.20.4.254 UGH 1 14745
192.168.1.209 202.78.224.88 UGH 1 0
202.78.224.64 202.78.224.68 U 1 286104 eri0
202.78.224.128 202.78.224.88 UG 1 1
10.20.254.0 202.78.224.88 UG 1 208544
192.0.2.0 10.20.4.254 UG 1 115384
10.20.4.0 10.20.4.31 U 1 0 eri1
224.0.0.0 202.78.224.68 U 1 0 eri0
default 202.78.224.90 UG 1 144721
127.0.0.1 127.0.0.1 UH 5929976173 lo0


REAL TIME PROCESSES:
# priocntl -d -i class RT
// if realtime process is running, some application (backup fssnap, del file ...) can not
excutable
Xem lai file backup Snapshot
/usr/lib/fs/ufs/fssnap -i <file_system>

######### Tim kiem file
grep -i test /tmp/zone_out |wc -1 // tim kiem tu khoa test trong file /tmp/zone_out






















OpenSolaris Command ######################################
#svcadm enable <service>
Xem /etc/user_attr de hieu vai tro cua root // tren Open Solaris, vai tro cua root co su
thay doi, no se khong log truc tiep vao he thong ma se duoc su thong qua user khac
Do do' khi cai dat Webmin, ta se khong login = account root duoc. Day la cach khac phuc:
Step 1:
#su root
#/usr/sfw/lib/webmin/setup.sh //buoc nay co the khong can
Selected all the default options: //buoc nay co the khong can
Step 2:
Then while root
Edited /etc/webmin/miniserv.users and added them user nhu sau:
nhieu:x:101 (<user>:x:<userID>)
-This allows you to login to the server
Step 3:
And also edited /etc/webmin/webmin.acl //Edit file nay de cap quyen truy cap service cho user
Copy the existing entry for root and added a new line and changed root to nhieu (<user>) to give access to all the modules
Step 4:
Exit root shell and do //restart lai webmin
$ svcadm enable webmin //neu cai dat = .pkg thi lenh se khac
#/etc/init.d webmin stop
#/etc/init.d webmin start
Step 5:
http://localhost:10000


############### Upgrade Webmin
Often Solaris is not configured by default to allow the upgrading of packages.
To change this, edit the file /var/sadm/install/admin/default and change the line
instance=unique to instance=overwrite. This will allow you to install a new Solaris
package of Webmin over an older version.
Another method of upgrading is to use the following commands :
/etc/webmin/stop
cp -r /etc/webmin /etc/webmin.old
pkgrm WSwebmin
mv /etc/webmin.old /etc/webmin
gunzip webmin-1.430.pkg.gz
pkgadd -d webmin-1.430.pkg WSwebmin



##############################
ESTABLISHED có nghia là socket dang nh?n và g?i và di?u này có nghia là có 1 active connection dang ho?t d?ng
SYN_SENT Socket dang ti?n hành thi?t l?p k?t n?i và dang trong quá trình d?i ACK t? host khách
SYN_RECEIVED có nghia là k?t n?i dã du?c xác nh?n, AKA, sau khi dã vu?t qua bu?c SYN_SENT
FIN_WAIT_1 nghia là socket dã du?c l?nh dóng l?i, và dang trong quá trình ng?t k?t n?i.
FIN_WAIT_2 g?n gi?ng _1 ch? khác là dang ch? socket dóng và g?i dóng k?t n?i cho máy khách
CLOSED socket không s? d?ng
CLOSE_WAIT Nghia là remote dã ng?t r?i và dang ch? d? dóng
LAST_ACK có nghia socket dang trong quá trình ch?, phía remote dã k?t thúc và dã dóng và socket dã dóng r?i
LISTEN socket dang ch? 1 k?t n?i d?n.

###############################
Su dung lenh sar de ghi nhan thong tin
###############################
Go phim #. de vao che cho ALOM
Go:
sc>console de vao lai che do console
User va pass de vao ALOM la : admin qtsc


###############################
Auto FTP bang script
###############################
Cach 1: Khong dung Auto-login
~~~~~~~~~~~~~~~~~~~~~~~~~
ftp -n <<Ketthuc // option -n o day la no auto-login
open 202.78.227.54
user nhutnb 67ty)O // user va pass
bin // cac cau lenh sau khi da login thanh cong FTP server dat o day.
ls
by
Ketthuc
Cach 2 : Du`ng Auto-login
~~~~~~~~~~~~~~~~~~~~~
ftp 202.78.227.54 <<Ketthuc
bin
ls
by
Ketthuc
O cach 2 nay khong can khai bao Username va password. Username va password se duoc khai bao
tai file $HOME/.netrc (nen nho la file .netrc luon dat tai thu muc HOME cua user ma` thuc thi script na`y)
# more ~/.netrc
machine 202.78.227.54
login nhutnb
password 67ty)O

Cach khai bao file .netrc tai day : http://www.mavetju.org/unix/netrc.php
Phai set dung quyen cho .netrc la 600

############################
tao script gui mail: (chua test)
#!/bin/bash
# script to send simple email
# email subject
SUBJECT="SET-EMAIL-SUBJECT"
# Email To ?
EMAIL="admin@somewhere.com"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE

##############################
DNS Flush on Solaris
# ps -ef|grep nscd
#kill no' di
Sau do start lai
#/usr/sbin/nscd

date '+%y%m%d'




###################### Su dung Vi trong Console
TERM=vt100
export TERM


#####################Khong truy cap duoc solaris tu Xmanager
Trong solaris, X evironment tu khong start moi khi restart OS. Neu X khong tu dong start, thuc hien nhu sau:
#cd /etc/rc2.d
#S99dtlogin start
Neu van chua duoc thi :
#S99dtlogin reset

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr
top -n 1 //top 1 lan