6 WC Command Examples to Count Number of Lines, Words, Characters in Linux

The wc (word count) command in Unix/Linux operating systems is used to find out number of newline countword countbyte and characters count in a files specified by the file arguments. The syntax of wc command as shown below.

# wc [options] filenames

The following are the options and usage provided by the command.

wc -l : Prints the number of lines in a file.
wc -w : prints the number of words in a file.
wc -c : Displays the count of bytes in a file.
wc -m : prints the count of characters from a file.
wc -L : prints only the length of the longest line in a file.

So, let’s see how we can use the ‘wc‘ command with their few available arguments and examples in this article. We have used the ‘tecmint.txt‘ file for testing the commands. Let’s find out the output of the file using cat command as shown below.

[root@tecmint ~]# cat tecmint.txt

Red Hat
CentOS
Fedora
Debian
Scientific Linux
OpenSuse
Ubuntu
Xubuntu
Linux Mint
Pearl Linux
Slackware
Mandriva

1. A Basic Example of WC Command

The ‘wc‘ command without passing any parameter will display a basic result of ”tecmint.txt‘ file. The three numbers shown below are 12 (number of lines), 16 (number of words) and 112 (number of bytes) of the file.

[root@tecmint ~]# wc tecmint.txt

12  16 112 tecmint.txt

2. Count Number of Lines

To count number of newlines in a file use the option ‘-l‘, which prints the number of lines from a given file. Say, the following command will display the count of newlines in a file. In the output the first filed assigned as count and second field is the name of file.

[root@tecmint ~]# wc -l tecmint.txt

12 tecmint.txt

3. Display Number of Words

Using ‘-w‘ argument with ‘wc‘ command prints the number of words in a file. Type the following command to count the words in a file.

[root@tecmint ~]# wc -w tecmint.txt

16 tecmint.txt

4. Count Number of Bytes and Characters

When using options ‘-c‘ and ‘-m‘ with ‘wc‘ command will print the total number of bytes and charactersrespectively in a file.

[root@tecmint ~]# wc -c tecmint.txt

112 tecmint.txt
[root@tecmint ~]# wc -m tecmint.txt

112 tecmint.txt

5. Display Length of Longest Line

The ‘wc‘ command allow an argument ‘-L‘, it can be used to print out the length of longest (number of characters) line in a file. So, we have the longest character line (‘Scientific Linux‘) in a file.

[root@tecmint ~]# wc -L tecmint.txt

16 tecmint.txt

6. Check More WC Options

For more information and help on the wc command, simple run the ‘wc –help‘ or ‘man wc‘ from the command line.

[root@tecmint ~]# wc --help

Usage: wc [OPTION]... [FILE]...
  or:  wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.  With no FILE, or when FILE is -,
read standard input.
  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
  -L, --max-line-length  print the length of the longest line
  -w, --words            print the word counts
      --help			display this help and exit
      --version			output version information and exit

Report wc bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'wc invocation'

Source

How to Setup DHCP Server and Client on CentOS and Ubuntu

DHCP (short for Dynamic Host Configuration Protocol) is a client/server protocol that enables a server to automatically assign an IP address and other related configuration parameters (such as the subnet mask and default gateway) to a client on a network.

DHCP is important because it prevents a system or network administrator from manually configuring IP addresses for new computers added to the network or computers that are moved from one subnet to another.

The IP address assigned by a DHCP server to a DHCP client is on a “lease”, the lease time normally varies depending on how long a client computer is likely to require the connection or the DHCP configuration.

In this article, we will explain how to configure a DHCP server in CentOS and Ubuntu Linux distributions to assign IP address automatically to a client machine.

Installing DHCP Server in CentOS and Ubuntu

The DCHP server package is available in the official repositories of mainstream Linux distributions, installing is quite easy, simply run the following command.

# yum install dhcp		        #CentOS
$ sudo apt install isc-dhcp-server	#Ubuntu

Once the installation is complete, configure the interface on which you want the DHCP daemon to serve requests in the configuration file /etc/default/isc-dhcp-server or /etc/sysconfig/dhcpd.

# vim /etc/sysconfig/dhcpd		 #CentOS
$ sudo vim /etc/default/isc-dhcp-server	 #Ubuntu

For example, if you want the DHCPD daemon to listen on eth0, set it using the following directive.

DHCPDARGS=”eth0”

Save the file and exit.

Configuring DHCP Server in CentOS and Ubuntu

The main DHCP configuration file is located at /etc/dhcp/dhcpd.conf, which should contain settings of what to do, where to do something and all network parameters to provide to the clients.

This file basically consists of a list of statements grouped into two broad categories:

  • Global parameters: specify how to carry out a task, whether to carry out a task, or what network configuration parameters to provide to the DHCP client.
  • Declarations: define the network topology, state a clients is in, offer addresses for the clients, or apply a group of parameters to a group of declarations.

Now, open and edit the configuration file to configure your DHCP server.

------------ On CentOS ------------ 
# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf	
# vi /etc/dhcp/dhcpd.conf	

------------ On Ubuntu ------------
$ sudo vim /etc/dhcp/dhcpd.conf				

Start by defining the global parameters which are common to all supported networks, at the top of the file. They will apply to all the declarations:

option domain-name "tecmint.lan";
option domain-name-servers ns1.tecmint.lan, ns2.tecmint.lan;
default-lease-time 3600; 
max-lease-time 7200;
authoritative;

Next, you need to define a sub-network for an internal subnet i.e 192.168.1.0/24 as shown.

subnet 192.168.1.0 netmask 255.255.255.0 {
        option routers                  192.168.1.1;
        option subnet-mask              255.255.255.0;
        option domain-search            "tecmint.lan";
        option domain-name-servers      192.168.1.1;
        range   192.168.10.10   192.168.10.100;
        range   192.168.10.110   192.168.10.200;
}

Note that hosts which require special configuration options can be listed in host statements (see the dhcpd.conf man page).

Now that you have configured your DHCP server daemon, you need to start the service for the mean time and enable it to start automatically from the next system boot, and check if its up and running using following commands.

------------ On CentOS ------------ 
# systemctl start dhcpd
# systemctl enable dhcpd
# systemctl enable dhcpd

------------ On Ubuntu ------------
$ sudo systemctl start isc-dhcp-server
$ sudo systemctl enable isc-dhcp-server
$ sudo systemctl enable isc-dhcp-server

Next, permit requests to the DHCP daemon on Firewall, which listens on port 67/UDP, by running.

------------ On CentOS ------------ 
# firewall-cmd --zone=public --permanent --add-service=dhcp
# firewall-cmd --reload 

#------------ On Ubuntu ------------
$ sudo ufw allow 67/udp
$ sudo ufw reload

Configuring DHCP Clients

Finally, you need to test if the DHCP server is working fine. Logon to a few client machines on the network and configure them to automatically receive IP addresses from the server.

Modify the appropriate configuration file for the interface on which the clients will auto-receive IP addresses.

DHCP Client Setup on CentOS

On CentOS, the interface config files ate located at /etc/sysconfig/network-scripts/.

# vim /etc/sysconfig/network-scripts/ifcfg-eth0

Add the options below:

DEVICE=eth0
BOOTPROTO=dhcp
TYPE=Ethernet
ONBOOT=yes

Save the file and restart network service (or reboot the system).

# systemctl restart network

DHCP Client Setup on Ubuntu

On Ubuntu 16.04, you can configure all interface in the config file /etc/network/interfaces.

   
$ sudo vi /etc/network/interfaces

Add these lines in it:

auto  eth0
iface eth0 inet dhcp

Save the file and restart network services (or reboot the system).

$ sudo systemctl restart networking

On Ubuntu 18.04, networking is controlled by the Netplan program. You need to edit the appropriate file under the directory /etc/netplan/, for example.

$ sudo vim /etc/netplan/01-netcfg.yaml 

Then enable dhcp4 under a specific interface for example under ethernetsens0, and comment out static IP related configs:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens0:
      dhcp4: yes

Save the changes and run the following command to effect the changes.

$ sudo netplan apply 

For more information, see the dhcpd and dhcpd.conf man pages.

$ man dhcpd
$ man dhcpd.conf

In this article, we have explained how to configure a DHCP server in CentOS and Ubuntu Linux distributions. If you need more clarification on any point, you can ask a question via the feedback form below, or simply share your comments with us.

Source

Installing ProFTPD Server on RHEL/CentOS 7

ProFTPD is an Open Source FTP Server and one of the most used, secure and reliable file transfer daemons on Unix environments, due to its file configurations simplicity speed and easy setup.

Install Proftpd In CentOS 7

Install Proftpd In RHEL/CentOS 7

Requirements

  1. CentOS 7 Minimal Installation
  2. Red Hat Enterprise Linux 7 Installation
  3. Configure Static IP Address on System

This tutorial will guide you on how you can install and use ProFTPD Server on CentOS/RHEL 7 Linux distributions for a simple file transfer from your local system accounts to remote systems.

Step 1: Install Proftpd Server

1. Official RHEL/CentOS 7 repositories doesn’t provide any binary package for ProFTPD Server, so you need to add extra package repositories on your system provided by EPEL 7 Repo, using the following command.

# rpm -Uvh http://ftp.astral.ro/mirrors/fedora/pub/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm

Install EPEL in CentOS 7

Install EPEL in RHEL/CentOS 7

2. Before you start installing ProFTPD Server, edit your machine hosts file, change it accordingly to your system FQDN and test the configurations to reflect your system domain naming.

# nano /etc/hosts

Here add your system FQDN on 127.0.0.1 localhost line like in the following example.

127.0.0.1 server.centos.lan localhost localhost.localdomain

Then edit /etc/hostname file to match the same system FQDN entry like in the screenshots below.

# nano /etc/hostname

Open Hostname File

Open Hostname File

Add Hostname in Hosts

Add Hostname in Hosts

3. After you have edited the host files, test your local DNS resolution using the following commands.

# hostname
# hostname -f    	## For FQDN
# hostname -s    	## For short name

How to Check Hostname in CentOS

Verify System Hostname

4. Now it’s time to install ProFTPD Server on your system and some required ftp utilities that we will be using later by issuing following command.

# yum install proftpd proftpd-utils

Install FTP in CentOS

Install Proftpd Server

5. After the server is installed, start and manage Proftpd daemon by issuing the following commands.

# systemctl start proftpd
# systemctl status proftpd
# systemctl stop proftpd
# systemctl restart proftpd

Start Proftpd Server

Start Proftpd Server

Step 2: Add Firewall Rules and Access Files

6. Now, your ProDTPD Server runs and listen for connections, but it’s not available for outside connections due to Firewall policy. To enable outside connections make sure you add a rule which opens port 21, using firewall-cmd system utility.

# firewall-cmd –add-service=ftp   ## On fly rule
# firewall-cmd –add-service=ftp   --permanent   ## Permanent rule
# systemctl restart firewalld.service 

Open FTP Port in CentOS

Open Proftp Port in Firewall

7. The most simple way to access your FTP server from remote machines is by using a browser, redirecting to your server IP Address or domain name using ftp protocol on URL.

ftp://domain.tld

OR 

ftp://ipaddress 

8. The default configuration on Proftpd Server uses valid system local accounts credentials to login and access your account files which is your $HOME system path account, defined in /etc/passwd file.

Access Proftpd from Browser

Access Proftpd from Browser

Index of Proftpd Files

Index of Proftpd Files

9. To make ProFTPD Server automatically run after system reboot, aka enable it system-wide, issue the following command.

# systemctl enable proftpd

That’s it! Now you can access and manage your account files and folders using FTP protocol using whether a browser or other more advanced programs, such as FileZilla, which is available on almost any platforms, or WinSCP, an excellent File Transfer program that runs on Windows based systems.

Suggested Read: How to Install, Configure and Secure FTP Server in CentOS 7

On the next series of tutorials concerning ProFTPD Server on RHEL/CentOS 7, I shall discuss more advanced features like enabling Anonymous accountuse TLS encrypted file transfers and adding Virtual Users.

Source

How to Control Web Traffic Using Squid Cache and Cisco Router in Linux

One important task in a network is control and manage staffs web surfing traffics, there are many solutions that can handles this issue, one of the best solutions is using squid cache on a Linux machine. Squid can inspect, limit and cache web traffics flow from one network to another network for example from a LAN to the Internet.

Traffic Control Using Squid and Cisco Router in CentOS

Traffic Control Using Squid and Cisco Router in CentOS

There is a few ways for redirecting client’s web requests to squid machine, in this article we will show you how to redirect web traffic from a CISCO router to a Squid Cache machine using WCCP protocol.

The picture below is an example of a basic scenario.

Control Web Traffic Using Squid Cisco Router

Control Web Traffic Using Squid Cisco Router

As you see in above picture all client’s web traffics first goes to Cisco Router (That is their default gateway), then router silently redirect packets to squid machine, now squid can play it’s roles, the main roles is caching web contents, limit access based on domains, time intervals, ip addresses, size of files, etc..

We review this scenario’s configuration in two Major steps, first we should install and configure squid and Linux, then configure router to redirecting web traffic packets into squid using WCCP protocol.

Testing Environment

In this scenario I use CENTOS 6.5 as my LINUX server and Cisco 2691 as my Router system.

Operating System: CENTOS 6.5
Application: Squid
Router: Cisco 2691

Step 1: Installing Squid Cache

Squid is available on default repository of CENTOS, we first install it using lovely yum command and then start their services and finally set automatic starting of squid service.

# yum -y install squid
# service squid start
# chkconfig squid on

Step 2: Preparing Squid Cache

Now we must change some default behaviors of centos operation system, we need to enable packet forwarding and disable reverse Path filter (RPF), we enable packet forwarding to let the centos acting as a transparent forwarder (like a router).

Let me explain in more detail, when traffics gets in centos it have their source and destination addresses, for example when a client enter www.example.com on his/her browser a http request packet generates and it have source ip address of client machine (like 192.168.1.20) and destination ip address of example.com server (like 2.2.2.2).

So, when packet received by centos it detect as an wrong packet because centos ip address is not as destination address of the packet, for security reasons centos drop the packet, but we want from squid to act in transparent mode. We tell this situation to centos by enabling packet forwarding potion.

Next we should disable Reverse path Filtering to let the centos accepting packets that not accessible by squid machine or it packets that do not have ip address in the same subnet of squid machine.

# nano /etc/sysctl.conf
net.ipv4.ip_forward = 1 #set to 1 for enable the packet forwarding feature
net.ipv4.conf.default.rp_filter = 0 # set to 0 for disable the reverse path filter behavior

Next we need to create a GRE interface on CENTOS machine, for what?? Let me explain more, the WCCPprotocol works through a GRE Tunnel, it means the language between router and Squid is GRE, so centos need to have a GRE interface for De-encapsulate GRE packets.

We should create the configuration file for GRE interface in “/etc/sysconfig/network-script/ifcfg-gre0” path.

Enter below codes in ifcfg-gre0 configuration file.

DEVICE=gre0
BOOTPROTO=static
IPADDR=10.0.0.2         #unused ip address in your network
NETMASK=255.255.255.252
ONBOOT=yes
IPV6INIT=no

After creating a GRE interface we need to restart network service.

# service network restart

Step 3: Configuring Squid Cache

We need to tell squid accepting WCCP packets from router. Enter below codes in /etc/squid/squid.conf file.

http_port 3128 intercept                 # Define SQUID listening port
wccp2_router 192.168.1.254          #ip address of the router
wccp2_forwarding_method gre
wccp2_return_method gre
wccp2_service standard 0

Save the configuration file and restart squid service.

# service squid restart

Squid listen for packets in 3128 port, but our packet’s destination port number is 80, so for changing destination port 80 to 3128, we need to create a NAT rule on CENTOS integrated firewall (that named iptable).

# iptables -t nat -A PREROUTING -i gre0 -p tcp --dport 80 -j REDIRECT --to-port 3128
# iptables -t nat -A POSTROUTING -j MASQUERADE

Step 4: Cisco Router Configurations

First we should enable WCCP on cisco router.

R1(config)# ip wccp version 2
Then we must use an ACL for introducing SQUID cache machine to router
R1(config)# ip access-list standard SQUID-MACHINE
R1(config-std-nacl)# permit host 192.168.1.10

Next we define another access list for two different purpose first we should except SQUID traffics from redirecting by WCCP protocol (if not we fall into an infinite loop!!) second we define which LAN traffics we want to passing through WCCP and SQUID.

R1(config)#ip access-list LAN-TRAFFICS
R1(config-ext-nacl)#deny ip host 192.168.1.10 any                            #Prevent SQUID to get in loop
R1(config-ext-nacl)#permit tcp 192.168.1.0 0.0.0.255 any equal www           #define LAN Traffics

After creating our access-list we must configure WCCP protocol on router.

R1(config)# ip wccp web-cache redirect-list LAN-TRAFFIC group-list SQUID-MACHINE

Every things is ready for final step, we must tell the router that in which interface/interfaces it must redirect traffics using their WCCP configuration.

R1(config)#interface fastEthernet 0/0
R1((config-if)# ip wccp web-cache redirect in

Summary

It’s time to summarize all commands and texts in a few lines for better understanding, according to the scenario we redirect staffs web surfing packets (that is on TCP port 80) from the ROUTER (that is default gateway of the clients) toward the squid cache machine using WCCP protocol.

All these process happened silently and there is no additional configuration on client side. So we can control and set policies on web traffics in the LAN. For example, we can gain web surfing access just in a limited time, limit maximum download size, define our custom blacklist and whitelist, generate full reports of internet activity usage and etc.

One of the interesting facts in this scenario is when squid machine goes down router detect this issue and stop redirecting packets toward it, so you can enjoy from zero-downtime in your network.

If you have any questions regarding to this article please leave a reply through below comment box.

Source

Install Plex Media Server on CentOS 7

Streaming media becomes more and more popular in recent years. Many people like to access their audio and video media from different locations and devices. With Plex Media Server you can easily achieve exactly that (and more) on practically any platform.

There are two versions of Plex – free and paid one.

Plex Free Version

Let’s have a look at what you can do with Plex Media Server (free):

  • Stream your audio and video content
  • Includes web app to access your content
  • Organize libraries
  • News and podcasts
  • Mobile app (with limited access)
  • Voice control
  • Available anywhere
  • PlexApp for remote control
  • 4K support
  • Media optimization for buffer free streaming

Plex Paid Version

The paid version of Plex, called Plex Pass, adds the following features:

  • Live TV and DVR
  • Stream trailers and extras. Also add lyrics to your songs, from LyricFind
  • Have geographic and scene-based tags on your photos
  • Use mobile sync for offline use
  • Camera upload for wireless syncing of photos
  • Sync content to multiple Cloud providers
  • Setup Plex Home to share content with your family and restrict what content can be accessed from your server
  • Unlock mobile features
  • Photo albums and Timeline view

It depends on you if you want to spend your hard earned money on the paid version of Plex, given the fact that the free version already provides lots of cool features.

Note that in order to use Plex, you will need to have an active account, that you can create here. The process is simple and straightforward so we will not stop to review the account creation.

Installing Plex Media Server in CentOS 7

Installing Plex is relatively easy task. Before we start, make sure your system is up to date by running:

$ sudo yum update

Next, head to Plex downloads page and download the package for your Linux distro. It is much easier to do this by simply coping the download link location with right click and then you can run:

$ sudo rpm -ivh https://downloads.plex.tv/plex-media-server/1.13.8.5395-10d48da0d/plexmediaserver-1.13.8.5395-10d48da0d.x86_64.rpm

Alternatively, you can download the package on your system with wget command as shown.

$ wget https://downloads.plex.tv/plex-media-server/1.13.8.5395-10d48da0d/plexmediaserver-1.13.8.5395-10d48da0d.x86_64.rpm

Use yum command to install the Plex server.

Now ensure that Plex is automatically started after system reboot and start the service.

$ sudo systemctl enable plexmediaserver.service
$ sudo systemctl start plexmediaserver.service

Configure Plex Media Server in CentOS 7

Plex comes with a pre-install web interface, through which you can manage your server. It can be accessed at:

http://[your-server-ip-address]:32400/web/

In my case this is:

http://192.168.20.110:32400/web/

You will be asked to login with your Plex account. When you authenticate, you will see a couple of windows regarding how Plex works and the second one providing you with list of paid options.

Lets head to the next one, where we can configure our server name. You can input whatever you like here:

Plex Media Server Setup

Plex Media Server Setup

Next you can organize your media library. Simply click the “Add library” button and navigate to your media.

Plex Media Organize

Plex Media Organize

Once you have configured your media library, you are all set and can complete the setup.

Plex Media Server Setup Completes

Plex Media Server Setup Completes

If you have skipped the media library setup, you can add more media later by clicking the plus “+” sign next to library in the left side menu. When configuring your media, it might come useful to check Plex’s naming convention here.

If you have setup Plex on a public server, it is recommended to disable DLNA as it will be accessible on port 1900. If you have setup Plex on a home server, you can leave it enabled so that media from your server is shared across devices in the same network.

To enable or disable DLNA click on “Settings” in the upper left corner and then scroll down to “DLNA”. From there you can check the box to enable or uncheck to disable DLNA:

Enable Plex DLNA

Enable Plex DLNA

Connect to Your Plex Server

Now that your media server is up and running, only thing left to do is:

  • Download the appropriate client to connect to your server. This can be done from your phone, PC, Mac etc.
  • Authenticate in the app with the same credentials you have used for your Plex server.
  • Start enjoying your media.

Connect to Plex Media Server

Connect to Plex Media Server

Plex is an easy to use, feature rich media server to help you enjoy your media from almost every device and place.

Source

How to Setup MySQL (Master-Slave) Replication in RHEL, CentOS, Fedora

The following tutorial aims to provide you a simple step-by-step guide for setting up MySQL (Master-SlaveReplication in RHEL 6.3/6.2/6.1/6/5.8CentOS 6.3/6.2/6.1/6/5.8 and Fedora 17,16,15,14,13,12 using latest MySQL version. This guide is specially written for CentOS 6.3 Operating System, but also work with older version of Linux distributions with MySQL 5.x.

UPDATE: If you’re looking for MariaDB Master-Slave Replication under CentOS/RHEL 7 and Debian 8 and it’s derivatives such as Ubuntu, follow this guide Setup MariaDB Master-Slave Replication.

mysql replication in Linux

MySQL Master-Slave Replication in RedHat / CentOS / Fedora

The MySQL Replication is very useful in terms of Data SecurityFail-over SolutionDatabase Backup from SlaveAnalytics etc. We use the following things to carry the replication process. In your scenario it would be different.

  1. Working Linux OS like CentOS 6.3RedHat 6.3 or Fedora 17
  2. Master and Slave are CentOS 6.3 Linux Servers.
  3. Master IP Address is: 192.168.1.1.
  4. Slave IP Address is: 192.168.1.2.
  5. Master and Slave are on the same LAN network.
  6. Master and Slave has MySQL version installed.
  7. Master allow remote MySQL connections on port 3306.

We have two servers, one is Master with IP (192.168.1.1) and other is Slave as (192.168.1.2). We have divided the setup process in two phases to make things easier for you, In Phase I we will configure Master server and in Phase II with Slave server. Let’s start the replication setup process.

Phase I: Configure Master Server (192.168.1.1) for Replication

In Phase I, we will see the installation of MySQL, setting up Replication and then verifying replication.

Install a MySQL in Master Server

First, proceed with MySQL installation using YUM command. If you already have MySQL installation, you can skip this step.

# yum install mysql-server mysql
Configure a MySQL in Master Server

Open my.cnf configuration file with VI editor.

# vi /etc/my.cnf

Add the following entries under [mysqld] section and don’t forget to replace tecmint with database name that you would like to replicate on Slave.

server-id = 1
binlog-do-db=tecmint
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
log-bin = /var/lib/mysql/mysql-bin

Restart the MySQL service.

# /etc/init.d/mysqld restart

Login into MySQL as root user and create the slave user and grant privileges for replication. Replace slave_userwith user and your_password with password.

# mysql -u root -p
mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'your_password';
mysql> FLUSH PRIVILEGES;
mysql> FLUSH TABLES WITH READ LOCK;
mysql> SHOW MASTER STATUS;

+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 11128001 | tecmint		 |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

mysql> quit;

Please write down the File (mysql-bin.000003) and Position (11128001) numbers, we required these numbers later on Slave server. Next apply READ LOCK to databases to export all the database and master database information with mysqldump command.

#  mysqldump -u root -p --all-databases --master-data > /root/dbdump.db

Once you’ve dump all the databases, now again connect to mysql as root user and unlcok tables.

mysql> UNLOCK TABLES;
mysql> quit;

Upload the database dump file on Slave Server (192.168.1.2) using SCP command.

scp /root/dbdump.db root@192.168.1.2:/root/

That’s it we have successfully configured Master server, let’s proceed to Phase II section.

Phase II: Configure Slave Server (192.168.1.2) for Replication

In Phase II, we do the installation of MySQL, setting up Replication and then verifying replication.

Install a MySQL in Slave Server

If you don’t have MySQL installed, then install it using YUM command.

# yum install mysql-server mysql
Configure a MySQL in Slave Server

Open my.cnf configuration file with VI editor.

# vi /etc/my.cnf

Add the following entries under [mysqld] section and don’t forget to replace IP address of Master server, tecmint with database name etc, that you would like to replicate with Master.

server-id = 2
master-host=192.168.1.1
master-connect-retry=60
master-user=slave_user
master-password=yourpassword
replicate-do-db=tecmint
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
log-bin = /var/lib/mysql/mysql-bin

Now import the dump file that we exported in earlier command and restart the MySQL service.

# mysql -u root -p < /root/dbdump.db
# /etc/init.d/mysqld restart

Login into MySQL as root user and stop the slave. Then tell the slave to where to look for Master log file, that we have write down on master with SHOW MASTER STATUS; command as File (mysql-bin.000003) and Position (11128001) numbers. You must change 192.168.1.1 to the IP address of the Master Server, and change the user and password accordingly.

# mysql -u root -p
mysql> slave stop;
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.1', MASTER_USER='slave_user', MASTER_PASSWORD='yourpassword', MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=11128001;
mysql> slave start;
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.1
                  Master_User: slave_user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 12345100
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 11381900
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: tecmint
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 12345100
              Relay_Log_Space: 11382055
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
1 row in set (0.00 sec)

Verifying MySQL Replication on Master and Slave Server

It’s really very important to know that the replication is working perfectly. On Master server create table and insert some values in it.

On Master Server
mysql> create database tecmint;
mysql> use tecmint;
mysql> CREATE TABLE employee (c int);
mysql> INSERT INTO employee (c) VALUES (1);
mysql> SELECT * FROM employee;
+------+
|  c  |
+------+
|  1  |
+------+
1 row in set (0.00 sec)
On Slave Server

Verifying the SLAVE, by running the same command, it will return the same values in the slave too.

mysql> use tecmint;
mysql> SELECT * FROM employee;
+------+
|  c  |
+------+
|  1  |
+------+
1 row in set (0.00 sec)

That’s it, finally you’ve configured MySQL Replication in a few simple steps. More information can be found at MySQL Replication Guide.

Source

Mytop – A Useful Tool for Monitoring MySQL/MariaDB Performance in Linux

Mytop is an open source and free monitoring program for MySQL and MariaDB databases was written by Jeremy Zawodny using Perl language. It is much similar in look and feel of the most famous Linux system monitoring tool called top.

Mytop program provides a command-line shell interface to monitor real time MySQL/MariaDB threadsqueries per secondprocess list and performance of databases and gives a idea for the database administrator to better optimize the server to handle heavy load.

By default Mytop tool is included in the Fedora and Debian/Ubuntu repositories, so you just have to install it using your default package manager.

If you are using RHEL/CentOS distributions, then you need to enable third party EPEL repository to install it.

For other Linux distributions you can get mytop source package and compile it from source as shown.

# tar -zxvf mytop-<version>.tar.gz
# cd mytop-
# perl Makefile.PL
# make
# make test
# make install

In this MySQL monitoring tutorial, we will show you how to install, configure and use mytop on various Linux distributions.

Please note you must have running MySQL/MariaDB Server on the system to install and use Mytop.

Install Mytop in Linux Systems

To install Mytop, run the appropriate command below for your Linux distribution to install it.

$ sudo apt install mytop	#Debian/Ubuntu
# yum install mytop	        #RHEL/CentOS
# dnf install mytop	        #Fedora 22+
# pacman -S mytop	        #Arch Linux 
# zypper in mytop	        #openSUSE
Sample Output :
Loaded plugins: changelog, fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.linode.com
 * epel: mirror.freethought-internet.co.uk
 * extras: mirrors.linode.com
 * updates: mirrors.linode.com
Resolving Dependencies
--> Running transaction check
---> Package mytop.noarch 0:1.7-10.b737f60.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================
 Package                               Arch                                   Version                                              Repository                            Size
==============================================================================================================================================================================
Installing:
 mytop                                 noarch                                 1.7-10.b737f60.el7                                   epel                                  33 k

Transaction Summary
==============================================================================================================================================================================
Install  1 Package

Total download size: 33 k
Installed size: 68 k
Is this ok [y/d/N]: y

How to use Mytop to Monitor MySQL/MariaDB

Mytop needs MySQL/MariaDB login credentials to monitor databases and connects to the server with the root username by default. You can specify the necessary options for connecting to the database server on the command-line as you run it or in the file ~/.mytop (for convenience as explained later on).

Just run the following command to start the mytop and provide your MySQL/MariaDB root user password, when prompted. This will connect to the test database by default.

# mytop --prompt
Password:

Once you entered the MySQL root password you will see Mytop monitoring shell, similar to below.

MySQL Database Monitoring

MySQL Database Monitoring

If you would like to monitor specific database, then use the -d option as shown below. For example the below command will monitor database tecmint.

# mytop --prompt -d tecmint
Password:

Monitor MySQL Database

Monitor MySQL Database

If each of your databases has a specific admin (for example tecmint database admin), then connect using the database username and password like so.

# mytop -u tecmint -p password_here -d tecmintdb

However, this has certain security implications since the user’s password is typed on the command-line and can be stored in the shell command history file. This file can be viewed later on by an unauthorized person who might land on the username and password.

To avoid the risk of such a scenario, use the ~/.mytop config file to specify options for connecting to the database. Another advantage of this method is that you also do away with typing numerous command-line arguments each time you want to run mytop.

# vi ~/.mytop

Then add the necessary options below in it.

user=root
pass=password_here
host=localhost
db=test
delay=4
port=3306
socket=

Save and close the file. Then run mytop without any command-line arguments.

# mytop

It has a capability to show large amount of information on the screen and has many keyboard shortcut options too, check out “man mytop” for more information.

# man mytop

Read Also :

  1. Mtop (MySQL Database Monitoring) in RHEL/CentOS/Fedora
  2. Innotop to Monitor MySQL Performance

In this article, we have explained how to install, configure and use mytop in Linux. If you have any questions, use the feedback form below to reach us.

Source

Install Mtop (MySQL Database Server Monitoring) in RHEL/CentOS 7/6/5/4, Fedora 17-12

mtop (MySQL top) is an open source real time MYSQL Server monitoring program written in Perl language that shows queries which are taking longer time to process and kills those longer queries after certain number of specified time. Mtop program enable us to monitor and identify performance and related issues of MySQL Server from the command line interface similar to Linux Top Command.

Mtop MySQL Monitoring

Install Mtop MySQL Monitoring

Mtop includes zooming feature that display query optimizer information of a running queries and killing queries, it also shows statistics of server, configuration information and some useful tuning tips to optimize and improve MySQL performance.

Please check some of the following features offered by Mtop program.

  1. Display real time MySQL server queries.
  2. Provides MySQL configuration information.
  3. Zooming feature to display process query.
  4. Provides query Optimizer information for a query and ‘killing’ queries.
  5. Provides MySQL tuning tips.
  6. Ability to save output in a .mtoprc configuration file.
  7. Provides Sysadmin recommendation page (‘T‘).
  8. Added queries/second to main header.
  9. Added per second info to stats screen.

In this article we’re going to show how to install Mtop (MySQL Top) program under RHEL 7/6.3/6.2/6.1/6/5.8/5.6/4.0CentOS 7/6.3/6.2/6.1/6/5.8/5.6/4.0 and Fedora 17,16,15,14,13,12 using RPMForgerepository via YUM Command.

Enable RPMForge Repository in RHEL/CentOS 6/5/4 and Fedora 17-12

First, you need to enable RPMForge repository under your Linux machine to download and install latest version of MTOP program.

Install RPMForge on RHEL/CentOS 6

Select the following links based on your Linux architecture to enable RPMforge repository under your Linux box. (Note : Fedora user’s don’t need to enable any repository under Fedora box).

For RHEL/CentOS 6 32-Bit OS
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.i686.rpm
For RHEL/CentOS 6 64-Bit OS
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

Install RPMForge on RHEL/CentOS 5

For RHEL/CentOS 5 32-Bit OS
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm
For RHEL/CentOS 5 64-Bit OS
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

Install RPMForge on RHEL/CentOS 4

For RHEL/CentOS 4 32-Bit OS
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el4.rf.i386.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el4.rf.i386.rpm
For RHEL/CentOS 4 64-Bit OS
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el4.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el4.rf.x86_64.rpm

Import RPMForge Repository Key in RHEL/CentOS 6/5/4

# wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
# rpm --import RPM-GPG-KEY.dag.txt

Install Mtop in RHEL/CentOS 6/5/4 and Fedora 17-12

Once you’ve installed and enabled RPMForge repository, let’s install MTOP using following YUM command.

# yum install mtop
Sample Output :
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
rpmforge                                                                          | 1.9 kB     00:00
rpmforge/primary_db                                                                 2.6 MB     00:19
Setting up Install Process
Dependencies Resolved

================================================================================================================
 Package                       Arch				Version					Repository				Size
================================================================================================================
Installing:
 mtop                          noarch           0.6.6-1.2.el6.rf        rpmforge                52 k
Installing for dependencies:
 perl-Curses                   i686             1.28-1.el6.rf           rpmforge                156 k

Transaction Summary
================================================================================================================
Install       2 Package(s)

Total download size: 208 k
Installed size: 674 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): mtop-0.6.6-1.2.el6.rf.noarch.rpm                                           |  52 kB     00:00
(2/2): perl-Curses-1.28-1.el6.rf.i686.rpm                                         | 156 kB     00:01
-----------------------------------------------------------------------------------------------------------------
Total                                                                     46 kB/s | 208 kB     00:04
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : perl-Curses-1.28-1.el6.rf.i686													1/2
  Installing : mtop-0.6.6-1.2.el6.rf.noarch                                                     2/2
  Verifying  : perl-Curses-1.28-1.el6.rf.i686                                                   1/2
  Verifying  : mtop-0.6.6-1.2.el6.rf.noarch                                                     2/2

Installed:
  mtop.noarch 0:0.6.6-1.2.el6.rf

Dependency Installed:
  perl-Curses.i686 0:1.28-1.el6.rf

Complete!

Starting Mtop in RHEL/CentOS 6/5/4

To start Mtop program, you need to connect to your MySQL Server, using following command.

# mysql -u root -p

Then you need to create separate user called mysqltop and grant privileges to him under your MySQL server. To do, this just run the following commands in mysql shell.

mysql> grant super, reload, process on *.* to mysqltop;
Query OK, 0 rows affected (0.00 sec)

mysql> grant super, reload, process on *.* to mysqltop@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye

Running Mtop in RHEL/CentOS 6/5/4

Let’s start the Mtop program by executing below command. You will see sample output similar to below.

# mtop
Sample Outpit :
load average: 0.01, 0.00, 0.00 mysqld 5.1.61 up 5 day(s), 19:21 hrs
2 threads: 1 running, 0 cached. Queries/slow: 5/0 Cache Hit: 71.43%
Opened tables: 0  RRN: 277  TLW: 0  SFJ: 0  SMP: 0  QPS: 0

ID       USER     HOST         DB       TIME   COMMAND STATE        INFO
322081   mysqltop localhost						Query				show full processlist

Monitor Remote MySQL Server using Mtop

Simply, type the following command to monitor any remote MySQL Server.

# mtop  –host=remotehost –dbuser=username –password=password –seconds=1

Mtop Usage and Functions

Please use the following keys while mtop is running.

Filtering/display

  1. s – change the number of seconds to delay between updates
  2. m – toggle manual refresh mode on/off
  3. d – filter display with regular expression (user/host/db/command/state/info)
  4. F – fold/unfold column names in select statement display
  5. h – display process for only one host
  6. u – display process for only one user
  7. i – toggle all/non-Sleeping process display
  8. o – reverse the sort order
  9. q – quit
  10. ? – help

For more options and usage please see the man pages of mtop command by running “man mtop” on terminal.

Read Also :

  1. Mytop Database Monitoring
  2. Innotop to Monitor MySQL Performance

Source

Install Innotop to Monitor MySQL Server Performance

Innotop is an excellent command line program, similar to ‘top command‘ to monitor local and remote MySQL servers running under InnoDB engine. Innotop comes with many features and different types of modes/options, which helps to monitor different aspects of MySQL performance and also helps database administrator to find out what’s wrong going with MySQL server.

For example, Innotop helps in monitoring mysql replication statususer statisticsquery listInnoDB buffersInnoDB I/O informationopen tableslock tables, etc, it refreshes its data regularly, so you could see updated results.

Install Innotop in Centos

Innotop MySQL Server Monitoring

Innotop comes with great features and flexibility and doesn’t needs any extra configuration and it can be executed by just running ‘innotop‘ command from the terminal.

Installing Innotop (MySQL Monitoring)

By default innotop package is not included in Linux distributions such as RHELCentOSFedora and Scientific Linux. You need to install it by enabling third party epel repository and using yum command as shown below.

# yum install innotop
Sample Output
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirror.net.in
 * epel: epel.mirror.net.in
 * epel-source: epel.mirror.net.in
 * extras: centos.mirror.net.in
 * updates: centos.mirror.net.in
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package innotop.noarch 0:1.9.0-3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================
 Package			Arch		Version			Repository		Size
==========================================================================================================
Installing:
 innotop                        noarch          1.9.0-3.el6             epel                    149 k

Transaction Summary
==========================================================================================================
Install       1 Package(s)

Total download size: 149 k
Installed size: 489 k
Is this ok [y/N]: y
Downloading Packages:
innotop-1.9.0-3.el6.noarch.rpm                                                      | 149 kB    00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : innotop-1.9.0-3.el6.noarch							1/1 
  Verifying  : innotop-1.9.0-3.el6.noarch                                                       1/1 

Installed:
  innotop.noarch 0:1.9.0-3.el6                                                                                                                                 

Complete!

To start innotop, simply type “innotop” and specify options -u (username) and -p (password) respectively, from the command line and press Enter.

# innotop -u root -p 'tecm1nt'

Once you’ve connected to MySQL server, you should see something similar to the following screen.

[RO] Dashboard (? for help)                                                                    localhost, 61d, 254.70 QPS, 5/2/200 con/run/cac thds, 5.1.61-log
Uptime  MaxSQL  ReplLag  Cxns  Lock  QPS     QPS  Run  Run  Tbls  Repl   SQL
   61d                      4     0  254.70  _         _     462  Off 1
Innotop Help

Press “?” to get the summary of command line options and usage.

Switch to a different mode:
   A  Dashboard         I  InnoDB I/O Info     Q  Query List
   B  InnoDB Buffers    K  InnoDB Lock Waits   R  InnoDB Row Ops
   C  Command Summary   L  Locks               S  Variables & Status
   D  InnoDB Deadlocks  M  Replication Status  T  InnoDB Txns
   F  InnoDB FK Err     O  Open Tables         U  User Statistics

Actions:
   d  Change refresh interval        p  Pause innotop
   k  Kill a query's connection      q  Quit innotop
   n  Switch to the next connection  x  Kill a query

Other:
 TAB  Switch to the next server group   /  Quickly filter what you see
   !  Show license and warranty         =  Toggle aggregation
   #  Select/create server groups       @  Select/create server connections
   $  Edit configuration settings       \  Clear quick-filters
Press any key to continue

This section contains screen shots of innotop usage. Use Upper-case keys to switch between modes.

User Statistics

This mode displays user statistics and index statistics sorted by reads.

CXN        When   Load  QPS    Slow  QCacheHit  KCacheHit  BpsIn    BpsOut 
localhost  Total  0.00  1.07k   697      0.00%     98.17%  476.83k  242.83k
Query List

This mode displays the output from SHOW FULL PROCESSLIST, similar to mytop’s query list mode. This feature doesn’t display InnoDB information and it’s most useful for general usage.

When   Load  Cxns  QPS   Slow  Se/In/Up/De%             QCacheHit  KCacheHit  BpsIn    BpsOut
Now    0.05     1  0.20     0   0/200/450/100               0.00%    100.00%  882.54   803.24
Total  0.00   151  0.00     0  31/231470/813290/188205      0.00%     99.97%    1.40k    0.22

Cmd      ID      State               User      Host           DB      Time      Query
Connect      25  Has read all relay  system u                         05:26:04
InnoDB I/O Info

This mode displays InnoDB’s I/O statisticspending I/OI/O threadsfile I/O and log statistics tables by default.

____________________ I/O Threads ____________________
Thread  Purpose               Thread Status          
     0  insert buffer thread  waiting for i/o request
     1  log thread            waiting for i/o request
     2  read thread           waiting for i/o request
     3  write thread          waiting for i/o request

____________________________ Pending I/O _____________________________
Async Rds  Async Wrt  IBuf Async Rds  Sync I/Os  Log Flushes  Log I/Os
        0          0               0          0            0         0

________________________ File I/O Misc _________________________
OS Reads  OS Writes  OS fsyncs  Reads/Sec  Writes/Sec  Bytes/Sec
      26          3          3       0.00        0.00          0

_____________________ Log Statistics _____________________
Sequence No.  Flushed To  Last Checkpoint  IO Done  IO/Sec
0 5543709     0 5543709   0 5543709              8    0.00
InnoDB Buffers

This section, you will see information about the InnoDB buffer poolpage statisticsinsert buffer, and adaptive hash index. The data fetches from SHOW INNODB STATUS.

__________________________ Buffer Pool __________________________
Size  Free Bufs  Pages  Dirty Pages  Hit Rate  Memory  Add'l Pool
 512        492     20            0  --        16.51M     841.38k

____________________ Page Statistics _____________________
Reads  Writes  Created  Reads/Sec  Writes/Sec  Creates/Sec
   20       0        0       0.00        0.00         0.00

______________________ Insert Buffers ______________________
Inserts  Merged Recs  Merges  Size  Free List Len  Seg. Size
      0            0       0     1              0          2

__________________ Adaptive Hash Index ___________________
Size    Cells Used  Node Heap Bufs  Hash/Sec  Non-Hash/Sec
33.87k                           0      0.00          0.00
InnoDB Row Ops

Here, you will see the output of InnoDB row operationsrow operation miscsemaphores, and wait array tables by default.

________________ InnoDB Row Operations _________________
Ins  Upd  Read  Del  Ins/Sec  Upd/Sec  Read/Sec  Del/Sec
  0    0     0    0     0.00     0.00      0.00     0.00

________________________ Row Operation Misc _________________________
Queries Queued  Queries Inside  Rd Views  Main Thread State          
             0               0         1  waiting for server activity

_____________________________ InnoDB Semaphores _____________________________
Waits  Spins  Rounds  RW Waits  RW Spins  Sh Waits  Sh Spins  Signals  ResCnt
    2      0      41         1         1         2         4        5       5

____________________________ InnoDB Wait Array _____________________________
Thread  Time  File  Line  Type  Readers  Lck Var  Waiters  Waiting?  Ending?
Command Summary

The command summary mode displays all the cmd_summary table, which looks similar to the below.

_____________________ Command Summary _____________________
Name                    Value     Pct     Last Incr  Pct   
Com_update              11980303  65.95%          2  33.33%
Com_insert               3409849  18.77%          1  16.67%
Com_delete               2772489  15.26%          0   0.00%
Com_select                   507   0.00%          0   0.00%
Com_admin_commands           411   0.00%          1  16.67%
Com_show_table_status        392   0.00%          0   0.00%
Com_show_status              339   0.00%          2  33.33%
Com_show_engine_status       164   0.00%          0   0.00%
Com_set_option               162   0.00%          0   0.00%
Com_show_tables               92   0.00%          0   0.00%
Com_show_variables            84   0.00%          0   0.00%
Com_show_slave_status         72   0.00%          0   0.00%
Com_show_master_status        47   0.00%          0   0.00%
Com_show_processlist          43   0.00%          0   0.00%
Com_change_db                 27   0.00%          0   0.00%
Com_show_databases            26   0.00%          0   0.00%
Com_show_charsets             24   0.00%          0   0.00%
Com_show_collations           24   0.00%          0   0.00%
Com_alter_table               12   0.00%          0   0.00%
Com_show_fields               12   0.00%          0   0.00%
Com_show_grants               10   0.00%          0   0.00%
Variables & Status

This section calculates statistics, like queries per second, and displays them out in number of different modes.

QPS     Commit_PS     Rlbck_Cmt  Write_Commit     R_W_Ratio      Opens_PS   Tbl_Cch_Usd    Threads_PS  Thrd_Cch_Usd CXN_Used_Ever  CXN_Used_Now
  0             0             0      18163174             0             0             0             0             0          1.99          1.32
  0             0             0      18163180             0             0             0             0             0          1.99          1.32
  0             0             0      18163188             0             0             0             0             0          1.99          1.32
  0             0             0      18163192             0             0             0             0             0          1.99          1.32
  0             0             0      18163217             0             0             0             0             0          1.99          1.32
  0             0             0      18163265             0             0             0             0             0          1.99          1.32
  0             0             0      18163300             0             0             0             0             0          1.99          1.32
  0             0             0      18163309             0             0             0             0             0          1.99          1.32
  0             0             0      18163321             0             0             0             0             0          1.99          1.32
  0             0             0      18163331             0             0             0             0             0          1.99          1.32
Replication Status

In this mode, you will see the output of Slave SQL StatusSlave I/O Status and Master Status. The first two section shows the slave status and slave I/O thread status and the last section shows Master status.

_______________________ Slave SQL Status _______________________
Master        On?  TimeLag  Catchup  Temp  Relay Pos  Last Error
172.16.25.125  Yes    00:00     0.00     0   41295853            

____________________________________ Slave I/O Status _____________________________________
Master        On?  File              Relay Size  Pos       State                           
172.16.25.125  Yes  mysql-bin.000025      39.38M  41295708  Waiting for master to send event

____________ Master Status _____________
File              Position  Binlog Cache
mysql-bin.000010  10887846         0.00%
Non-Interactively

You can run “innotop” in non-interactively.

# innotop --count 5 -d 1 -n
uptime	max_query_time	time_behind_master	connections	locked_count	qps	spark_qps	run	spark_run	open	slave_running	longest_sql
61d			2	0	0.000363908088893752				64	Yes 	
61d			2	0	4.96871146980749	_		_	64	Yes 	
61d			2	0	3.9633543857494	^_		__	64	Yes 	
61d			2	0	3.96701862656428	^__		___	64	Yes 	
61d			2	0	3.96574802684297	^___		____	64	Yes
Monitor Remote Database

To monitor a remote database on a remote system, use the following command using a particular usernamepassword and hostname.

# innotop -u username -p password -h hostname

For more information about ‘innotop‘ usage and options, see the man pages by hitting “man innotop” on a terminal.

Reference Links

Innotop Homepage

Read Also :

  1. Mtop (MySQL Database Monitoring) in RHEL/CentOS/Fedora

Source

How to Create and Use Alias Command in Linux

Linux users often need to use one command over and over again. Typing or copying the same command again and again reduces your productivity and distracts you from what you are actually doing.

You can save yourself some time by creating aliases for your most used commands. Aliases are like custom shortcuts used to represent a command (or set of commands) executed with or without custom options. Chances are you are already using aliases on your Linux system.

List Currently Defined Aliases in Linux

You can see a list of defined aliases on your profile by simply executing alias command.

$ alias

Here you can see the default aliases defined for your user in Ubuntu 18.04.

List Aliases in Linux

List Aliases in Linux

As you can see, executing.

$ ll

Is equivalent to running:

$ ls -alF

You can create an alias with a single character that will be equivalent to a command of your choice.

How to Create Aliases in Linux

Creating aliases is relatively easy and quick process. You can create two types of aliases – temporary ones and permanent. We will review both types.

Creating Temporary Aliases

What you need to do is type the word alias then use the name you wish to use to execute a command followed by "=" sign and quote the command you wish to alias.

The syntax is as follows:

$ alias shortName="your custom command here"

Here is an actual example:

$ alias wr=”cd /var/www/html”

You can then use "wr" shortcut to go to the webroot directory. The problem with that alias is that it will only be available for your current terminal session.

If you open new terminal session, the alias will no longer be available. If you wish to save your aliases across sessions you will need a permanent alias.

Creating Permanent Aliases

To keep aliases between sessions, you can save them in your user’s shell configuration profile file. This can be:

  • Bash – ~/.bashrc
  • ZSH – ~/.zshrc
  • Fish – ~/.config/fish/config.fish

The syntax you should use is practically the same as creating a temporary alias. The only difference comes from the fact that you will be saving it in a file this time. So for example, in bash, you can open .bashrc file with your favorite editor like this:

$ vim ~/.bashrc

Find a place in the file, where you want to keep the aliases. For example, you can add them in the end of the file. For organizations purposes you can leave a comment before your aliases something like this:

#My custom aliases
alias home=”ssh -i ~/.ssh/mykep.pem tecmint@192.168.0.100”
alias ll="ls -alF"

Save the file. The file will be automatically loaded in your next session. If you want to use the newly defined alias in the current session, issue the following command:

$ source ~/.bashrc

To remove an alias added via the command line can be unaliased using unalias command.

$ unalias alias_name
$ unalias -a [remove all alias]
Conclusion

This was a short example on how to create your own alias and execute frequently used commands without having to type each command again and again. Now you can think about the commands you use the most and create shortcuts for them in your shell.

Source

WP2Social Auto Publish Powered By : XYZScripts.com