multipath -ll
fdisk -l
echo "1" > /sys/class/fc_host/host0/issue_lip
echo "1" > /sys/class/fc_host/host1/issue_lip
multipath -ll
fdisk -l
multipath -ll
pvcreate /dev/mapper/mpath4
pvdisplay
vgcreate vglog_file /dev/mapper/mpath4
lvcreate -L 100G vglog_file -n lvlog_file
lvcreate -L 99G vglog_file -n lvlog_file
mkfs.ext3 /dev/mapper/vglog_file-lvlog_file
mkdir logfile
mount -t ext3 /dev/mapper/vglog_file-lvlog_file /logfile/
chown sysadmin:root logfile/
echo "/dev/mapper/vglog_file-lvlog_file /logfile/ ext3 defaults 1 2">>/etc/fstab
Showing posts with label administration. Show all posts
Showing posts with label administration. Show all posts
Oct 12, 2011
Mount SAN's Partition over Fiber cable for Linux
Sep 21, 2011
Change Bash Color in Linux
Add this following line in to : '/etc/bashrc'
PS1='\[\033[04;33m\]\t\033[00m\]-\033[04;32m\]\u\033[04;33m\]@\033[04;31m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'
Example:
PS1='\[\033[04;33m\]\t\033[00m\]-\033[04;32m\]\u\033[04;33m\]@\033[04;31m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'
Example:
Sep 14, 2011
LINUX SERVER PASSWORD POLICY
Password Aging
New Accounts
/etc/login.defs and /etc/default/useradd are the files related to password aging on new accounts.
/etc/login.defs:
# Password aging controls: # # PASS_MAX_DAYS Maximum number of days a password may be used. # PASS_MIN_DAYS Minimum number of days allowed between password changes. # PASS_MIN_LEN Minimum acceptable password length. # PASS_WARN_AGE Number of days warning given before a password expires.
/etc/default/useradd:
INACTIVE=-1 EXPIRE=
By default, password inactivity (i.e., the number of days after a password is expired in which a user can no longer reset it themselves) and an account expiration date are disabled.
Note that PASS_MIN_LEN in /etc/login.defs has no effect. Minimum password length is controlled by the pam_cracklib module. If minlen= is not specified in pam_cracklib, the default minimum password length is 6 characters.
Existing Accounts
/usr/bin/chage is used to modify password aging on existing accounts. chage does not update the last password change field (field 3) in /etc/shadow, so passwords could expire immediately after running it. You may run it with the -d option to modify the last password change field in /etc/shadow.
Example
User hutchib was already created with essentially no password aging (the default PASS_MAX_DAYS of 99999). To configure the following:
- A minimum of 7 days between password changes.
- Password expiration after 90 days.
- Begin warning about password expiration 14 days in advance.
# /usr/bin/chage -m 7 -M 90 -W 14 hutchib
What happens when your password expires?
- If the account is inactive (see chage -I and field 7 in /etc/shadow), you will be unable to login and your password will have to be manually reset by an administrator.
e.g., /var/log/messages entry:
Dec 4 14:33:42 host sshd(pam_unix)[31601]: account hutchib has expired (failed to change password)
- If the account is expired but not inactive, you are allowed a "grace login" where your old password is accepted, but you must immediately change your password. After changing your password, the connection is closed and you must login again.
WARNING: Your password has expired. You must change your password now and login again! Changing password for user hutchib. Changing password for hutchib (current) UNIX password: New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully. Connection to host closed.
Password Length and Complexity
Both pam_cracklib and pam_passwdqc are modules used in enforcing password length and complexity. Although pam_passwordqc is more powerful, I'll be using pam_cracklib as its capabilities meet our site's needs and it is already in the PAM stack.
Example: Require a minimum password length of 9 characters, with at least 1 lowercase character, 1 uppercase character, and 1 digit.
Relevant entry in bold in /etc/pam.d/system-auth:
password requisite /lib/security/$ISA/pam_cracklib.so retry=3 minlen=12 lcredit=1 ucredit=1 dcredit=1 ocredit=0
Password History
Password history--i.e., preventing re-use of old passwords--may be enabled using both pam_unix (stores the old password) and pam_cracklib(prevents re-use). By default, password history is disabled.
Example: Prevent re-use of each user's last 24 passwords.
- Create the password database store.
# touch /etc/security/opasswd # chown root:root /etc/security/opasswd # chmod 600 /etc/security/opasswd
- Configure PAM.
Relevant entry in bold in /etc/pam.d/system-auth:
password sufficient /lib/security/$ISA/pam_unix.so nullok use_authtok md5 shadow remember=24
Account Lockout
Account lockout after a number of unsuccessful authentication attempts may be enabled using pam_tally. In this example, accounts are locked out after 5 failed login attempts. Twice an hour, the failed login counter is reset. The failed login counter is also reset with each successful authentication (resetoption in PAM configuration).
- Create the pam_tally store for failed login attempts.
# touch /var/log/faillog # chown root:root /var/log/faillog # chmod 600 /var/log/faillog
- Configure PAM.
RHEL 3/4 Example
Relevant entries in bold in /etc/pam.d/system-auth:
auth required /lib/security/$ISA/pam_env.so auth required /lib/security/$ISA/pam_tally.so onerr=fail no_magic_root auth sufficient /lib/security/$ISA/pam_unix.so likeauth nullok auth required /lib/security/$ISA/pam_deny.so account required /lib/security/$ISA/pam_unix.so account sufficient /lib/security/$ISA/pam_succeed_if.so uid < 100 quiet account required /lib/security/$ISA/pam_permit.so account required /lib/security/$ISA/pam_tally.so deny=5 no_magic_root reset
- pam_tally on RHEL 3/4 does not support the unlock_time parameter. Run the reset_failed_logins script periodically from cron to reset the number of failed logins.
Example root crontab:
# Reset pam_tally counter twice hourly 0,30 * * * * /usr/local/bin/reset_failed_logins
RHEL 5 Example
Modifications needed for pam_tally2 in RHEL 5:
- pam_tally2 on RHEL 5 supports the unlock_time paramter.
- deny is allowed in the auth phase only, not the account phase.
- no_magic_root and reset are not valid options.
Relevant entries in bold in /etc/pam.d/system-auth:
auth required /lib/security/$ISA/pam_env.so auth required /lib/security/$ISA/pam_tally.so onerr=fail deny=5 unlock_time=1800 auth sufficient /lib/security/$ISA/pam_unix.so likeauth nullok auth required /lib/security/$ISA/pam_deny.so account required /lib/security/$ISA/pam_unix.so account sufficient /lib/security/$ISA/pam_succeed_if.so uid < 100 quiet account required /lib/security/$ISA/pam_permit.so account required /lib/security/$ISA/pam_tally.so
Sep 8, 2011
How to create automated Linux/Unix backups
“A stitch in time saves nine”, goes an old saying. In the world of computers we refer to that stitch as backups. When running a production IT infrastructure, it is imperative that we achieve an uptime on our servers and applications of as close to a hundred percent as possible. While there are a number of ways to make an IT infrastructure solid, it is impossible to make it failure proof. So we make a plan B.
Servers are made of three broad layers – the hardware, the operating system and applications, and the data. In case of a hardware failure it is rather simple to replace the machine with a new one. Installing the operating system and applications too are relatively simple. The part that is hard to replace is the data and configuration that your applications use. In case of failure this is the part that can not be replaced. So we backup that data on a regular basis. We back it up in such a way that it becomes easy to retrieve in case of emergency.
I will guide you through writing a script to take daily backups on your system. For this exercise I will use a server that runs the Apache web server, a MySQL database server, and has a directory on the /home partition that contains some data that needs to be backed up. We will also backup the previous day’s Apache access logs in a separate backup directory. First, we need to create a directory where our backups will reside. As part of the exercise I have created a directory called BACKUP on the /opt partition. We will organize the backups in this directory so that each days backup resides in a directory formed like this – /opt/BACKUP/YEAR/MONTH/DATE/. So on the 11th of August 2008 the backups will go into /opt/BACKUP/2008/08/11/. Let’s create these directories. Run the following set of commands as the root user.
# mkdir -p /opt/backup/DATA/2008
# cd /opt/backup/DATA/2008
# mkdir 01 02 03 04 05 06 07 08 09 10 11 12
# cd /opt/backup/DATA/
# cp -r 2008 2009
# cd /opt/backup/
# cp -r DATA LOG
# cd /opt/backup/DATA/2008
# mkdir 01 02 03 04 05 06 07 08 09 10 11 12
# cd /opt/backup/DATA/
# cp -r 2008 2009
# cd /opt/backup/
# cp -r DATA LOG
See note below before issuing this last command.
# chown -R calvin.calvin /opt/backup
We now have two sets of backup directories – one for data and another for log files. With the backups directories created we are now ready to start writing the script. Note: I’m using the user calvin throughout this article. Please replace calvin with your own username.
###########################################################
# CODE BEGINS HERE
###########################################################
#!/bin/bash
# SERVER DATA BACKUP V1.0
#########################
# BACKUP CONFIG
#########################
# BACKUP CONFIG
#########################
#Configure the month, date, and day
YEAR=`date +”%Y”` # 2008
MONTH=`date +”%m”`# 11
DAY=`date +”%d”` # 14
YESTERDAY=`date –date=”yesterday” +%Y-%m-%d` # 2008-11-13
YESTERDAY_DATE=`date –date=yesterday +%d` # 13
YESTERDAY_MONTH=`date –date=yesterday +%m` # 11
YESTERDAY_YEAR=`date –date=yesterday +%Y` # 2008
TODAY=`date +%Y-%m-%d` # 2008-11-14
TODAY_DATE=`date +%d` # 14
YEAR=`date +”%Y”` # 2008
MONTH=`date +”%m”`# 11
DAY=`date +”%d”` # 14
YESTERDAY=`date –date=”yesterday” +%Y-%m-%d` # 2008-11-13
YESTERDAY_DATE=`date –date=yesterday +%d` # 13
YESTERDAY_MONTH=`date –date=yesterday +%m` # 11
YESTERDAY_YEAR=`date –date=yesterday +%Y` # 2008
TODAY=`date +%Y-%m-%d` # 2008-11-14
TODAY_DATE=`date +%d` # 14
# directories to backup to
DATA_BACKUP_PARENT_DIR=/opt/backup/DATA/ # <-- Change this your data backup dir
LOG_BACKUP_PARENT_DIR=/opt/backup/LOG/ # <-- Change this your log backup dir
DATA_BACKUP_PARENT_DIR=/opt/backup/DATA/ # <-- Change this your data backup dir
LOG_BACKUP_PARENT_DIR=/opt/backup/LOG/ # <-- Change this your log backup dir
# Apache Document Root Directory
APACHE_DOCROOT=/var/www/html/
APACHE_DOCROOT=/var/www/html/
# MySQL Database config
DB_IP="localhost" # <-- Change this to the IP of your database server
DB_USER="calvin" # <-- Change this to your database username
DB_PASS="calvin_password" # <-- Change this to your database password
DB_NAME="clientlist" # <-- Change this to your database name
DB_IP="localhost" # <-- Change this to the IP of your database server
DB_USER="calvin" # <-- Change this to your database username
DB_PASS="calvin_password" # <-- Change this to your database password
DB_NAME="clientlist" # <-- Change this to your database name
# Apache Log Dir
APACHE_LOG_DIR="/var/log/httpd/" # <-- Change this to the path data of your logs
APACHE_LOG_DIR="/var/log/httpd/" # <-- Change this to the path data of your logs
# Application Files' Dir
APP_FILES="/home/calvin/application_files/" # <-- Change this to the path of the data directory
APP_FILES="/home/calvin/application_files/" # <-- Change this to the path of the data directory
# Config Dir
CONFIG_DIR="/etc/" # <-- Change this to the path data directory
CONFIG_DIR="/etc/" # <-- Change this to the path data directory
# Mail report address
EMAIL_ID="you@youremailid.com" # <-- Change this to your e-mail ID
EMAIL_ID="you@youremailid.com" # <-- Change this to your e-mail ID
###########################################################
# DATA BACKUP
###########################################################
# DATA BACKUP
###########################################################
# Create and go into backup directory
cd $DATA_BACKUP_PARENT_DIR/$YEAR/$MONTH
mkdir $DAY
cd $DAY
cd $DATA_BACKUP_PARENT_DIR/$YEAR/$MONTH
mkdir $DAY
cd $DAY
# Database backup
mysqldump -h ${DB_IP} -u ${DB_USER} -p${DB_PASS} ${DB_NAME} > ${DB_NAME}.db
tar -zcvf ${DB_NAME}.tar.gz ${DB_NAME}.db
rm -f ${DB_NAME}.db
mysqldump -h ${DB_IP} -u ${DB_USER} -p${DB_PASS} ${DB_NAME} > ${DB_NAME}.db
tar -zcvf ${DB_NAME}.tar.gz ${DB_NAME}.db
rm -f ${DB_NAME}.db
# /etc backup
tar -zcf etc.tar.gz /etc
tar -zcf etc.tar.gz /etc
# Application backup
tar -zcf Apache_Doc_Root.tar.gz ${APACHE_DOCROOT}
tar -zcf App_Files.tar.gz ${APP_FILES}
tar -zcf Apache_Doc_Root.tar.gz ${APACHE_DOCROOT}
tar -zcf App_Files.tar.gz ${APP_FILES}
###########################################################
# LOG BACKUP
###########################################################
# LOG BACKUP
###########################################################
# Create and go into backup directory
cd $LOG_BACKUP_PARENT_DIR/$YESTERDAY_YEAR/$YESTERDAY_MONTH
mkdir $YESTERDAY_DATE
cd $YESTERDAY_DATE
cd $LOG_BACKUP_PARENT_DIR/$YESTERDAY_YEAR/$YESTERDAY_MONTH
mkdir $YESTERDAY_DATE
cd $YESTERDAY_DATE
# HTTPD Log Backup
for i in ${APACHE_LOG_DIR}/access_log.${YESTERDAY}*; do cp $i .; done
for i in access_log.${YESTERDAY}*; do gzip $i; done
for i in ${APACHE_LOG_DIR}/access_log.${YESTERDAY}*; do cp $i .; done
for i in access_log.${YESTERDAY}*; do gzip $i; done
###########################################################
# Send out mail notifications
###########################################################
# Send out mail notifications
###########################################################
# Mail notify
du -shc $DATA_BACKUP_PARENT_DIR/$YEAR/$MONTH/$DAY/* | mail -s “Backup for ${HOSTNAME}::DATA done
” ${EMAIL_ID}
du -shc $LOG_BACKUP_PARENT_DIR/$YESTERDAY_YEAR/$YESTERDAY_MONTH/$YESTERDAY_DATE/* | mail -s “Backup for ${HOSTNAME}::LOG done
” ${EMAIL_ID}
du -shc $DATA_BACKUP_PARENT_DIR/$YEAR/$MONTH/$DAY/* | mail -s “Backup for ${HOSTNAME}::DATA done
du -shc $LOG_BACKUP_PARENT_DIR/$YESTERDAY_YEAR/$YESTERDAY_MONTH/$YESTERDAY_DATE/* | mail -s “Backup for ${HOSTNAME}::LOG done
###########################################################
# CODE ENDS HERE
###########################################################
# CODE ENDS HERE
###########################################################
Save this script in a directory such as /home/calvin/scripts/backup.sh. Give executable permissions to the file:
# chmod +x /home/calvin/scripts/backup.sh
Now you are good to go. Run the script form your command line:
# /home/calvin/scripts/backup.sh
You can also optionally add this script as a cron job so that it will be executed on a daily basis at a time of your choice. If you want to run this script at 4 AM daily do the following:
# crontab -e
Create a new line in the file that opens and add the following:
0 4 * * * /home/calvin/scripts/backup.sh > /dev/null
There you go. Your server will now backup your data, database, configuration files, application files, and log files to /opt/backup everyday at 4 AM. A smart thing to do now would be to export these backups to a remote machine so that you don’t lose your backups if your server faces problems. We will cover how to do that in my next article.
Subscribe to:
Posts (Atom)
