MySQL DBA - Tips and Techniques Magazine

3 Oct 2014


User Management

a)      Add new user


useradd hslakhan


visudo   (to add to /etc/sudoers  - or see which sudo grp like wheel)

usermod -G wheel  hslakhan


b)      Add new group

Sudo groupadd group 1

Usermod –G group 1,group2  hslakhan

Tail /etc/groups

Hslakhan> newgrp group1   (change primary group)


> cat /etc/issue    (linux distrubtion and version)

> uname –a    (Processor type – 32 or 64 bit)



System messages for invalid logins etc  : tail –f /var/log/secure

Cron messages :  /log/cron



Check system load (filter)

◦ 'w | grep load' will display just the line(s) containing the word load


/etc is for config files

/var is for changing files

/var/logs  , /var/mysql , /var/..mail and spool file   = SYSTEM FILES

tail -f , tail -10 etc


>  redirect file output

| pipe output into next command

Eg cat cron secure > cutom.log

cat custom.log | grep fail |grep authentication

ls | grep cron    (searches filenames)


up arrow / e   - backwards

Down arrow / y  - forwards

Up one page / b

Down one page / d

Specifc line : 20 SHIFT G

/word    - search word  , n is forward

?word – search word backwards

c)      Other:

userdel hslakhan

rm -rf  /home/hslakhan

OR userdel -r hslakhan


d)      Become other user


su hslakhan

sudo su hslakhan (no passwd needed)



chmod u,g,o   , or r=4, w=2, x=1

chown –R owner:group /directory



SYSTEM CRON is in /etc/crontab

crontab –e

crontab –l

USER CRON is in /var/spool/cron  (injcluding root, hslakhan etc)

min hour d_o_m  mon  d_o_w   command  (*/ means intervals eg */1 every minute, */2 every 2 days)

*/1 * * * echo "Harjit" > /tmp/file.tx &1>2

tail – f /var/log/cron   - can check cron jobs that were run

cd etc

ls | grep cron  

shows directories like cron.daily, cron.hourly , cronta.monthly  - can place scripts in here and it will run it automatically.



REPOSITORY = storage location from where software packages can be retieved

PACKAGE = software built from source i.e. compiled code

ADVANTAGES:  OS is tidy and secure (don't require anti-virus/malware) and smaller in size.  User can add/remove packages as required.


Change to root (or run commands as sudo)

CentOS – use YUM

Repos (repositories) contain the packages.  They can be found in   cd /etc  , ls | grep yum

cd /etc/yum.repos.d     (can see it covers most of the system utilities we need)

can download further program by getting the rpm and installing it

or get source and put it directly in this directory

EG want to install http apache server:

Can see in /etc that http doesn't exist

>yum search http     (searches through online repos and returns) :

httpd.i686 : Apache HTTP Server

So now to install we have the options:

1 ) download source files and compile (advanced)

2) go to apache website, download rpm and install using rmp package manager

OR 3) do yum install :

> yum install httpd /y

Can see now ls /etc/http/httpd  is installed

Now do updates, can include security updates :

>  yum update


Debian/Ubuntu – use apt-get

APT = Advanced Packaging Tool

                apt_get caches repos information on your computer, whereas yum checks repos online

> apt_get update   (always do this to make sure cache is upto date)

> apt-cache search apache2

Returns apache2   at the top of listing

>apt-get install apache2

>apt-get upgrade (downloads newest versions of packages)




TOP command

> top


system time , up time, #users on system, load average  1min,  5min , 15 min


 – percentage CPU utilisation.  Eg 0.90 = 90% cpu used

So if 1 cpu system,  and load average = 90%

So if Load average is  1 +

-        If one cpu then 100% used

-        If two cpu then first cpu at 100% second at 0%.

-        If LA is 2 and two cpus, then both are at 100% - system bogged down

-        If quad – 4 processor …






               Top processes


SHIFT N – sort by %MEM

SHIFT P – sort by %CPU

NI  - NICE value , range from -20 to 19 .    19 is lowest priority, -20 highest priority

               R – renice the value,  eg select process eg 31711 , ENTER, -20   

Kill process,    press K,  select process 31711,  signal  eg 15 is close normally and exit it.  -9 is force quit.

Kick off a user,  find the sshd worker process and kill it.

ps aux |grep apache     - will list processes and show apache ones

kill -9 31711

/sbin/killall apache2     ..kills all apache2 processes




This is faster than find as it searches through an index database.  If we have just installed new programs can update the database manually :  > updatedb

> which locate     …if not installed,   apt-get install locate   or yum install locate

> locate motd


find  /etc -name 'motd*'    (find al files in /etc that match motd*)


No comments:

Post a Comment