Showing posts with label RHEL 7. Show all posts
Showing posts with label RHEL 7. Show all posts

Thursday, June 2, 2016

how to use systemctl command in RHEL7 and Centos 7 ?

systemctl command with all possible options rhel7 and centos7

systemctl is a command available in new version of Linux. Systemctl is used to control the systemd and service manager. To control services we have to use lot many options along with systemctl command. It is changed dramatically in new version of Linux. In this article we are going to explore as many possible ways as to use systemctl command in Linux.

Let’s start with checking the service status.

 Service Status Check and show service units
below is the command used to verify the service status
[root@Linuxforfreshers ~]# systemctl status network.service
network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network)
   Active: active (exited) since Thu 2016-04-28 13:39:38 IST; 32min ago
  Process: 5239 ExecReload=/etc/rc.d/init.d/network reload (code=killed, signal=TERM)
  Process: 5313 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)
[root@linuxforfreshers ~]# systemctl show crond.service
Id=crond.service
Names=crond.service
Requires=basic.target
Wants=system.slice
Conflicts=shutdown.target
Before=shutdown.target

Verify service is active and enabled

If service is active it means service is running without any issues.  As a example we verify web service is running OR not.
[root@Linuxforfreshers ~]# systemctl is-active httpd.service
active
Enabling service means we are ensuring that service should start when server is rebooted. In older versions chkconfig command.
[root@linuxforfreshers ~]# systemctl enable crond.service
[root@linuxforfreshers ~]# systemctl is-enabled crond.service
enabled
Start and restart service using systemctl
As simple as starting the services and restarting the services is very easy, Here we have little more than that in New version.
[root@linuxforfreshers ~]# systemctl start crond.service
[root@linuxforfreshers ~]# systemctl restart crond.service
as we say it is more than start and restart we have systemctl try-restart now your thinking about what is the difference between restart and try-restart..?
option restart will restart the service if it is in stopped state also.
option try-restart Restart one or more units specified on the command line if the units are running. This does nothing if units are not running. Note that, for compatibility with Red Hat init scripts, condrestart is equivalent to this command.
[root@linuxforfreshers ~]# systemctl try-restart crond.service

 Listing dependencies, jobs, sockets, unit-files and Units
Listing dependencies means what are the services we have to start before starting this required service this before version this feature was not there.
Shows required and wanted units of the specified unit. If no unit is specified, default.target is implied. Target units are recursively expanded. When –all is passed, all other units are recursively expanded as well
[root@linuxforfreshers ~]# systemctl list-dependencies crond.service
crond.service
system.slice
└─basic.target
alsa-restore.service
alsa-state.service
firewalld.service
microcode.service
rhel-autorelabel-mark.service
rhel-autorelabel.service
rhel-configure.service
rhel-dmesg.service
rhel-loadmodules.service
paths.target
slices.target
list-jobs will show what are jobs running currently in background
[root@linuxforfreshers ~]# systemctl list-jobs
No jobs running.
Listing installed unit files
[root@linuxforfreshers ~]# systemctl list-unit-files |grep sshd
anaconda-sshd.service static
sshd-keygen.service static
sshd.service enabled
sshd@.service static
sshd.socket disabled
List all available sockets
[root@linuxforfreshers ~]# systemctl list-sockets
LISTEN UNIT ACTIVATES
/dev/initctl systemd-initctl.socket systemd-initctl.service
/dev/log systemd-journald.socket systemd-journald.service
/run/dmeventd-client dm-event.socket dm-event.service
/run/dmeventd-linuxforfreshers dm-event.socket dm-event.service
/run/lvm/lvmetad.socket lvm2-lvmetad.socket lvm2-lvmetad.service
/run/systemd/journal/socket systemd-journald.socket systemd-journald.service
/run/systemd/journal/stdout systemd-journald.socket systemd-journald.service
/run/systemd/shutdownd systemd-shutdownd.socket systemd-shutdownd.service
/run/udev/control systemd-udevd-control.socket systemd-udevd.service
/var/run/avahi-daemon/socket avahi-daemon.socket avahi-daemon.service
/var/run/cups/cups.sock cups.socket cups.service
/var/run/dbus/system_bus_socket dbus.socket dbus.service
/var/run/rpcbind.sock rpcbind.socket rpcbind.service
@ISCSIADM_ABSTRACT_NAMESPACE iscsid.socket iscsid.service
@ISCSID_UIP_ABSTRACT_NAMESPACE iscsiuio.socket iscsiuio.service
kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
16 sockets listed.
Pass --all to see loaded but inactive sockets, too.
Note: because the addresses might contains spaces, this output is not suitable for programmatic consumption.
[root@linuxforfreshers ~]# systemctl list-sockets --show-types
LISTEN TYPE UNIT ACTIVATES
/dev/initctl FIFO systemd-initctl.socket systemd-initctl.service
/dev/log Datagram systemd-journald.socket systemd-journald.service
/run/dmeventd-client FIFO dm-event.socket dm-event.service
/run/dmeventd-linuxforfreshers FIFO dm-event.socket dm-event.service
/run/lvm/lvmetad.socket Stream lvm2-lvmetad.socket lvm2-lvmetad.service
/run/systemd/journal/socket Datagram systemd-journald.socket systemd-journald.service
/run/systemd/journal/stdout Stream systemd-journald.socket systemd-journald.service
/run/systemd/shutdownd Datagram systemd-shutdownd.socket systemd-shutdownd.service
/run/udev/control SequentialPacket systemd-udevd-control.socket systemd-udevd.service
/var/run/avahi-daemon/socket Stream avahi-daemon.socket avahi-daemon.service
/var/run/cups/cups.sock Stream cups.socket cups.service
/var/run/dbus/system_bus_socket Stream dbus.socket dbus.service
/var/run/rpcbind.sock Stream rpcbind.socket rpcbind.service
@ISCSIADM_ABSTRACT_NAMESPACE Stream iscsid.socket iscsid.service
@ISCSID_UIP_ABSTRACT_NAMESPACE Stream iscsiuio.socket iscsiuio.service
kobject-uevent 1 Netlink systemd-udevd-kernel.socket systemd-udevd.service
16 sockets listed.
Pass --all to see loaded but inactive sockets, too.
[root@linuxforfreshers ~]# systemctl list-sockets --failed
0 sockets listed.
Pass --all to see loaded but inactive sockets, too.

Setting up default target (Older version Run Level) and getting default target
We have to use set-default to set default run level and we can see default run level using get-default option as shown below example
[root@linuxforfreshers ~]# systemctl set-default multi-user.target
rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target'
[root@linuxforfreshers ~]# systemctl get-default
multi-user.target

Masking service ans unmasking service
What is mean by masking service, there is situation that company will have multiple administrators working together still there are times one administrator will stop the service which is not required but another administrator will start the same service unfortunately Or unknowingly , will lead to lot of problems to avoid this types of situations. We have to disable, stop the service and mask it, when other administrator try to start also the service will never start until unless explicitly unmask.
[root@linuxforfreshers ~]# systemctl disable crond.service
rm '/etc/systemd/system/multi-user.target.wants/crond.service'
[root@linuxforfreshers ~]# systemctl stop crond.service
[root@linuxforfreshers ~]# systemctl mask crond.service
ln -s '/dev/null' '/etc/systemd/system/crond.service'
[root@linuxforfreshers ~]# systemctl status crond.service
crond.service
Loaded: masked (/dev/null)
 Active: inactive (dead)
As shown in above command examples we have stopped the service, disabled the service and masked the service. Now try to start the service.
[root@linuxforfreshers ~]# systemctl start crond.service
Failed to issue method call: Unit crond.service is masked.
now unmask the service and start it will start
[root@linuxforfreshers ~]# systemctl unmask crond.service
rm '/etc/systemd/system/crond.service'
[root@linuxforfreshers ~]# systemctl start crond.service
[root@linuxforfreshers ~]# systemctl status crond.service
crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; disabled)
Active: active (running) since Thu 2016-04-28 22:45:12 IST; 9s ago
Main PID: 7521 (crond)
CGroup: /system.slice/crond.service
└─7521 /usr/sbin/crond -n

Reload and reset service status
Most of the administrator will still have an question that what is the difference between service reload and restart.
Service reload is used whenever we changed something to the service and we would like to push the changes to the service without interrupting the connected users. Reloading the service will never change existing PID (Process Identity)
Service restart is used to restart the service which means stop and start the service, whenever we run restart existing users will disconnect and new PID will be created. It required little downtime to the service changes.
Before reloading the service status
[root@linuxforfreshers ~]# systemctl status sshd.service
sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
Active: active (running) since Thu 2016-04-28 05:56:52 IST; 16h ago
Process: 7228 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 1601 (sshd)
CGroup: /system.slice/sshd.service
└─1601 /usr/sbin/sshd -D

After reloading the service

[root@linuxforfreshers ~]# systemctl reload sshd.service
[root@linuxforfreshers ~]# systemctl status sshd.service
sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
Active: active (running) since Thu 2016-04-28 05:56:52 IST; 16h ago
Process: 7243 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 1601 (sshd)
CGroup: /system.slice/sshd.service
└─1601 /usr/sbin/sshd -D
if observe correctly PID before and after reload not changed.
Reset the “failed” state of the specified units

[root@linuxforfreshers ~]# systemctl reset-failed sshd.service

 Daemon reload option
After deleting the file or directory, you should reload the systemd process so that it no longer attempts to reference these files and reverts back to using the system copies. You can do this by typing:
[root@linuxforfreshers ~]# systemctl daemon-reload

Isolating Targets using systemctl command
It is possible to start all of the units associated with a target and stop all units that are not part of the dependency tree. The command that we need to do this is called, appropriately, isolate. This is similar to changing the runlevel in other init systems.

For instance, if you are operating in a graphical environment with graphical.target active, you can shut down the graphical system and put the system into a multi-user command line state by isolating the multi-user.target. Since graphical.target depends on multi-user.target but not the other way around, all of the graphical units will be stopped.

You may wish to take a look at the dependencies of the target you are isolating before performing this procedure to ensure that you are not stopping vital services:

systemctl list-dependencies multi-user.target

When you are satisfied with the units that will be kept alive, you can isolate the target by typing:
systemctl isolate multi-user.target

Create service snapshot and delete
Create a snapshot. If a snapshot name is specified, the new snapshot will be named after it. If none is specified, an automatic snapshot name is generated. In either case, the snapshot name used is printed to STDOUT, unless –quiet is specified.

A snapshot refers to a saved state of the systemd manager. It is implemented itself as a unit that is generated dynamically with this command and has dependencies on all units active at the time. At a later time, the user may return to this state by using the isolate command on the snapshot unit.
Snapshots are only useful for saving and restoring which units are running or are stopped, they do not save/restore any other state. Snapshots are dynamic and lost on reboot.

[root@linuxforfreshers ~]# systemctl snapshot sshd.service
sshd.service.snapshot
[root@linuxforfreshers ~]# systemctl status sshd.service.snapshot
sshd.service.snapshot
Loaded: loaded
Active: inactive (dead)
[root@linuxforfreshers ~]# systemctl delete sshd.service.snapshot
[root@linuxforfreshers ~]# systemctl status sshd.service.snapshot
sshd.service.snapshot
Loaded: not-found (Reason: No such file or directory)

Active: inactive (dead)

Saturday, December 12, 2015

how to assign network setting in rhel 7 using nmtui and nmcli ?

How to assign network in RHEL 7?


networking two ways

lagacy
network manager

networkmanager
--------------

rpm -qa | grep -i Networkmanager

systemctl status NetworkManager

There are  three  different ways assign network settings

GUI ----->Graphical
text ... nmtui   --->Text based
cli .... nmcli    ----> Command line



Using lagacy network service
----------------------

planing to add manually values for eth0

vim /etc/sysconfig/netwok-scripts/ifcfg-eth0

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp

for static

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none   or static
IPADDR=172.25.X.11
PREFIX=24  or  NETMASK=255.255.255.0
GATEWAY=172.25.X.254
DNS1=172.25.254.254

:wq
sytemctl restart NetworkManager

To assign  system name (hostname)
Using command line

hostnamectl set-hostname serverx.example.com

or

vim /etc/hostname
serverx.example.com

before rhel7 .....to set hostname

vim /etc/sysconfig/network
HOSTNAME=serverx.example.com


updating name server info

vim /etc/resolv.conf
nameserver 8.8.8.8

or local dns 172.25.254.254


local name mapping
------------------
if u have to systems .... call with nicknames ...alias name user /etc/hosts
give ip call that system with name  ( nss switch will manage this proccess)
ex:-  172.25.x.11 system1
     172.25.x.10 system2

vim /etc/hosts

172.25.x.11 system1
172.25.x.10 system2
:wq






using nmtui

nmtui stands for Network Manager Text User Interface.
nmtui is actually a very easy text based tool to configure IP address and host names. Just type “nmtui” on command prompt and follow the simple steps

Now choose your connection type after selecting “Edit a connection”. I am choosing ethernet as I don’t have any other connection to my virtual machine.








As I showing here in rhel7 configuring IP addresses. So I had selected “edit” to manually set the ip address





Now after selecting “manual” you can configure ip addresses as per your specifications.

After you press “OK” to come out of this window. Don’t forget to activate the network connection again.



Once you are done with the nmtui tool in rhel7 configuring IP addresses.  You can check using ‘ifconfig or ip a or hostname –i.



Using  nmcli (Network Manager Command Line Interface )

show the connections using

nmcli connection show
nmcli connection show eno1

Configure an IP address
nmcli connection modify eno1 ipv4.addresses 192.168.0.5/24

Configure an IP address with default gateway
nmcli connection modify eno1 ipv4.addresses 192.168.0.5/24 \  ipv4.gateway 192.168.0.1 ipv4.never-default no

Configure an additional IP address
nmcli connection modify eno1 +ipv4.addresses 192.168.0.6

Add a static route
These will be saved in the route-<interface> file in /etc/sysconfig/network-scripts/ :


nmcli connection modify eno1 +ipv4.routes '192.168.111.0/24 192.168.99.1'

Wednesday, November 18, 2015

what is the difference between rhel 6 and rhel 7 ?

Features
RHEL 7
RHEL 6
Default File System
XFS
EXT4
Kernel Version
3.10.x-x kernel
2.6.x-x Kernel
Kernel Code Name
Maipo
Santiago
General Availability Date of First Major Release
2014-06-09 (Kernel Version 3.10.0-123)
2010-11-09 (Kernel Version 2.6.32-71)
First Process
systemd (process ID 1)
init (process ID 1)
Runlevel
runlevels are called as "targets" as shown below:

runlevel0.target -> poweroff.target
runlevel1.target -> rescue.target
runlevel2.target -> multi-user.target
runlevel3.target -> multi-user.target
runlevel4.target -> multi-user.target
runlevel5.target -> graphical.target
runlevel6.target -> reboot.target

/etc/systemd/system/default.target (this by default is linked to the multi-user target)
Traditional runlevels defined :

runlevel 0
runlevel 1
runlevel 2
runlevel 3
runlevel 4
runlevel 5
runlevel 6

and the default runlevel would be defined in /etc/inittab file.
/etc/inittab
Host Name Change
In Red Hat Enterprise Linux 7, as part of the move to the new init system (systemd), the hostname variable is defined in /etc/hostname.
In Red Hat Enterprise Linux 6, the hostname variable was defined in the /etc/sysconfig/network configuration file.
Change In UID Allocation
By default any new users created would get UIDs assigned starting from 1000.

This could be changed in /etc/login.defs if required.
Default UID assigned to users would start from 500.


This could be changed in /etc/login.defs if required.
Max Supported File Size
Maximum (individual) file size = 500TB
Maximum filesystem size = 500TB

(This maximum file size is only on 64-bit machines. Red Hat Enterprise Linux does not support XFS on 32-bit machines.)
Maximum (individual) file size = 16TB
Maximum filesystem size = 16TB

(This maximum file size is based on a 64-bit machine. On a 32-bit machine, the maximum files size is 8TB.)
File System Check
"xfs_repair"

XFS does not run a file system check at boot time.
"e2fsck"

File system check would gets executed at boot time.
Differences Between xfs_repair & e2fsck

"xfs_repair"

- Inode and inode blockmap (addressing) checks.
- Inode allocation map checks.
- Inode size checks.
- Directory checks.
- Pathname checks.
- Link count checks.
- Freemap checks.
- Super block checks.

"e2fsck"

- Inode, block, and size checks.

- Directory structure checks.

- Directory connectivity checks.

- Reference count checks.

- Group summary info checks.
Difference Between xfs_growfs & resize2fs
"xfs_growfs"

xfs_growfs takes mount point as arguments.
"resize2fs"

resize2fs takes logical volume name as arguments.
Change In File System Structure
/bin, /sbin, /lib, and /lib64 are now nested under /usr.
/bin, /sbin, /lib, and /lib64 are usually under /
Boot Loader
GRUB 2
Supports GPT, additional firmware types, including BIOS, EFI and OpenFirmwar. Ability to boot on various file systems (xfs, ext4, ntfs, hfs+, raid, etc)
GRUB 0.97
KDUMP
RHEL7 supports kdump on large memory based systems up to 3 TB
Kdump doesn’t work properly with large RAM based systems.
System & Service Manager
"Systemd"

systemd is a system and service manager for Linux, and replaces SysV and Upstart used in previous releases of Red Hat Enterprise Linux. systemd is compatible with SysV and Linux Standard Base init scripts.
Upstart
Enable/Start Service
For RHEL 7, the systemctl command replaces service and chkconfig.

- Start Service : "systemctl start nfs-server.service".

- Enable Service : To enable the service (example: nfs service ) to start automatically on boot : "systemctl enable nfs-server.service".

Although one can still use the service and chkconfig commands to start/stop and enable/disable services, respectively, they
are not 100% compatible with the RHEL 7 systemctl command (according to redhat).
Using "service" command and "chkconfig" commands.

- Start Service : "service start nfs" OR "/etc/init.d/nfs start"

- Enable Service : To start with specific runlevel : "chkconfig --level 3 5 nfs on"
Default Firewall
"Firewalld (Dynamic Firewall)"

The built-in configuration is located under the /usr/lib/firewalld directory. The configuration that you can customize is under the /etc/firewalld directory. It is not possible to use Firewalld and Iptables at the same time. But it is still possible to disable Firewalld and use Iptables as before.
Iptables
Network Bonding
"Team Driver"

-/etc/sysconfig/network-scripts/ifcfg-team0
- DEVICE=”team0”
- DEVICETYPE=”Team”
"Bonding"

-/etc/sysconfig/network-scripts/ifcfg-bond0
- DEVICE=”bond0”
Network Time Synchronization
Using Chrony suite (faster time sync compared with ntpd)
Using ntpd
NFS
NFS4.1
NFSv2 is no longer supported. Red Hat Enterprise Linux 7 supports NFSv3, NFSv4.0, and NVSv4.1 clients.
NFS4
Cluster Resource Manager
Pacemaker
Rgmanager
Load Balancer Technology
Keepalived and HAProxy
Piranha
Desktop/GUI Interface
GNOME3 and KDE 4.10
GNOME2
Default Database
MariaDB is the default implementation of MySQL in Red Hat Enterprise Linux 7
MySQL
Managing Temporary Files
RHEL 7 uses systemd-tmpfiles (more structured, and configurable, method to manage tmp files and directories).
Using "tmpwatch"