Wednesday, May 20, 2015

System Administration Best Practices

System Administration Best Practices


Linux distributions have three branches

SLS :


The Softlanding Linux System (SLS) distribution, which evolved into the Slackware
distribution, is one of the oldest

RPM

The Red Hat Package Manager (RPM) was developed by Red Hat in order to
provide some structure for software management.

DPKG or DEB


The Debian Packaging System (DPKG/DEB) was developed about the same time
as the RPM, and has the same features, although they are implemented differently.


Summary


Debian is an extremely stable Linux distribution that includes a great variety of
software that runs in many different environments and on many different CPU
architectures. It is free, in the spirit of the Free Software Foundation's definition,
and thus may be run freely on as many systems as an administrator desires, without
limit or licensing fees. It may be freely copied, modified, and re-distributed. Debian
is available from many official Debian servers and mirrors, and it is well supported
by an official and well-defined, albeit all-volunteer organization, which provides
support via many channels. Paid installation media and support are also available
from many third parties.

Filesystem 

Types

Selecting a filesystem format is the next major choice before installing Debian. The
supported formats that are appropriate for a Linux installation include ext2, ext3,
ext4, JFS, XFS, ReiserFS, and Btrfs. The first three are actually progressive versions of
the extended filesystem (ext) developed specifically for Linux.

ext2, ext3, and ext4

The ext filesystem was originally developed to overcome the limitations of the
MINIX filesystem.
MINIX was Linus Torvalds' inspiration for Linux.
The second extended filesystem (ext2) improved upon it, while the third extended
filesystem (ext3) added journaling, as well as performance improvements. The fourth
extended filesystem (ext4) added additional features and performance improvements.
The ability to disable journaling is one reason ext2
was sometimes used over ext3 for flash drives in
order to reduce the write cycles.

Journaled File System


Developed by IBM for its Unix-like AIX operating system, and offered as an
alternative to the ext and ext2 filesystems via release under the GPL, Journaled File
System (JFS) is one of the alternatives to the current ext4. It uses fewer resources,
while remaining quite stable and resilient. It includes many features of Btrfs, and
is a good choice when CPU power is limited, or with database systems that require
synchronous writes to survive hardware failures.

Saturday, May 16, 2015

Authentication token manipulation error

  Authentication token manipulation error


[root@sysadmin Desktop]# pwconv
[root@sysadmin Desktop]# passwd demo
Changing password for user demo.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

Friday, May 15, 2015

Set Up a Virtual Host


1)Root login :-#ssh root@192.168.100.251
2)Create new user:- #adduser demo1
3)Change Password:- #passwd demo1
4)Change Root privileges:- visudo
       
        root    ALL=(ALL)       ALL
     demo1   ALL=(ALL)       ALL


5)su demo1 (Switch user)
6)sudo yum install httpd
7)sudo mkdir -p /var/www/server.lan/public_html
8)sudo chown -R apache:apache /var/www/server.lan/public_html
9)sudo chmod -R 777 /var/www
10)  create a new file called index.html within our configurations directory.

     sudo vi /var/www/server.lan/public_html/index.html

11)add below text to the file index.html

<html>
  <head>
    <title>www.server.lan</title>
  </head>
  <body>
    <h1>Success: You Have Set Up a Virtual Host</h1>
  </body>
</html>


----------------Turn on virtual Host:-

 12)    sudo vi /etc/httpd/conf/httpd.conf

   #Listen 12.34.56.78:80
   #////add hash on Listen 80 & add ip Listen 192.168.100.251:80
   # Listen 80
 Listen 192.168.100.251:80 

NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#   

#   
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
     ServerAdmin webmaster@server.lan
     DocumentRoot /var/www/server.lan/public_html
     ServerName www.server.lan
     ServerAlias server.lan
   #  ErrorLog /var/www/server.lan/error.log
    # CustomLog /var/www/server.lan/requests.log
</VirtualHost>

13)   #sudo systemctl stop httpd.service

14)   #sudo /etc/init.d/httpd start

15) sudo vim /etc/hosts

# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost

#Virtual Hosts
192.168.100.251    www.server.lan

16)check result

curl -I http://192.168.100.251

Wednesday, May 13, 2015

Install Samba to build a File Server

Install and Configure Samba.



  smbclient -L //localhost
1)
  mkdir /sambashare
  chmod 777 /sambashare
  ls -ltr /
  cd /sambashare/
   touch testfile1
   touch testfile2
  useradd lisa

2) 
  yum -y install samba samba-client
 
  cd /etc/samba/
 
  cp smb.conf smb.conf.backup

3)
  vim smb.conf
    workgroup = sambagroup
//copy last section para as it & modify it
        [sambashare]
       comment = my share
       path = /sambashare
       public = yes
       writable = yes
       write list = +users
4)
  service smb start

  service smb status
 
  smbpasswd -a lisa

5) 

  ls -ltr /sambashare/
  
  ls -Zd /sambashare/

6)  setenforce 0

how to test samba work
   smbclient -L //192.168.100.251 -U lisa
 
7) 
  mount  -o username=lisa //192.168.100.251/sambashare/ /mnt
   cd /mnt
   ls

8) access from windows

   \\192.168.100.251

///////////////////////////////////////////////////////////////////

  testparm



//////////////////////////////////////////////////////////////////
  
  [root@mydemovm home]# systemctl stop firewalld
[root@mydemovm home]# systemctl disable firewalld
 



////////////////////////////////////////////////////////////////////

 umount -l /mnt

 mount  -o username=lisa //192.168.100.251/sambashare/ /mnt

 umount -f /mnt

 ls -Zd /sambashare

  smbclient -L //192.168.100.251 -U lisa

 yum install cifs-utils -y

Sunday, May 10, 2015

Own Git server like github

Gitorious is an open source web interface to git that you can run on your own server, much like github:

http://getgitorious.com/

Update:
http://gitlab.org/ is another alternative now as well.

Update 2:
Gitorious has now joined with GitLab

The commercial service by GitHub starts at US$ 25 a month, ranging up to US$ 200 for the Platinum service, whereas Gitorious costs at least US$ 99 for your own sub-domain.


Fedora and Ubuntu include the two programs in their package repositories, which makes the install very easy.


 The basic requirements for setting up a Git server are a directory for the configuration and the repositories, a user account, and SSH keys needed to handle authentication. Access to Git repositories always relies on SSH, which means the Git servers don’t need a separate port. 




Thursday, May 7, 2015

Soft links hard links


1. What are links in Unix?
    A link in UNIX is a pointer to a file. Like pointers in any programming languages, links in UNIX are pointers pointing to a file or a directory . Creating links is a kind of shortcuts to access a file. The two different types of links in UNIX are:
  • Soft Links or Symbolic Links
  • Hard links

2. How to create Soft links and hard links? And how do we access them?
     Say, you have a file named "file1" with the following contents:
$ cat file1
welcome
.   To create a hard link of file1:
$ ln file1 file2
   To create a soft link of file1:
$ ln -s file1 file3 
    Once the links are created, the linked files contain the same content as of the original file. See below
$ cat file2
welcome
$ cat file3
welcome
Note: Soft links can be created on non-existent files as well.

3. "file2" and "file3" being the linked files, can I say which is a soft link & which is hard link?
   Yes. When you do the listing of the files with "-li" option:
$ ls -li
total 20
9962464 -rw-r--r-- 2 guru users 8 Mar  9  file1
9962464 -rw-r--r-- 2 guru users 8 Mar  9  file2
9962471 lrwxrwxrwx 1 guru users 5 Mar  9  file3 -> file1
   If you notice file3, it shows "->" towards file1. This indicates file3 is a soft-link of file1.  In case of file2, if you notice the inode numbers of file1 and file2, they are the same. Same inode number indicates file1 and file2 are hardlinks. Also note, the link count of these files is 2.

4. file1 and file2 are of the same size. In case of the file "file3", the file size is being shown as 5. How is it 5?
      The file size of a soft linked file is the length of the filename of the original file. In this case, the original file "file1" is of length 5. In a soft linked file, the location where the file content is to be stored, the file name of the original file gets stored, and hence the file size is so.

5. file1 and file2 are hardlinks? Can we say which is the original file and which is the hard-linked file?
    No. We cannot say which is the original file and which one was the hard-linked file. Once a hard-link is created, it is like 2 files pointing to the same location. In fact, once a hard link is created on a file, using the term 'original file' is actually incorrect.

6. Will deleting the file "file1" make "file2" and "file3" inaccessible?
   On deleting the file "file1", the soft linked file "file3" will become inaccessible. However, the hard linked file "file2" can still be accessed. - See more at: http://www.theunixschool.com/2012/03/soft-links-hard-links-all-about-inodes.html#sthash.JVsIPdJ1.dpuf
What are links in Unix?
    A link in UNIX is a pointer to a file. Like pointers in any programming languages, links in UNIX are pointers pointing to a file or a directory . Creating links is a kind of shortcuts to access a file. The two different types of links in UNIX are:
  • Soft Links or Symbolic Links
  • Hard links

2. How to create Soft links and hard links? And how do we access them?
     Say, you have a file named "file1" with the following contents:
$ cat file1
welcome
.   To create a hard link of file1:
$ ln file1 file2
   To create a soft link of file1:
$ ln -s file1 file3 
    Once the links are created, the linked files contain the same content as of the original file. See below
$ cat file2
welcome
$ cat file3
welcome
Note: Soft links can be created on non-existent files as well.

3. "file2" and "file3" being the linked files, can I say which is a soft link & which is hard link?
   Yes. When you do the listing of the files with "-li" option:
$ ls -li
total 20
9962464 -rw-r--r-- 2 guru users 8 Mar  9  file1
9962464 -rw-r--r-- 2 guru users 8 Mar  9  file2
9962471 lrwxrwxrwx 1 guru users 5 Mar  9  file3 -> file1
   If you notice file3, it shows "->" towards file1. This indicates file3 is a soft-link of file1.  In case of file2, if you notice the inode numbers of file1 and file2, they are the same. Same inode number indicates file1 and file2 are hardlinks. Also note, the link count of these files is 2.

4. file1 and file2 are of the same size. In case of the file "file3", the file size is being shown as 5. How is it 5?
      The file size of a soft linked file is the length of the filename of the original file. In this case, the original file "file1" is of length 5. In a soft linked file, the location where the file content is to be stored, the file name of the original file gets stored, and hence the file size is so.

5. file1 and file2 are hardlinks? Can we say which is the original file and which is the hard-linked file?
    No. We cannot say which is the original file and which one was the hard-linked file. Once a hard-link is created, it is like 2 files pointing to the same location. In fact, once a hard link is created on a file, using the term 'original file' is actually incorrect.

6. Will deleting the file "file1" make "file2" and "file3" inaccessible?
   On deleting the file "file1", the soft linked file "file3" will become inaccessible. However, the hard linked file "file2" can still be accessed. - See more at: http://www.theunixschool.com/2012/03/soft-links-hard-links-all-about-inodes.html#sthash.JVsIPdJ1.dpuf

   If you notice file3, it shows "->" towards file1. This indicates file3 is a soft-link of file1.  In case of file2, if you notice the inode numbers of file1 and file2, they are the same. Same inode number indicates file1 and file2 are hardlinks. Also note, the link count of these files is 2.

4. file1 and file2 are of the same size. In case of the file "file3", the file size is being shown as 5. How is it 5?
      The file size of a soft linked file is the length of the filename of the original file. In this case, the original file "file1" is of length 5. In a soft linked file, the location where the file content is to be stored, the file name of the original file gets stored, and hence the file size is so.

5. file1 and file2 are hardlinks? Can we say which is the original file and which is the hard-linked file?
    No. We cannot say which is the original file and which one was the hard-linked file. Once a hard-link is created, it is like 2 files pointing to the same location. In fact, once a hard link is created on a file, using the term 'original file' is actually incorrect.

6. Will deleting the file "file1" make "file2" and "file3" inaccessible?
   On deleting the file "file1", the soft linked file "file3" will become inaccessible. However, the hard linked file "file2" can still be accessed. - See more at: http://www.theunixschool.com/2012/03/soft-links-hard-links-all-about-inodes.html#sthash.JVsIPdJ1.dp
http://www.theunixschool.com/2012/03/soft-links-hard-links-all-about-inodes.html

How to find when my os was installed?

[root@sysadmin Desktop]# last |grep wtemp

[root@sysadmin Desktop]# last

 [root@sysadmin Desktop]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:    CentOS
Description:    CentOS Linux release 7.1.1503 (Core)
Release:    7.1.1503
Codename:    Core