MySQL Replication Document@CA

As Root User on Server 1 (192.168.210.116)
==========================================

cd /var/lib/mysql
mv auto.cnf auto_.cnf
mkdir -p /Data/mysqldata
chown -R mysql:mysql /mysqldata
chmod -R 777 /mysqldata
cp mysql -r /Data/mysqldata
service mysql stop
<<<change /etc/my.cnf file and edit data_dir>>
cd /var/lib/
cd /Data/mysqldata
tar -zcvf mysql.tgz mysql
scp -P6381 mysql.tgz dbaadmin@192.168.210.117:/Data/mysqldata/

My.cnf File
———–
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#datadir=/var/lib/mysql
datadir=/Data/mysqldata/mysql
socket=/var/lib/mysql/mysql.sock

join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
max_connections = 300
bind-address=0.0.0.0
key_buffer = 32M
key_buffer_size=256M
myisam_sort_buffer_size = 128M
bulk_insert_buffer_size=1G
#join_buffer_size = 1M
#read_buffer_size = 1M
#sort_buffer_size = 2M
#table_cache = 5120
innodb_buffer_pool_size=1G
innodb_additional_mem_pool_size=20M
innodb_log_file_size=256M
innodb_log_buffer_size=8M
innodb_flush_log_at_trx_commit=1
innodb_lock_wait_timeout=50
innodb_flush_method=O_DIRECT
transaction-isolation=READ-COMMITTED
wait_timeout = 1800
connect_timeout=15
max_allowed_packet = 24M
max_connect_errors = 10
query_cache_limit = 10M
query_cache_size = 32M
query_cache_type = 1
max_connect_errors = 1844674407370954751
thread_cache_size = 256
skip-name-resolve
tmp_table_size=524288000
max_heap_table_size=524288000

# —————
server_id=001
log-bin=/Data/mysqldata/BinaryLogs/ad1/master1
log-bin-index=/Data/mysqldata/BinaryLogs/ad1/bin-log.index
relay-log=/Data/mysqldata/BinaryLogs/ad1/relay-log
relay-log-index=/Data/mysqldata/BinaryLogs/ad1/relay-log.index
relay-log-space-limit = 4G
auto_increment_increment = 10
auto_increment_offset = 1

binlog-do-db= ctrdb
binlog-ignore-db=mysql
binlog-ignore-db=test
binlog-format=MIXED

#master-host = 192.168.210.49
#master-user = replication
#master-password = slave
#master-port = 3306

# ——————————————————————————–

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Login to MySQL Terminal :

grant replication slave on *.* to ‘replication’@192.168.210.116 identified by ‘slave’;
grant replication slave on *.* to ‘replication’@192.168.210.117 identified by ‘slave’;

show master status; (note the position and log).
stop slave;

on server 1:(192.168.210.116)
change master to master_host= ‘192.168.210.117’, master_port=3306, master_user=’replication’, master_password=’slave’, master_log_file=’master2.000002′, master_log_pos=120, master_connect_retry=10 ;

start slave;
show slave status \G;
show master status;

============================================
As Root User on Server 2 (192.168.210.117)
============================================

mkdir /Data/mysqldata
cd /Data
chmod -R 777 mysqldata/
chown -R mysql:mysql mysqldata/

as dbadmin user

sudo tar -zxvf mysql.tgz
service mysql stop
cd /Data/mysqldata
tar -xvf mysql.tgz
<<<change /etc/my.cnf file and edit data_dir>>>
service mysql stop

MY.CNF FILE
————–
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#datadir=/var/lib/mysql
datadir=/Data/mysqldata/mysql
socket=/var/lib/mysql/mysql.sock

join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
max_connections = 300
bind-address=0.0.0.0
key_buffer = 32M
key_buffer_size=256M
myisam_sort_buffer_size = 128M
bulk_insert_buffer_size=1G
#join_buffer_size = 1M
#read_buffer_size = 1M
#sort_buffer_size = 2M
#table_cache = 5120
innodb_buffer_pool_size=1G
innodb_additional_mem_pool_size=20M
innodb_log_file_size=256M
innodb_log_buffer_size=8M
innodb_flush_log_at_trx_commit=1
innodb_lock_wait_timeout=50
innodb_flush_method=O_DIRECT
transaction-isolation=READ-COMMITTED
wait_timeout = 1800
connect_timeout=15
max_allowed_packet = 24M
max_connect_errors = 10
query_cache_limit = 10M
query_cache_size = 32M
query_cache_type = 1
max_connect_errors = 1844674407370954751
thread_cache_size = 256
skip-name-resolve
tmp_table_size=524288000
max_heap_table_size=524288000

# —————
server_id=002
log-bin=/Data/mysqldata/BinaryLogs/ad2/master2
log-bin-index=/Data/mysqldata/BinaryLogs/ad2/bin-log.index
relay-log=/Data/mysqldata/BinaryLogs/ad2/relay-log
relay-log-index=/Data/mysqldata/BinaryLogs/ad2/relay-log.index
relay-log-space-limit = 4G
auto_increment_increment = 10
auto_increment_offset = 1

binlog-do-db= ctrassetdb
binlog-ignore-db=mysql
binlog-ignore-db=test
binlog-format=MIXED

#master-host = 192.168.210.49
#master-user = replication
#master-password = slave
#master-port = 3306

# ——————————————————————————–

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
open Terminal of MySQL:
———————–

STOP SLAVE;

On Server 2:(192.168.210.117)

change master to master_host= ‘192.168.210.116’, master_port=3306, master_user=’replication’, master_password=’slave’, master_log_file=’master1.000002′,master_log_pos=120, master_connect_retry=10 ;

START SLAVE;
SHOW SLAVE STATUS \G;
show master status;

Advertisements

Configuration of VNC-Server on CentOS 5.7 & Prior Versions of CentOS 5.9

Steps to configure VNC server on CentOS:

//First verify version & redhat-release by following command:

[root@centos ~]# cat /proc/version
[root@centos ~]# cat /etc/redhat-release

//Install required packages:
[root@centos ~]# yum install vnc* -y
[root@centos ~]# yum groupinstall “GNOME Desktop Environment” -y
OR
You can download repected rpm of vnc & GNOME Desktop environment from web.

[root@centos ~]# vncpasswd
Password: supp0rt
Verify: supp0rt

//Edit this file as below
[root@centos ~]# nano /etc/sysconfig/vncservers
VNCSERVERS=”2:root”
VNCSERVERARGS[2]=”-geometry 1024×800″

//Restart VNC-Server services by issuing following command:

[root@centos ~]# service vncserver stop
[root@centos ~]# service vncserver start
OR
[root@centos ~]# service vncserver restart

//Edit following file, Remove comments
[root@centos ~]# nano .vnc/xstartup
unset SESSION_MANAGER // Remove comment
exec /etc/X11/xinit/xinitrc // Remove comment

//Stop all iptables.
[root@centos ~]# /etc/init.d/iptables stop

//Restart VNC-Server services again by issuing following command:
[root@centos ~]# service vncserver stop
[root@centos ~]# service vncserver start
OR
[root@centos ~]# service vncserver restart

//Access vnc from browser:
URL: <IP_address>:5802
OR
You can use VNC Viewer to take access.

You will get GUI of the same server.

**************************************************************

Share the terminal session in Linux

For that you need to install “screen” by issuing following command:

[root@centos ~]# yum install screen* -y
OR
Install “screen” via rpm package according to your linux version.

Create new screen by issuing following command:
[root@centos ~]# screen -S Terminal_Share_demo

Open duplicate session of same linux server and issue following command for terminal sharing:
[root@centos ~]# screen -x Terminal_Share_demo

This is two-way sharing.

Type Ctrl + a + d to get out of the screen.

***********************************************************************

Linux Usefull commands

df -kh
free -m
cat /proc/cpuinfo | grep processor | wc -l
cat /etc/redhat-release
ps -ef|grep mysql

Check number of CPU’s

–$cat /proc/cpuinfo

Check memory information

–cat /proc/meminfo

Check swap

–$swapon -s

Kernel parameter

–#/sbin/sysctl -a
cat /etc/sysctl.conf

System error log

–/var/log/messages

Nic configuration

–ifconfig -a

Directory Commands – mkdir

To create a new directory below current directory:

–$ mkdir new-dir-name

To create multiple versions of directory:

–$ mkdir -p dir1/dir2/dir3

Creates dir1 first. Creates dir2 under dir1. Creates dir3 under dir2
To create a directory with given permissions:

–$ mkdir -m 754 new-dir

new-dir will be created with 754 permissions

Directory Commands – rmdir

To remove a directory:

–$ rmdir dir-name

rmdir can remove only empty directories
To remove directory along parent directory:

–$rmdir -p dir1/dir2/dir3

Deletes all the directories

Directory Commands – cd

Stands for change directory
Used to navigate among directories

–$ cd dir1

Takes to dir1 directory

–$ cd

Takes to the home directory
Can give full-path-name or relative-path-name as argument

Linux Macine:

–# uname -m

—————————————————————————————————————————————-
File Backup using ‘tar’ command
—————————————————————————————————————————————-
The “tar” command stands for tape archive that generally used by system/database administrator to
write archives directly to tape devices or can use it to create archives files on disk.
The ‘tar’ program is easy to use and transportable having limits on file name size,
won’t backup special files, does not follow symbolic links, and doesn’t support multiple volumes.
The main advantage is that ‘tar’ is supported every where or can be moved easily from one disk to another disk or machine to machine.
It is also useful for copying directories.

The ‘tar’ program takes one of three function command line arguments:

c – to create a tar file

t – table of contents (see the name of all files)

x – extract (restore) the contents of the tar file.

In addition to above function command line argument these argument are useful:

f – Specifies filename

z – Use zip/unzip to compress the tar file or to read from a compressed tar file.

v – Verbose output, show the file being stored into or restored from tar file.

Example:

To tar all .arc and .ctf files into a tar file named data.tgz use:

–tar cvzf data.tgz *.arc *.ctf

This will creates (c) a compressed tar file name data.tgz (f) and shows the file being stored into the tar file (v). The .tgz suffix is a convention for gzipped tar file.

To extract files from tar file

–tar –xvf filename.tar

To tar up all files and directories under current directories or under PROD1 directory and writes files to filename.tar.

–tar cvzf data.tgz shahid123

–tar -cvf /tmp/filename.tar .

–tar -cvf /tmp/filename.tar PROD1

It is often more useful to tar a directory (which tar all files and subdirectories recursively unless you specify other option)

To see a tar file table of contents

–tar tzf data.tgz

To display only the content in tar binary file

–tar –tvf filename.tar

When file size is too large (more than 8GB), use –E option.

–tar -cvfE /data/oradata/tars/PROD1/large_file_blob.tar

—————————————————————————————————————————————-
Retrieve Oracle version information
—————————————————————————————————————————————-

SQL> select * from v$version where banner like ‘Oracle%’;

—————————————————————————————————————————————-
Other Commands
—————————————————————————————————————————————-

As a DBA you need to use frequent OS command or alt least how to query the OS and its hardware.
Usually we do it before fresh install upgrade, migrate of database/operating system. Here is some of the useful frequently
used day to day OS command for DBA.

To find and delete files older than N number of days:
find . -name ‘*.*’ -mtime +[N in days] -exec rm {} ;
Example : find . -mtime +5 -exec rm {} ;
The above command is specially useful to delete log, trace, tmp file

To list files modified in last N days:
find . -mtime – -exec ls -lt {} ;
Example: find . -mtime +3 -exec ls -lt {} ;1
The above command will find files modified in last 3 days

To sort files based on Size of file:
ls -l | sort -nk 5 | more
useful to find large files in log directory to delete in case disk is full

To find files changed in last N days :
find -mtime -N –print
Example: find -mtime -2 -print

To find CPU & Memory detail of linux:
cat /proc/cpuinfo (CPU)
cat /proc/meminfo (Memory)

Linux: cat /proc/cpuinfo|grep processor|wc -l

HP: ioscan -fkn -C processor|tail +3|wc -l

Solaris: psrinfo -v|grep “Status of processor”|wc –l

psrinfo -v|grep “Status of processor”|wc –l

lscfg -vs|grep proc | wc -l

To find if Operating system in 32 bit or 64 bit:

ON Linux: uname -m
On 64-bit platform, you will get: x86_64 and on 32-bit patform , you will get:i686
On HP: getconf KERNEL_BITS
On Solaris: /usr/bin/isainfo –kv
On 64-bit patform, you will get: 64-bit sparcv9 kernel modules and on 32-bit, you will get: 32-bit sparc kernel modules. For solaris you can use
directly: isainfo -v
If you see out put like: “32-bit sparc applications” that means your O.S. is only 32 bit but if you see output like “64-bit sparcv9 applications”
that means youe OS is 64 bit & can support both 32 & 64 bit applications.

To find if any service is listening on particular port or not:
netstat -an | grep {port no}
Example: netstat -an | grep 1523

To find Process ID (PID) associated with any port:
This command is useful if any service is running on a particular port (389, 1521..) and that is run away process which you wish to terminate using kill
command
lsof | grep {port no.} (lsof should be installed and in path)

How to kill all similar processes with single command:
ps -ef | grep opmn |grep -v grep | awk ‘{print $2}’ |xargs -i kill -9 {}

Locating Files under a particular directory:
find . -print |grep -i test.sql

To remove a specific column of output from a UNIX command:
For example to determine the UNIX process Ids for all Oracle processes on server (second column)
ps -ef |grep -i oracle |awk ‘{ print $2 }’

Changing the standard prompt for Oracle Users:
Edit the .profile for the oracle user
PS1=”`hostname`*$ORACLE_SID:$PWD>”

Display top 10 CPU consumers using the ps command:
/usr/ucb/ps auxgw | head -11

Show number of active Oracle dedicated connection users for a particular ORACLE_SID
ps -ef | grep $ORACLE_SID|grep -v grep|grep -v ora_|wc -l

Display the number of CPU’s in Solaris:
psrinfo -v | grep “Status of processor”|wc -l

Display the number of CPU’s in AIX:
lsdev -C | grep Process|wc -l

Display RAM Memory size on Solaris:
prtconf |grep -i mem

Display RAM memory size on AIX:
First determine name of memory device: lsdev -C |grep mem
then assuming the name of the memory device is ‘mem0’ then the command is: lsattr -El mem0
Swap space allocation and usage:
Solaris : swap -s or swap -l
Aix : lsps -a

Total number of semaphores held by all instances on server:
ipcs -as | awk ‘{sum += $9} END {print sum}’
View allocated RAM memory segments:
ipcs -pmb

Manually deallocate shared memeory segments:
ipcrm -m ”

Show mount points for a disk in AIX:
lspv -l hdisk13

Display occupied space (in KB) for a file or collection of files in a directory or sub-directory:
du -ks * | sort -n| tail

Display total file space in a directory:
du -ks .

Cleanup any unwanted trace files more than seven days old:
find . *.trc -mtime +7 -exec rm {} ;

Locate Oracle files that contain certain strings:
find . -print | xargs grep rollback

Locate recently created UNIX files:
find . -mtime -1 -print

Finding large files on the server:
find . -size +102400 -print
Crontab Use:

To submit a task every Tuesday (day 2) at 2:45PM
45 14 2 * * /opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1

To submit a task to run every 15 minutes on weekdays (days 1-5)
15,30,45 * 1-5 * * /opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1

To submit a task to run every hour at 15 minutes past the hour on weekends (days 6 and 0)
15 * 0,6 * * opt/oracle/scripts/tr_listener.sh > /dev/null 2>&1

—————————————————————————————————————————————-
UNIX Useful Commands
—————————————————————————————————————————————-

1) Find whether OS is 64/32 Bit Kernel in UNIX.

uname -a

2) Find free physical memory in UNIX.

free -m

3) Find CPU details in UNIX.

cat /proc/cpuinfo

4) Find files modified within specific time.

find . -mtime -3 (modified less than 3days ago)

5) command used to alter file permissions.

chmod 777 abc.txt

6) Command used to reset the Ownership.

chown oracle:dba abc.txt

7) command used to set, or reset, the users login password.

Passwd username

8) Kill specific process in UNIX.

Kill -9 processid

9) Command used for display last given lines of a file.

tail -n alert_PROD.log

10) Command used for intall a rpm package.

rpm -ivh packagename.rpm

11) Command used to querry about any rpm package

rpm -q packagename

12) Command to Check the server up time

uptime

13) Command to check the file versions

strings -a <filename> |grep ‘$Header’

14) Command will keep ‘n’ number of days files and remove rest of file.

find . -mtime +n -exec rm {} ; &

15) Basic commands for vi editor

i :- insert before cursor.

l : insert begining of the line.

a :- append after the cursor.

A :- Append at the end of the line.

o :- insert a blank line below the cursor.

O :- insert a blank line above the cursor position.

h :- from current position one char towards left .

I :- from current position one char towards right.

j :- from current position one line towards down.

k :- from current position one line towards up.

Shift+g :- go to end of the file.

Shift+:1 :- go to top of the file.

dd –> delete the ful line.

:q! —> closing the file without saving any changes.

:wq! –> save the changes and force close.

:w –> to save the changes without closing the file.

————————————————————————————————————————————————————-
UNIX Crontab Basics
————————————————————————————————————————————————————-

A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.
#——————————————————————————————
# Minute Hour Month Day Month Weekday Command
# 0-59 0-23 1-31 1-12 0-6 (0=Sunday)
#——————————————————————————————
* * * * * command to be executed
– – – – –
| | | | |
| | | | +—– day of week (1 – 7) (monday = 1)
| | | +——- month (1 – 12)
| | +——— day of month (1 – 31)
| +———– hour (0 – 23)
+————- min (0 – 59)
crontab -e Edit your crontab file, or create one if it doesn’t already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file.
Example:
To run the calendar command at 6:30 a.m. every Monday, Wednesday, and Friday, enter:
1

30 6 * * 1,3,5 /usr/bin/calendar

To run the calendar command every day of the year at 6:30, enter the following:
1

30 6 * * * /usr/bin/calendar

To run a script called maintenance every day at midnight in August, enter the following:
1

0 0 * 8 * /u/harry/bin/maintenance

Note : You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use,
crontab if your name does not appear in the file /usr/lib/cron/cron.deny. If only cron.deny exists and is empty

—————————————————————————————————————————————————————————-

scp stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.

You can this way copy files from or to a remote server, you can even copy files from one remote server to another remote server, without passing through your PC.
Syntax:
scp [[user@]from-host:]source-file [[user@]to-host:][destination-file]

Description of options

from-host: Is the name or IP of the host where the source file is, this can be omitted if the from-host is the host where you are actually issuing the command

user: Is the user which have the right to access the file and directory that is supposed to be copied in the cas of the from-host and the user who has the rights to write in the to-host

source-file:Is the file or files that are going to be copied to the destination host, it can be a directory but in that case you need to specify the -r option to copy the contents of the directory

destination-file:Is the name that the copied file is going to take in the to-host, if none is given all copied files are going to maintain its names
Options

-p Preserves the modification and access times,
as well as the permissions of the source-file in the destination-file
-q Do not display the progress bar
-r Recursive, so it copies the contents of the
source-file (directory in this case) recursively
-v Displays debugging messages

Example

[oracle@testdb]$ scp java.tar.gz tamim@172.168.0.222:/home/tamim/
The authenticity of host ‘172.168.0.222 (172.168.0.222)’ can’t be established.
RSA key fingerprint is 23:b9:a4:b9:93:99:28:1f:4c:08:fa:8a:5f:d7:10:d0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘172.168.0.222’ (RSA) to the list of known hosts.
tamim@172.168.0.222’s password:
java.tar.gz 100% 35MB 11.7MB/s 00:03

File is successfully transfer to the host 172.168.0.222 in home/tamim directory

To copy a directory user scp –r

========================================================================================================
Some useful Linux Command for DBA
========================================================================================================

ls: List files
cp: Copy files
mv: Move and rename files
mkdir: Make a directory
alias: Define command macros
rm: Remove files and directories
more: Page through output
head: Show beginning of file contents
tail: Show end of file contents
df: Display filesystem space usage
du: Display directory disk space usage
cat: Show and concatenate files
grep: Search for patterns in files
chmod: Change permissions of files
chown: Change owner of files
zip: Compress and package files together
gedit: A WYSIWYG text editor
export: Make environment settings global
ps: List running processes
touch: Change file time stamps
id: Show information about the current user
sudo: Execute commands as another user

Standard Measurement Tools
• Top Resource Consumers: top
• System Activity Reporter: sar
• Virtual Memory Statistics: vmstat
• I/O Statistics: iostat
• System Log files: /var/log/messages
Linux Tools
• X-based tools: xosview
• The /proc virtual file system
• Free and used memory: free
Tools for monitoring and tuning CPU include:
• top
• pstree and free
• vmstat
• Syntax: vmstat <interval> <count>
• Example : # vmstat 2 5
• mpstat –p All
• sar –u
• Syntax: #sar -B <frequency> <count>
#sar -R <frequency> <count>
• Example : #sar -B 2 3
#sar -R 2 3
• xosview
• xload
• System Monitor
Measuring Total Memory
• top
• free
• cat /proc/meminfo
Monitoring and Tuning I/O

• /proc file system
• sar -d
• I/O statistics by device [iostat –d]
Syntax : iostat -d <interval> <count>
Eample : #iostat -d 2 2
• I/O activity by partition
iostat –d -p <interval> <count>
• vmstat
• xosview
====================================================================================================================

Check number of CPU’s

$cat /proc/cpuinfo

Check memory information

cat /proc/meminfo

Check swap

$swapon -s

Kernel parameter

#/sbin/sysctl -a
cat /etc/sysctl.conf

System error log

/var/log/messages

Nic configuration

ifconfig -a

How to add a user to the sudoers list

How to add a user to the sudoers list? Beleive it or not, this is a fairly common question and in all reality the answer is quite simple. Adding a user to the sudoers list on a fully installed Linux system such as Debian is only possible via the command visudo. Users in the sudoers list are allowed the privileges to run commands and open files as the root user. In the following quick tutorial, we will show you how adding a new sudoer is quickly done.

How to add a user to the sudoers list:

Open a Root Terminal and type visudo (to access and edit the list)
Using the up/down arrows, navigate to the bottom of the sudoers file that is now displayed in the terminal
Just under the line that looks like the following:

root ALL=(ALL) ALL

Add the following (replacing user with your actual username):

user ALL=(ALL) ALL

Now press Ctrl+X and press Y when promted to save

That’s it, your new user now has root privileges!

Ref:http://www.pendrivelinux.com/how-to-add-a-user-to-the-sudoers-list/

Configuration of VNC-Server on CentOS 6.0 & Above Versions

Steps to configure VNC server on CentOS:

//First verify version & redhat-release by following command:
[root@centos ~]# cat /proc/version
[root@centos ~]# cat /etc/redhat-release

//Install required packages:

[root@centos ~]# yum -y install tigervnc-server xorg*
[root@centos ~]# yum groupinstall “General Purpose Desktop” –y
OR
You can download repected rpm of “tigervnc-server, xorg & General Purpose Desktop” from web.

[root@centos ~]# vncpasswd
Password: supp0rt
Verify: supp0rt

//Edit this file as below
[root@centos ~]# nano /etc/sysconfig/vncservers
VNCSERVERS=”2:root”
VNCSERVERARGS[2]=”-geometry 1024×800″

//Restart VNC-Server services by issuing following command:
[root@centos ~]# service vncserver stop
[root@centos ~]# service vncserver start
OR
[root@centos ~]# service vncserver restart

//Edit this file as below
[root@centos ~]# nano .vnc/xstartup
#twm & //comment last line.
exec gnome-session & //add this line

//Stop all iptables.
[root@centos ~]# /etc/init.d/iptables stop

//Restart VNC-Server services by issuing following command:
[root@centos ~]# service vncserver stop
[root@centos ~]# service vncserver start
OR
[root@centos ~]# service vncserver restart

//Access vnc from browser:
URL: <IP_address>:5802
OR
You can use VNC Viewer to take access.

You will get GUI of the same server.

***********************************************************************

How to stop/start and disable/enable Firewall on Redhat 7 Linux system

How to stop/start and disable/enable Firewall on Redhat 7 Linux system:
———————————————————————–

The firewall on Redhat 7 Linux system is enabled by default. Normally there should not be a need to disable firewall but it may be quite handy for testing purposes etc. On Redhat 7 Linux system the firewall run as firewalld daemon. Bellow command can be used to check the firewall status:

[root@rhel7 ~]# systemctl status firewalld
firewalld.service – firewalld – dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
Active: active (running) since Thu 2014-09-04 19:18:47 EST; 3 months 28 days ago
Main PID: 539 (firewalld)
CGroup: /system.slice/firewalld.service
└─539 /usr/bin/python -Es /usr/sbin/firewalld –nofork –nopid

Sep 04 19:18:45 rhel7 systemd[1]: Starting firewalld – dynamic firewall daemon…
Sep 04 19:18:47 rhel7 systemd[1]: Started firewalld – dynamic firewall daemon.

From the above output we can see that the firewall is enabled, which means it will start automatically after reboot and that is also current active. Furthermore, or you can even check all currently applied rules with:

[root@rhel7 ~]# iptables-save

1. Stop and Start RHEL7 firewall
The firewall on Redhat 7 Linux system can be stopped by a following command:

[root@rhel7 ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service

Stopped firewall will start again after system’s reboot. To start firewall on Redhat 7 Linux system use:

[root@rhel7 ~]# service firewalld start
Redirecting to /bin/systemctl start firewalld.service

2. Disable and Enable RHEL7 firewall
In order to completely disable RHEL7 firewall so it would no load after reboot run:

[root@rhel7 ~]# systemctl disable firewalld
rm ‘/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service’
rm ‘/etc/systemd/system/basic.target.wants/firewalld.service’

Now the firewall would not start after system’s reboot. To enable the firewall again run:

[root@rhel7 ~]# systemctl enable firewalld
ln -s ‘/usr/lib/systemd/system/firewalld.service’ ‘/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service’
ln -s ‘/usr/lib/systemd/system/firewalld.service’ ‘/etc/systemd/system/basic.target.wants/firewalld.service’

Reset forgotten Linux Root Password

Reset forgotten Linux Root Password

1. Introduction

The following steps were done on a CentOS 6.3 OS, however the same can be replicated with few modifications on almost all Linux distributions.
If you run lilo boot loader instead of grub you can use the same method but with some modifications on how to edit lilo boot prompt.

2. Edit Grub boot menu options

First you need to get into grub menu options. This menu is displayed right at the beginning of the boot. If you cannot see your grub menu options press “ESC‘ key.
You should get something similar to this:
Grub Boot Option
Now we attempt to edit grub’s boot option. Press “e” to edit the first grub menu option and navigate to kernel line:
Editing the Grub Boot loader
Press “e” key again to edit and remove:
quiet splash 
and add:

init=/bin/bash 
You may have some different boot options but the main part you need to change/ add is init=/bin/bash. You will get something similar to this:
Editing the Grub Boot Loader

Once you have edited the line, simply press “enter key” to return to the Grub Boot menu as shown.

Grub Boot menu
At this point, we have edited grub boot menu, and we are ready to boot. Press “b” key to boot.

3. Remount / and /proc

After successfully boot you will be presented with bash command prompt:
bash command prompt
On some linux systems, you will need to completely mount / and /proc partitions. To do that, enter following commands:

# mount -o remount,rw / 
# mount -o remount,rw /proc 
NOTE: If you are not sure that if your partition is already mounted RW, run the above command anyway as, otherwise on some systems you will not be able reset your root password. If you fail to do so, you get this error displayed on the screen:

passwd: Authentication token lock busy 
NOTE: On some Linux distributions, you will have /proc mounted already if this is not your case, just run following command:
# mount /proc 
Remounting the / and /proc filesystem

4. reset / recover forgotten Linux root password

To reset a actual root password is now simple as typing :

# passwd

Changing the password for root

5. Reboot

Before you reboot it is recommended but not compulsory to run:

# sync

That’s it !! You have now successfully changed the root password of your Linux system.

Stay tuned to more such how-to tutorials coming your way shortly !!

Basic Unix Commands

command Description
a2p Creates a Perl script from an awk script.
ac Prints statistics about users’ connect time.
alias Create a name for another command or long command string.
ar Maintain portable archive or library.
arch Display the architecture of the current host.
arp Manipulate the system ARP cache.
as An assembler.
at Command scheduler.
awk Awk script processing program.
basename Deletes any specified prefix from a string.
bash Command Bourne interpreter
bc Calculator.
bdiff Compare large files.
bfs Editor for large files.
bg Continues a program running in the background.
biff Enable / disable incoming mail notifications.
break Break out of while, for, foreach, or until loop.
bs Battleship game.
bye Alias often used for the exit command.
cal Calendar
calendar Display appointments and reminders.
cancel Cancels a print job.
cat View or modify a file.
cc C compiler.
cd Change directory.
chdir Change directory.
chekeq Language processors to assist in describing equations.
checknr Check nroff and troff files for any errors.
chfn Modify your own information or if super user or root modify another users information.
chgrp Change a groups access to a file or directory.
chkey Change the secure RPC key pair.
chmod Change the permission of a file.
chown Change the ownership of a file.
chsh Change login shell.
cksum Display and calculate a CRC for files.
clear Clears screen.
cls Alias often used to clear a screen.
cmp Compare files.
col Reverse line-feeds filter.
comm Compare files and select or reject lines that are common.
compress Compress files on a computer.
continue Break out of while, for, foreach, or until loop.
copy Copy files.
cp Copy files.
cpio Creates archived CPIO files.
crontab Create and list files that you wish to run on a regular schedule.
csh Execute the C shell command interpreter
csplit Split files based on context.
ctags Create a tag file for use with ex and vi.
cu Calls or connects to another Unix system, terminal or non-Unix system.
curl Transfer a URL.
cut Cut out selected fields of each line of a file.
date Tells you the date and time in Unix.
dc An arbitrary precision arithmetic package.
df Display the available disk space for each mount.
deroff Removes nroff/trofftbl, and eqn constructs.
dhclient Dynamic Host Configuration Protocol Client.
diff Displays two files and prints the lines that are different.
dig DNS lookup utility.
dircmp Lists the different files when comparing directories.
dirname Deliver portions of path names.
dmesg Print or control the kernel ring buffer.
dos2unix Converts text files between DOS and Unix formats.
dpost Translates files created by troff into PostScript.
du Tells you how much space a file occupies.
echo Displays text after echo to the terminal.
ed Line oriented file editor.
edit Text editor.
egrep Search a file for a pattern using full regular expressions.
elm Program command used to send and receive e-mail.
emacs Text editor.
enable Enables / Disables LP printers.
env Displays environment variables.
eqn Language processors to assist in describing equations.
ex Line-editor mode of the vi text editor.
exit Exit from a program, shell or log you out of a Unix network.
expand Expand copies of file s.
expr Evaluate arguments as an expression.
fc The FC utility lists or edits and re-executes, commands previously entered to an interactive sh.
fg Continues a stopped job by running it in the foreground
fgrep Search a file for a fixed-character string.
file Tells you if the object you are looking at is a file or if it is a directory.
find Finds one or more files assuming that you know their approximate filenames.
findsmb List info about machines that respond to SMB name queries on a subnet.
finger Lists information about the user.
fmt Simple text formatters.
fold Filter for folding lines.
for Shell built-in functions to repeatedly execute action(s) for a selected number of times.
foreach Shell built-in functions to repeatedly execute action(s) for a selected number of times.
fromdos Converts text files between DOS and Unix formats.
fsck Check and repair a Linux file system.
ftp Enables ftp access to another terminal.
getfacl Display discretionary file information.
gprof The gprof utility produces an execution profile of a program.
grep Finds text within a file.
groupadd Creates a new group account.
groupdel Enables a super user or root to remove a group.
groupmod Enables a super user or root to modify a group.
gunzip Expand compressed files.
gview A programmers text editor.
gvim A programmers text editor.
gzip Compress files.
halt Stop the computer.
hash Remove internal hash table.
hashstat Display the hash stats.
head Displays the first ten lines of a file, unless otherwise stated.
help If computer has online help documentation installed this command will display it.
history Display the history of commands typed.
host DNS lookup utility.
hostid Prints the numeric identifier for the current host.
hostname Set or print name of current host system.
id Shows you the numeric user and group ID on BSD.
ifconfig Sets up network interfaces.
ifdown take a network interface down
ifup bring a network interface up
isalist Display the native instruction sets executable on this platform.
jobs List the jobs currently running in the background.
join Joins command forms together.
keylogin Decrypt the user’s secret key.
kill Cancels a job.
ksh Korn shell command interpreter.
ld Link-editor for object files.
ldd List dynamic dependencies of executable files or shared objects.
less Opposite of the more command.
lex Generate programs for lexical tasks.
link Calls the link function to create a link to a file.
ln Creates a link to a file.
lo Allows you to exit from a program, shell or log you out of a Unix network.
locate List files in databases that match a pattern.
login Signs into a new system.
logname Returns users login name.
logout Logs out of a system.
lp Prints a file on System V systems.
lpadmin Configure the LP print service.
lpc Line printer control program.
lpq Lists the status of all the available printers.
lpr Submits print requests.
lprm Removes print requests from the print queue.
lpstat Lists status of the LP print services.
ls Lists the contents of a directory.
mach Display the processor of the current host.
mail One of the ways that allows you to read/send E-Mail.
mailcompat Provide SunOS 4.x compatibility for the Solaris mailbox format.
mailx Mail interactive message processing system.
make Executes a list of shell commands associated with each target.
man Display a manual of a command.
mesg Control if non-root users can send text messages to you.
mii-tool View, manipulate media-independent interface status.
mkdir Create a directory.
mkfs Build a Linux file system, usually a hard disk partition.
more Displays text one screen at a time.
mount Disconnects a file systems and remote resources.
mt Magnetic tape control.
mv Renames a file or moves it from one directory to another directory.
nc TCP/IP swiss army knife.
neqn Language processors to assist in describing equations.
netstat Shows network status.
newalias Install new elm aliases for user or system.
newform Change the format of a text file.
newgrp Log into a new group.
nice Invokes a command with an altered scheduling priority.
niscat Display NIS+ tables and objects.
nischmod Change access rights on a NIS+ object.
nischown Change the owner of a NIS+ object.
nischttl Change the time to live value of a NIS+ object.
nisdefaults Display NIS+ default values.
nisgrep Utilities for searching NIS+ tables.
nismatch Utilities for searching NIS+ tables.
nispasswd Change NIS+ password information.
nistbladm NIS+ table administration command.
nmap Network exploration tool and security / port scanner.
nohup Runs a command even if the session is disconnected or the user logs out.
nroff Formats documents for display or line-printer.
nslookup Queries a name server for a host or domain lookup.
on Execute a command on a remote system, but with the local environment.
onintr Shell built-in functions to respond to (hardware) signals.
optisa Determine which variant instruction set is optimal to use.
pack Shrinks file into a compressed file.
pagesize Display the size of a page of memory in bytes, as returned by getpagesize.
passwd Allows you to change your password.
paste Merge corresponding or subsequent lines of files.
pax Read / write and writes lists of the members of archive files and copy directory hierarchies.
pcat Compresses file.
perl Perl is a programming language optimized for scanning arbitrary text files, extracting information from those text files.
pg Files perusal filters for CRTs.
pgrep Examine the active processes on the system and reports the process IDs of the processes
pico Simple and very easy to use text editor in the style of the Pine Composer.
pine Command line program for Internet News and Email.
ping Sends ICMP ECHO_REQUEST packets to network hosts.
pkill Examine the active processes on the system and reports the process IDs of the processes
poweroff Stop the computer.
pr Formats a file to make it look better when printed.
priocntl Display’s or set scheduling parameters of specified process(es)
printf Write formatted output.
ps Reports the process status.
pvs Display the internal version information of dynamic objects within an ELF file.
pwd Print the current working directory.
quit Allows you to exit from a program, shell or log you out of a Unix network.
rcp Copies files from one computer to another computer.
reboot Stop the computer.
red Line oriented file editor.
rehash Recomputes the internal hash table of the contents of directories listed in the path.
remsh Runs a command on another computer.
repeat Shell built-in functions to repeatedly execute action(s) for a selected number of times.
rgview A programmers text editor.
rgvim A programmers text editor.
rlogin Establish a remote connection from your terminal to a remote machine.
rm Deletes a file without confirmation (by default).
rmail One of the ways that allows you to read/send E-Mail.
rmdir Deletes a directory.
rn Reads newsgroups.
route Show / manipulate the IP routing table.
rpcinfo Report RPC information.
rsh Runs a command on another computer.
rsync Faster, flexible replacement for rcp.
rview A programmers text editor.
rvim A programmers text editor.
s2p Convert a sed script into a Perl script.
sag Graphically displays the system activity data stored in a binary data file by a previous sar run.
sar Displays the activity for the CPU.
script Records everything printed on your screen.
sdiff Compares two files, side-by-side.
sed Allows you to use pre-recorded commands to make changes to text.
sendmail Sends mail over the Internet.
set Set the value of an environment variable.
setenv Set the value of an environment variable.
setfacl Modify the Access Control List (ACL) for a file or files.
settime Change file access and modification time.
sftp Secure file transfer program.
sh Runs or processes jobs through the Bourne shell.
shred Delete a file securely, first overwriting it to hide its contents.
shutdown Turn off the computer immediately or at a specified time.
sleep Waits a x amount of seconds.
slogin OpenSSH SSH client (remote login program).
smbclient An ftp-like client to access SMB/CIFS resources on servers.
sort Sorts the lines in a text file.
spell Looks through a text file and reports any words that it finds in the text file that are not in the dictionary.
split Split a file into pieces.
stat Display file or filesystem status.
stop Control process execution.
strip Discard symbols from object files.
stty Sets options for your terminal.
su Become super user or another user.
sysinfo Get and set system information strings.
sysklogd Linux system logging utilities.
tabs Set tabs on a terminal.
tail Delivers the last part of the file.
talk Talk with other logged in users.
tac Concatenate and print files in reverse.
tar Create tape archives and add or extract files.
tbl Preprocessor for formatting tables for nroff or troff.
tcopy Copy a magnetic tape.
tcpdump Dump traffic on a network.
tee Read from an input and write to a standard output or file.
telnet Uses the telnet protocol to connect to another remote computer.
time Used to time a simple command.
timex The timex command times a command; reports process data and system activity.
todos Converts text files between DOS and Unix formats.
top Display Linux tasks.
touch Change file access and modification time.
tput Initialize a terminal or query terminfo database.
tr Translate characters.
traceroute Print the route packets take to network host.
troff Typeset or format documents.
ul Reads the named filenames or terminal and does underlining.
umask Get or set the file mode creation mask.
unalias Remove an alias.
unhash Remove internal hash table.
uname Print name of current system.
uncompress Uncompressed compressed files.
uniq Report or filter out repeated lines in a file.
unmount Crates a file systems and remote resources.
unpack Expands a compressed file.
untar Create tape archives and add or extract files.
until Execute a set of actions while/until conditions are evaluated TRUE.
useradd Create a new user or updates default new user information.
userdel Remove a users account.
usermod Modify a users account.
vacation Reply to mail automatically.
vedit Screen-oriented (visual) display editor based on ex.
vgrind Grind nice program listings
vi Screen-oriented (visual) display editor based on ex.
vim A programmers text editor.
view A programmers text editor.
w Show who is logged on and what they are doing.
wait Await process completion.
wc Displays a count of lines, words, and characters in a file
whereis Locate a binary, source, and manual page files for a command.
while Repetitively execute a set of actions while/until conditions are evaluated TRUE.
which Locate a command.
who Displays who is on the system.
whois Internet user name directory service.
write Send a message to another user.
X Execute the X windows system.
xfd Display all the characters in an X font.
xlsfonts Server font list displayer for X.
xset User preference utility for X.
xterm Terminal emulator for X.
xrdb X server resource database utility.
yacc Short for yet another compiler-compiler, yacc is a compiler.
yes Repeatedly output a line with all specified STRING(s), or ‘y’.
yppasswd Changes network password in the NIS database.
zcat Compress files.

Vi Editor Commands

Here are a few useful commands for those who are new to vi.

esc :q! Just quit – don’t save
esc :e! Revert to saved
esc :wq Save and exit
esc shift zz Save and exit
esc i Enter insert mode (edit mode)
esc a Enter append mode (edit mode)
esc Exit edit mode
esc r Replace a single character
esc x Delete a single character
esc  u Undo last Change
esc  U Undo all changes to line
esc dd Delete a single line
esc yy Copy a single line
esc p Paste a single line
. Repeat the last command
esc / String search
esc $ Jump to end of line
esc ^ Jump to begining of line
shift g (or) :$ Jump to the end of the file
:1  or gg Jump to the begining of the file
:.= Display the current line number
nG  (or) :n Move to nth line of the file
:set nu To turn ON numbering to each line
:set nonu To turn OFF numbering to each line

FIND & REPLACE :

Syntax:          :%s/WORD-To-Find-HERE/Replace-Word-Here/g

Examples

To find each occurrence of ‘UNIX’, and replace it with ‘Linux’, enter (press ESC, type : and following command):
                                 :%s/UNIX/Linux/g

Task: Find and Replace with Confirmation

Find a word called ‘UNIX’ and replace with ‘Linux’, but ask for confirmation first, enter:
:%s/UNIX/Linux/gc

Task: Find and Replace Whole Word Only

Find whole words exactly matching ‘UNIX’ to ‘Linux’; and ask for confirmation too:
:%s/\<UNIX\>/Linux/gc

Task: Case Insensitive Find and Replace

Find ‘UNIX’ (match UNIX, unix, UnIx, Unix and so on) and replace with ‘Linux’:
:%s/unix/Linux/gi

Same command with confirmation:
:%s/unix/Linux/gic

Task: Case sensitive Find and Replace

Find each ‘UNIX’ and replace with ‘bar’:
:%s/UNIX/bar/gI

Same command with confirmation:

:%s/UNIX/bar/gIc

How Do I Replace In the Current Line Only?

Find ‘UNIX’ and replace with ‘Linux’ in the current line only (note % is removed from substitute command)
       :s/UNIX/Linux/g

NOTE: You need to prefix % the substitute command to make changes on all lines:

     :%s/UNIX/Linux/g

 How Do I Replace All Lines Between line 100 and line 250?

     :{START-n},{END-n}s/word1/word2/g

EX : Find ‘UNIX’ and replace with ‘Linux’ all lines between line 100 and line 250, enter
:100,200s/UNIX/Linux/g

OR
           :100,200s/UNIX/Linux/gc

Task :  Count the word ABC  in entire vi file     :%s/ABC/ABC/g