This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Thursday, April 5, 2018

How to use --exclude option in du command

Thursday, April 05, 2018 0
du command is used to estimate file space usage.

Sometime we need to exclude some folder or files while running du command.
For that we can use below option to achieve that.

[root@testserver /]# du -sh * --exclude=repository --exclude=oem1

The above command will exclude the repository & oem folder  under / path.

Hope it helps.

Sunday, March 18, 2018

How to Add SSH Public Key to Remote Server(s) in a Single Command.

Sunday, March 18, 2018 0
Below command is used to copy the key to single server.

# cat id_rsa.pub | ssh username@servername 'cat >> /home/user/.ssh/authorized_keys'

Below command is used to copy the key to multiple server. We can use for loop.

# for i in  `cat serverlist`; do echo $i; cat id_rsa.pub |
ssh username@servername 'cat >> /home/user/.ssh/authorized_keys'; done

Hope it helps.

Wednesday, February 28, 2018

How to kill the IDLE pts/tty session in Linux Server?

Wednesday, February 28, 2018 0
 Kill the IDLE pts/tty session in Linux Server

Situation:
    Sometime script command may not be completed properly or sometime improperly closed ssh session makes the idle pts/tty session.
           
[root@dbserver ~]# w
 14:18:28 up 31 days,  4:18,  4 users,  load average: 3.35, 3.42, 3.41
USER     TTY      FROM  LOGIN@   IDLE     JCPU   PCPU  WHAT
root        pts/2    -            27Jan18   31days  0.00s  0.00s   script -a /os_backup_fs/patches/DB_Server/logs/dbserver_Postwork-1.log


Solution:
Here, sometime ps -ft command will not respond

[root@dbserver ~]# ps -ft pts/2
UID         PID   PPID  C STIME TTY          TIME CMD

So, search with process and kill the process id.

[root@dbserver ~]# ps -ef | grep -i /os_backup_fs/patches/DB_Server/logs/dbserver_Postwork-1.log
root     202948 185999  0 14:18 pts/4    00:00:00 grep -i /os_backup_fs/patches/DB_Server/logs/dbserver_Postwork-1.log
root     271243 113886  0 Jan27 pts/1    00:00:00 script -a /os_backup_fs/patches/DB_Server/logs/dbserver_Postwork-1.log
root     271245 271243  0 Jan27 pts/1    00:00:00 script -a /os_backup_fs/patches/DB_Server/logs/dbserver_Postwork-1.log
[root@dbserver ~]# kill -9 271243

Hope it helps.

Monday, February 26, 2018

How to create VLAN interface by using comand line in RHEL7

Monday, February 26, 2018 0
By using nmcli command we can craete the VLAN interface in RHEL7.

VLANs are isolated broadcast domains that run over a single physical network. They allow you to segment a local network and also to "stretch" a LAN over multiple physical locations. Most enterprises implement this on their network switching environment, but in some cases, the tagged VLANs reach your server.

For this case, our physical network interface is called enp0s3. The VLAN's ID is 501, and the IPv4 address is 192.168.1.10, with a subnet mask of 255.255.255.0 and a default gateway of 192.168.1.1.

Create vlan
[root@nsk ~]# nmcli connection add type vlan dev enp0s3 id 501 ip4 192.168.1.10/24 gw4 192.168.1.1
Connection 'vlan' (a01bd6a3-a486-4c5b-83af-73d7344cc388) successfully added.

Activate the connection
[root@nsk ~]# nmcli connection up vlan
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

Check the Connection
[root@nsk ~]# nmcli connection show
NAME     UUID                                                                 TYPE                   DEVICE
enp0s3  191fbaab-7ac3-4616-9368-3b006cba3574      802-3-ethernet     enp0s3
vlan        a01bd6a3-a486-4c5b-83af-73d7344cc388      vlan                      enp0s3.501

[root@nsk ~]# nmcli device status
DEVICE          TYPE           STATE         CONNECTION
enp0s3          ethernet       connected    enp0s3
enp0s3.501   vlan              connected    vlan
lo                  loopback       unmanaged   --

[root@nsk ~]# nmcli device show enp0s3.501
GENERAL.DEVICE                   :    enp0s3.501
GENERAL.TYPE                      :      vlan
GENERAL.HWADDR                :     08:00:27:93:16:4B
GENERAL.MTU                        :    1500
GENERAL.STATE                    :    100 (connected)
GENERAL.CONNECTION        :   vlan
GENERAL.CON-PATH             :    /org/freedesktop/NetworkManager/ActiveConnection/3
IP4.ADDRESS[1]                     :      192.168.1.10/24
IP4.GATEWAY                         :      192.168.1.1
IP6.ADDRESS[1]                     :       fe80::ecb7:3969:728f:a67b/64
IP6.GATEWAY                         :       --
[root@nsk ~]#

The command line to create a VLAN with nmcli is very basic as it uses default values.

Below command will full option to create detailed VLAN interface.
[root@nsk ~]# nmcli con add help

Saturday, February 17, 2018

How to change the Linux user's password in single command

Saturday, February 17, 2018 0
Changing the Linux user's password in one command

Chpasswd reads a list of user name and password pairs from standard input and uses this information to update a group of existing users

chpasswd - update passwords in batch mode

Syntax    -  user_name:password

 By default the supplied password must be in clear-text. Also the password age will be updated, if present.

#echo user:password | /usr/sbin/chpasswd

Friday, February 16, 2018

Default Physical extent size in RHEL5, RHEL6 and RHEL7

Friday, February 16, 2018 0
Default Physical extent size in RHEL5, RHEL6 and RHEL7

Each physical volume is divided chunks of data, known as physical extents, these extents have the same size as the logical extents for the volume group.

Making the PE too small wouldn't be recommended, as the maximum volume size is 65,536 PEs, so if you reduce this to 1MB, you end up with volumes not larger than 64GB.

RHEL 5 - 32 M
RHEL 6 - 4 MB  (maximum we can create 256 GB file system)
RHEL 7 - 4 MB

Thursday, February 15, 2018

Working with Docker Container - Labeling and filtering containers

Thursday, February 15, 2018 0
Labeling and filtering containers

With Docker 1.6, a feature has been added to label containers and images, through which we can attach arbitrary key-value metadata to them. You can think of them as environment variables, which are not available to running applications inside containers but they are available to programs (Docker CLI) that are managing images and containers. Labels attached to images also get applied to containers started via them. We can also attach labels to containers while starting them.

Docker also provides filters to containers, images, and events, which we can use in conjunction with labels to narrow down our searches.

For this document, let's assume that we have an image with the label, distro=centos.

root@Docker:~# docker images
REPOSITORY                 TAG                 IMAGE ID                CREATED            SIZE
nskselvan/nsk                   latest              b2f0c17eed23        2 months ago        197MB
centos-latest                     latest              2083898799b1       2 months ago        197MB
wordpress                         latest              224b7eef6944        3 months ago        408MB
mysql                                 5.7                 b4e78b89bcf3        3 months ago        412MB
registry                               2                    28525f9a6e46       3 months ago        33.2MB
localhost:5000/reg            latest               28525f9a6e46       3 months ago        33.2MB
centos                               latest              196e0ce0c9fb        3 months ago        197MB
localhost:5000/centos-ka  latest              196e0ce0c9fb        3 months ago        197MB

As you can see from the preceding screenshot, if we use filters with the docker images command, we only get an image where the corresponding label is found in the image's metadata.

To start the container with the --label/-l option, run the following command:
root@Docker:~# docker run --label environment=test centos date
Thu Feb 15 06:21:09 UTC 2018

Let's start a container without a label and start two others with the same label:
root@Docker:~# docker run --name container1 centos date
Thu Feb 15 06:22:13 UTC 2018
root@Docker:~# docker run --name tcontainer1 --label environment=test centos date
Thu Feb 15 06:23:01 UTC 2018
root@Docker:~# docker run --name tcontainer2 --label environment=test centos date
Thu Feb 15 06:23:20 UTC 2018

If we list all the containers without a label, we will see all the containers, but if we use label, then we get only containers, which matches the label.




Docker attaches label metadata to containers while starting them and matches the label while listing them or other related operations
We can list all the labels attached to a container through the inspect command

root@Docker:~# docker inspect -f '{{.Config.Labels}}' tcontainer1
map[build-date:20170911 environment:test license:GPLv2 name:CentOS Base Image vendor:CentOS]
root@Docker:~# docker inspect -f '{{.Config.Labels}}' tcontainer2
map[license:GPLv2 name:CentOS Base Image vendor:CentOS build-date:20170911 environment:test]

Wednesday, February 14, 2018

Working with Docker Container - Docker info Command

Wednesday, February 14, 2018 0
Docker info Command

As we know, images are required to run containers. You can either use existing images or create new custom images. You will need to create custom images to suit your development and deployment environment. Once you create an image, you can share it through the public or private registry. Before we explore more about Docker images, let's look at the output of the docker info command:

root@Docker:~# docker info
Containers: 26
 Running: 5
 Paused: 0
 Stopped: 21
Images: 6
Server Version: 17.09.0-ce
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 87
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.4.0-96-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.859GiB
Name: Docker
ID: S3LP:G73H:NJWO:SVEG:I7U5:UB5M:B3LC:WAQV:AINP:7YYE:I7EN:MRFF
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: nskselvan
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support
root@Docker:~#

The preceding command gives the current system-wide info as follows:

It has 26 containers and 6 images.


The current storage driver, devicemapper, and its related information, such as thin pool name, data, metadata file, and so on. Other types of storage drivers are aufs, btrfs, overlayfs, vfs, and so on. Devicemapper, btrfs, and overlayfs have native support in the Linux kernel. AUFS support needs a patched kernel. 


To leverage the kernel features that enable containerization, the Docker daemon has to talk to the Linux kernel. This is done through the execution driver. libconatiner or native is one of that type. The others are libvirt, lxc, and so on.


The kernel version on the host operating system.
The user account that is registered on the registry mentioned in the next section to pull/push images.