Friday, February 27, 2015

check serial hard disk on Ubuntu | CentOS

1. sudo smartctl -i -H -c /dev/sda
** for CentOS install package

yum install smartmontools
 
 
vim /etc/smartmontools/smartd.conf
smartctl 6.2 2013-07-26 r3841 [i686-linux-3.13.0-46-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Seagate Momentus 5400.6
Device Model:     ST9500325AS
Serial Number:    6VEMGZEG
LU WWN Device Id: 5 000c50 032cbc8df
Firmware Version: 0001SDM1
User Capacity:    500,107,862,016 bytes [500 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    5400 rpm
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA8-ACS T13/1699-D revision 4
SATA Version is:  SATA 2.6, 3.0 Gb/s
Local Time is:    Fri Feb 27 16:42:48 2015 ICT
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x82) Offline data collection activity
                                        was completed without error.
                                        Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever
                                        been run.
Total time to complete Offline
data collection:                (    0) seconds.
Offline data collection
capabilities:                    (0x7b) SMART execute Offline immediate.
                                        Auto Offline data collection on/off support.
                                        Suspend Offline collection upon new
                                        command.
                                        Offline surface scan supported.
                                        Self-test supported.
                                        Conveyance Self-test supported.
                                        Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                                        power-saving mode.
                                        Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                                        General Purpose Logging supported.
Short self-test routine
recommended polling time:        (   1) minutes.
Extended self-test routine
recommended polling time:        ( 144) minutes.
Conveyance self-test routine
recommended polling time:        (   2) minutes.
SCT capabilities:              (0x103b) SCT Status supported.
                                        SCT Error Recovery Control supported.
                                        SCT Feature Control supported.
                                        SCT Data Table supported.

** ปรับให้ smartd check disk แล้วส่งเมลแจ้งเมื่อพบ Error
vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf

---edit---
#1
# Monitor SMART status, ATA Error Log, Self-test log, and track
# changes in all attributes except for attribute 194
#/dev/sdb -H -l error -l selftest -t -I 194
/dev/sda -a -I 194 -W 4,45,55 -R 5 -m admin@domain.com (-ระบุผู้รับเมล)

#2
# A very silent check.  Only report SMART health status if it fails
# But send an email in this case
#/dev/sdc -H -C 0 -U 0 -m admin@example.com
#/dev/sdc -a -m admin@example.com
/dev/sda -H -C 0 -U 0 -m admin@domain.com (-ระบุผู้รับเม)
/dev/sdb -H -C 0 -U 0 -m admin@domain.com
/dev/sdc -H -C 0 -U 0 -m admin@domain.com
/dev/sdd -H -C 0 -U 0 -m admin@domain.com

-----------------

start service smartd on CentOS
systemctl enable smartd.service
systemctl start smartd.service
systemctl reload smartd.service
systemctl status smartd.service
check status is running
systemctl |grep smartd.service

ทำ Crontab เพื่อให้ smartd ค่อย monitor hard disk
# vim systemctlreload.sh
systemctl reload smartd
# chmod u+x systemctlreload.sh
# vim /etc/crontab
05 05 * * * root /root/systemctlreload.sh

ปรับแต่งการส่งเมลโดยให้ส่งเมลจาก Sender ที่เราต้องการ และปรับแต่ง Subject
vim /etc/smartmontools/smartd_warning.sh
----------------------------------------------------
# Format subject
export SMARTD_SUBJECT="ALERT: SMART error (${SMARTD_FAILTYPE-[SMARTD_FAILTYPE]}) detected on host: $hostname"

# Send mail, use platform mailer by default
  test -n "$SMARTD_MAILER" || SMARTD_MAILER=$os_mailer
  if [ -n "$dryrun" ]; then
    echo "exec '$SMARTD_MAILER' -s '$SMARTD_SUBJECT' -r "noreply@domain.com" $SMARTD_ADDRESS <$fullmessage
EOF"
  else
    exec "$SMARTD_MAILER" -s "$SMARTD_SUBJECT" -r "noreply@domain.com" $SMARTD_ADDRESS <$fullmessage
EOF
  fi
-----------------------------------------------------

หลังปรับ /etc/smartmontools/smartd_warning.sh ทดสอบสคริปด้วยคำสั่ง systemctl reload smartd.service แล้วรันคำสั่ง tail -f /var/log/maillog ดูว่าส่งเมลด้วย Sender ที่เราระบุไหม

vim /etc/smartmontools/smartd.conf
vim /etc/smartmontools/smartd.conf
2. sudo apt-get install lshw
#lshw -class disk
  *-disk                
       description: ATA Disk
       product: ST31500341AS
       vendor: Seagate
       physical id: 0.0.0
       bus info: scsi@2:0.0.0
       logical name: /dev/sda
       version: CC1H
       serial: 9VS1LZJJ
       size: 1397GiB (1500GB)
       capabilities: partitioned partitioned:dos
       configuration: ansiversion=5 signature=1e5b6b6d

Ref: 1.smartd
       2. how-to-monitor-disk-health-with-smartd-s-m-a-r-t

3. df -aTh

Ref:
smartctl

4. check disk health with Graphic mode
on ubuntu install package gsmartcontrol

sudo apt-get install gsmartcontrol

sudo gsmartcontrol






Ref:
gsmartcontrol

Friday, February 20, 2015

Vm Ware system

Copy form : Siamimprove

จากที่เราได้ทำความรู้จักกับ Storage ของ VM  มาแล้วเมื่อเราสร้าง VM ขึ้นมา 1 เครืื่อง ตัว ESX  เองจะสร้างไฟล์ต่าง ๆที่เกี่ยวข้องขึ้นมา โดยจะเก็บอยู่ใน Folder เดียวกันตามชื่อเครื่องที่เราตั้งขึ้นมา

Image
 
ประเภทไฟล์ต่าง ๆ มีดังนี้

ไฟล์ .vmx

   เป็นไฟล์ Configuration ของ VM

ไฟล์ .vswp
   เป็น Swap ของ VM

ไฟล์ .nvram
   เป็นไฟล์ จำลอง BIOS  ของ VM

ไฟล์ .vmem
   เป็นหน่วยความจำที่นำเอาพื้นที่ Disk ไปใช้แทน

ไฟ์ .vmss
   เป็นไฟล์ของ VM ถ้ามีคำสั่งให้ Suspend

ไฟล์ .vmsd
   เป็นไฟล์ข้อมูลของการทำ Snapshot

ไฟล์ -Snapshotxx.vmsn
    เป็นไฟล์สถานะของหน่วยความจำจากการทำ Snapshot

ไฟล์ .log
    เป็นไฟล์ Log ต่าง ๆ

ไฟล์ .vmdk
   เป็นไฟล์ Virtual Disk  (มีความสำคัญมากที่สุดบนโลกของ VMware)

Sunday, February 15, 2015

Datastores of Vmware

The datastores are mounted under /vmfs/volumes
use command copy with scp
scp -r /path/filename user@domain.com:/directory
-r คือ Recursive ซึ่งเป็นการ copy directory และ subdirectory ด้วย

Example: scp -r ARSHQ1F-1  /vmfs/volumes/datastore/

More

Tuesday, January 20, 2015

usb boot able by unetbootin

Create boot from USB from ubuntu
* Install by apt-get
sudo add-apt-repository ppa:gezakovacs/ppa
sudo apt-get update
sudo apt-get install unetbootin

Ref:
unetbootin

1.#Install unetbootin by download from website http://unetbootin.sourceforge.net/#install
2. how to use
chmod +x unetbootin-linux-608
3. execute program
./unetbootin-linux-608







Wednesday, January 14, 2015

encrypt file การเข้ารหัสไฟล์เอกสาร

1. Install programe

sudo aptitude install ccrypt

2. Zip file
tar cjvf file.tar.bz2 file  for creat file .bz2

3. Encrypt file

sudo ccrypt file.tar.bz2

4. Decrypt file

sudo ccrypt -d .file.tar.bz2.cpt


Wednesday, January 7, 2015

เซทให้ส่งเมลได้เฉพาะภายในโดเมนหรือบางโดเมน

1. แก้ไขไฟล์ /etc/postfix/main.cf

myhostname = mailgw.domain.com
mydomain = domain.com
myorigin = $myhostname
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain $mydomain
#mynetworks = hash:/etc/postfix/network_table
mynetworks = 192.168.0.0/24, 10.10.10.0/24
relay_domains = domain.com
transport_maps = hash:/etc/postfix/transport
append_at_myorigin = no
broken_sasl_auth_clients = yes
smtpd_banner = My companee
relayhost = 192.xx.xx.xx
disable_dns_lookups = yes
smtpd_restriction_classes = local_only, local_plus
local_only = reject_unauth_destination
local_plus = check_recipient_access hash:/etc/postfix/local_plus reject_unauth_destination
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/restricted_users
header_checks = regexp:/etc/postfix/header_checks

2. สร้างไฟล์ที่ยอมให้ส่งเมลไปยังที่ไดได้บ้าง /etc/postfix/local_plus

# /etc/postfix/local_plus
# this file contains allowed destinations for users restricted to local_plus
# postmap this file after changes
domain.com OK
domain.org OK
domain.in.th OK

#postmap /etc/postfix/local_plus

3. สร้างไฟล์ที่ไม่ให้ user คนนั้น ๆ ส่งเมลออกภายนอกได้ /etc/postfix/restricted_users

email@domain.com local_plus
email@domain.in.th local_plus

#postmap /etc/postfix/restricted_users

4. แก้ไขไฟล์ /etc/postfix/transport

domain.com                      smtp:mail.mailserver.com:25

#postmap /etc/postfix/transport



Monday, December 15, 2014

Config postfixamdin on Debian 7.7 (postfix+mysql+dovecot)

Read on:
1. debian-wheezy-mail-server-postfix-dovecot-sasl-mysql-postfixadmin-roundcube-spamassassin-clamav-greylist-nginx-php5
2. http://rimuhosting.com/knowledgebase/linux/mail/postfixadmin


1. fix multi domain can't send mail
Error:
: unknown user: “maxime”

fix mydestination = localhost

2. create Local DNS for test mail

setup-dns-server-debian-7-wheezy

     2.1 cat /etc/bind/named.conf.local
//
// Do any local configuration here
//

// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone    "nanyang.com"   {
        type master;
        file    "/etc/bind/nanyang.com";
 };
zone    "sirivatana.com"   {
        type master;
        file    "/etc/bind/sirivatana.com";
 };

zone   "122.168.192.in-addr.arpa"        {
       type master;
       file    "/etc/bind/db.192.168.122";
 };

zone   "122.168.192.si.in-addr.arpa"        {
       type master;
       file    "/etc/bind/db.192.168.122.si";
 };
------------------------------------------------------------------------
     2.2 cat /etc/bind/nanyang.com
;
; BIND data file for local loopback interface
;
$TTL    604800
@       IN      SOA     pop3s.nanyang.com. root.nanyang.com. (
                         121220143      ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL

        IN      A       192.168.122.10
;
@       IN      NS      pop3s.nanyang.com.
@       IN      MX      10      pop3s.nanyang.com.
@       IN      A       192.168.122.10
@       IN      AAAA    ::1
pop3s   IN      A       192.168.122.10
mail    IN      A       192.168.122.10
dns     IN      A       192.168.122.10
www     IN      A       192.168.122.10
--------------------------------------------------------------------------
     2.3 cat /etc/bind/db.192.168.122
;
; BIND reverse data file for local loopback interface
;
$TTL    604800
@       IN      SOA     pop3s.nanyang.com. root.pop3s.nanyang.com. (
                         121220142      ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      pop3s.
@       IN      A       192.168.122.10
10      IN      PTR     pop3s.nanyang.com.

3. setup Superuser postfixadmin

3.1#cp config.inc.php.bak config.inc.php
--------------------------Edit file----------------------
$CONF['configured'] = true; $CONF['postfix_admin_url'] = 'https://192.168.122.10/postfixadmin';
$CONF['database_type'] = 'mysqli'; $CONF['database_host'] = 'localhost'; $CONF['database_user'] = 'postfix_admin'; $CONF['database_password'] = ''; $CONF['database_name'] = 'postfix'; $CONF['domain_path'] = 'YES'; $CONF['domain_in_mailbox'] = 'NO'; $CONF['fetchmail'] = 'NO';
------------------------------------------------

3.2 run setup.php from browser: https://192.168.122.10/postfixadmin/setup.php
Step 1 Click Generate password hash


Step 2 add Gen passwd to config.inc.php

add $CONF['setup_password'] = '13a402059836b65b6531a7a16d66dfbb:223b34da76ccf8daeb193737e2266be3dc2e7e6b'; to file config.inc.php and save and then create Supper user postfixadmin



Step 3 add Super user postfixadmin done!
* ในการสร้าง user จะมีพาสเวิร์ด 2 ส่วนคือ
1. ส่วน Setup password ต้องจำให้ได้ว่า ตอนแรกใส่พาวเวิร์ดอะไรไว้ เพราะมันเข้ารหัสไว้ เช่น '13a402059836b65b6531a7a16d66dfbb:223b34da76ccf8daeb193737e2266be3dc2e7e6b';
2. Password Admin: พาสเวิร์ดที่ตั้งไว้ให้กับ Super Admin


4. Dovecot

You really want to change in /etc/dovecot/conf.d/10-mail.conf:

mail_location = maildir:/home/vmail/%d/%n:INDEX=/home/vmail/%d/%n/indexes
to
mail_location = maildir:/home/vmail/%Ld/%Ln:INDEX=/home/vmail/%Ld/%Ln/indexes

otherwise if someone will send you email with mixed case such as AbCdE@ExAmPle.com then dovecot will create a NEW directories for the same user.

5. vacation
postfixadmin-setup-with-correct-vacation-settings-on-freebsd

Error: Command output: Can't locate
    MIME/EncWords.pm
#apt-get install libmime-encwords-perl

Command output: Can't locate
    Email/Valid.pm
#apt-get install libemail-valid-perl

Command output: Can't locate
    Mail/Sender.pm
Run command....
# perl -MCPAN -e shell
Y to all

  cpan> install Mail::Sender
  cpan> quit

#apt-get install libmail-sendmail-perl libdbd-pg-perl libemail-valid-perl libmime-tools-perl liblog-log4perl-perl liblog-dispatch-perl libgetopt-argvfile-perl libmime-charset-perl libmime-encwords-perl

Tuesday, November 18, 2014

script add new user on centos


---------------------------adduser.sh----------------------------------------------------
#!/bin/bash
# Script to add a user to Linux system

if [ $(id -u) -eq 0 ]; then
        read -p "Enter realname : " realname
#       read -p "Enter company : " company
        read -p "Enter username : " username
        read -s -p "Enter password : " password
        egrep "^$username" /etc/passwd >/dev/null
        if [ $? -eq 0 ]; then
                echo "$username exists!"
                exit 1
        else
                sender=email@mydomain.com
                pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
                useradd -p $pass $username -c "$realname" -m -g group -s /sbin/nologin
                [ $? -eq 0 ] && echo "User has been added to system!" && echo | mail -s "Welcome new email, Do not reply mail" < user.txt mooy@mydomain.com -c image@mydomain.com -- -f $sender  || echo "Failed to add a user!"
        fi
else
        echo "Only root may add a user to the system"
        exit 2
fi

-------------------------------------------------------------------------------

----------------------------------user.txt------------------------------------
Hi
You email address: mooy@mydomain.com
password: m12345


By.
Auto Generate mail.
-----------------------------------------------------------------------------

Monday, November 17, 2014

How to generate user & password on ubuntu

Install package makepasswd
apt-get install makepasswd

makepasswd -count 100 --chars 6 --string=คำที่ต้องการนำไป Gen ใช้คำ ข้อความ ตัวอักษรเล้กใหญ่ หรือตัวเลข > passwor.txt