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

Friday, September 14, 2018

python: SELinux is preventing httpd from connectto access on the unix_stream_socket /var/lib/mysql/mysql.sock - Mariadb running on RHEL 7

Friday, September 14, 2018 0
SELinux is preventing the httpd access by default.

Situation
While connecting mysql database from web, getting this error.
 python: SELinux is preventing httpd from connectto access on the unix_stream_socket /var/lib/mysql/mysql.sock

Solution
Run below command to allow httpd in Selinux.

[root@nsk ~]#  ausearch -c 'httpd' --raw | audit2allow -M my-httpd
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i my-httpd.pp

[root@nsk ~]# semodule -i my-httpd.pp

Hope it helps.

Friday, September 7, 2018

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' - Mariadb running on RHEL7

Friday, September 07, 2018 0
Situation : 
                  I have tried to login as root to MariaDB Database in Linux Server, Getting below error.

[root@nsk ~]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

Solution: 
                We need to recover the root password of mariadb. Follow the below steps to achieve root password recovery.

STEP 1 : Stop the mariadb service
[root@nsk ~]# systemctl stop mariadb.service
[root@nsk ~]#

STEP 2 : Run mysql in safe mode
[root@nsk ~]# mysqld_safe --skip-grant-tables &
[1] 8051
[root@nsk ~]# 180907 13:23:49 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
180907 13:23:49 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

STEP 3 : Login as root and select mysql db. Then reset root password.
[root@nsk ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+-------------------------------+
| Database                      |
+-------------------------------+
| information_schema     |
| company                       |
| mydb                             |
| mysql                            |
| performance_schema   |
| test                                |
+-------------------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]> use mysql;
Database changed
MariaDB [mysql]> update user set password=PASSWORD("NewPassword") where User='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3  Changed: 0  Warnings: 0

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

MariaDB [mysql]> quit
Bye

STEP 4 : Now stop and start the mariadb service and test the new password.

[root@nsk ~]# systemctl stop mariadb.service
[root@nsk ~]#
[root@nsk ~]# systemctl start mariadb.service
[root@nsk ~]#
[root@nsk ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Hope it helps.

Tuesday, September 4, 2018

Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again - SOLVED

Tuesday, September 04, 2018 0
Situation : I have installed epel-release-latest-6.noarch.rpm on CentOS release 6.10 (Final) and trying to install 
python-pip, but getting the below error.

[root@puppetlabs tmp]# rpm -ivh epel-release-latest-6.noarch.rpm
warning: epel-release-latest-6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
   1:epel-release         ###########################################  [100%]
[root@puppetlabs tmp]#
[root@puppetlabs tmp]# yum install python-pip
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

Solution:

Edit both /etc/yum.repos.d/epel.repo and /etc/yum.repos.d/epel-testing.repo files, commenting all entries 
starting with mirrorlist=  and uncomment all the entries starting with baseurl= 

epel.repo base url is changed from http://download.fedoraproject.org/pub/epel/6/  to http://del-repos.extreme-ix.org/epel/6/x86_64/repodata/ update the same.
epel-testing.repo base url is changed from http://del-repos.extreme-ix.org/epel/testing/6/ to http://del-repos.extreme-ix.org/epel/testing/6 update the same.

Now run yum repolist command.

[root@puppetlabs yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirror.far.fi
 * extras: centos.mirror.far.fi
 * updates: centos.mirror.far.fi
repo id                 repo name                                                                        status
base                    CentOS-6 - Base                                                               6,713
epel                     Extra Packages for Enterprise Linux 6 - x86_64           12,522
extras                  CentOS-6 - Extras                                                                 31
updates               CentOS-6 - Updates                                                             114
repolist: 19,380

Hope it helps.

Monday, September 3, 2018

How to reduce (lvreduce) the Logical Volume in Linux Server

Monday, September 03, 2018 0
How to reduce (lvreduce) the Logical Volume in Linux Server.

Situation

Here, /app1 is 100GB filesystem. We need to reduce it to 70GB 

[root@testserver ~]# df -hP
Filesystem                                                 Size  Used Avail Use% Mounted on
/dev/mapper/vg_main-lv_root                   31G  2.0G    28G   7%    /
tmpfs                                                        3.7G     0      3.7G   0%   /dev/shm
/dev/xvdb1                                              477M   93M  355M  21%  /boot
/dev/mapper/vg_DPFERT-lv_app1           99G   11G    84G  11%   /app1


[root@testserver ~]# vgs
  VG                #PV #LV #SN Attr      VSize    VFree
  vg_DPFERT    1   1      0    wz--n-  100.00g    0
  vg_main           1   2      0    wz--n-    31.50g   0

[root@testserver ~]# fdisk -l /dev/xvdc

Disk /dev/xvdc: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdc1               1       13054   104856254+  8e  Linux LVM

STEP 1 : First Unmount the LV

STEP 2 : Run e2fsck command to check the file system

[root@testserver ~]# e2fsck -f /dev/vg_DPFERT/lv_app1
e2fsck 1.43-WIP (20-Jun-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg_DPFERT/lv_app1: 57971/6553600 files (0.2% non-contiguous), 3073907/26213376 blocks


STEP 3 : Run resize2fs command for resizing the file system.

[root@testserver ~]# resize2fs /dev/vg_DPFERT/lv_app1 70G 
resize2fs 1.43-WIP (20-Jun-2013)
Resizing the filesystem on /dev/vg_DPFERT/lv_app1 to 18350080 (4k) blocks.
The filesystem on /dev/vg_DPFERT/lv_app1 is now 18350080 blocks long.

STEP 4 : Run lvreduce command to resuce the lvsize.

[root@testserver ~]# lvreduce -L 70G /dev/vg_DPFERT/lv_app1
  WARNING: Reducing active logical volume to 70.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_app1? [y/n]: y
  Size of logical volume vg_DPFERT/lv_app1 changed from 100.00 GiB (25599 extents) to 70.00 GiB (17920 extents).
  Logical volume lv_app1 successfully resized
[root@testserver ~]#

STEP 5 : Mount the LV
[root@testserver ~]# lvs
  LV          VG                  Attr          LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_app1  vg_DPFERT  -wi-a-----  70.00g
  lv_root    vg_main       -wi-ao----  31.22g
  lv_swap  vg_main       -wi-ao---- 288.00m

[root@testserver ~]# vgs
  VG                  #PV #LV #SN Attr       VSize      VFree
  vg_DPFERT    1      1      0    wz--n-  100.00g   30.00g
  vg_main           1      2     0     wz--n-  31.50g     0
  
[root@testserver home]# df -hP
Filesystem                                          Size  Used Avail Use% Mounted on
/dev/mapper/vg_main-lv_root             31G   2.0G   28G   7%   /
tmpfs                                                  3.7G     0      3.7G   0%  /dev/shm
/dev/xvdb1                                        477M   93M  355M  21% /boot
/dev/mapper/vg_DPFERT-lv_app1     69G   11G   56G   16%  /app1

Hope it helps.

Export proxy variable in Linux by using command line

Monday, September 03, 2018 0
Here Export Command is used to set Proxy Environment Variables in Linux Servers.

Syntax:

export "http_proxy=http://username:password@proxy.example.com:port_no/"
export "https_proxy=https://username:password@proxy.example.com:port_no/"

Note : If password contains Reserved charecters, need to replace with respective percent-encoding.

Reserved characters and Percent-encoding
! - %21
# - %23
$ - %24
& - %26
' - %27
( - %28
) - %29
* - %2A
+ - %2B
, - %2C
/ - %2F
: - %3A
; - %3B
= - %3D
? - %3F
@ - %40
[ - %5B
] - %5D

Check the proxy server settings by running env command.

[root@puppetlabs ~]# env | grep -i proxy

If we want to remove proxy variables. Run unset command.

[root@puppetlabs ~]# unset http_proxy
[root@puppetlabs ~]# unset https_proxy

Tuesday, July 10, 2018

How to upgrade Ansible by using PIP?

Tuesday, July 10, 2018 0
What is PIP

PIP is a package management system used to install and manage software packages written in Python. If you do not have PIP installed, we can download and install it from this page: https://pypi.org/project/pip/

Download the required ansible tar.gz package from below URL.

https://releases.ansible.com/ansible/

Here i already have ansible 2.0 running on this server. I need to upgrade it to 2.2.

[root@ansibleserver nskselvan]# pip install ansible-2.2.0.0.tar.gz
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Processing ./ansible-2.2.0.0.tar.gz
Requirement already satisfied: paramiko in /usr/local/lib/python2.6/site-packages/paramiko-1.15.2-py2.6.egg (from ansible==2.2.0.0)
Requirement already satisfied: jinja2 in /usr/local/lib/python2.6/site-packages/Jinja2-2.8-py2.6.egg (from ansible==2.2.0.0)
Requirement already satisfied: PyYAML in /usr/local/lib/python2.6/site-packages (from ansible==2.2.0.0)
Requirement already satisfied: setuptools in /usr/local/lib/python2.6/site-packages/setuptools-18.1-py2.6.egg (from ansible==2.2.0.0)
Requirement already satisfied: pycrypto>=2.6 in /usr/local/lib/python2.6/site-packages (from ansible==2.2.0.0)
Requirement already satisfied: ecdsa>=0.11 in /usr/local/lib/python2.6/site-packages/ecdsa-0.13-py2.6.egg (from paramiko->ansible==2.2.0.0)
Requirement already satisfied: MarkupSafe in /usr/local/lib/python2.6/site-packages/MarkupSafe-0.23-py2.6-linux-x86_64.egg (from jinja2->ansible==2.2.0.0)
Installing collected packages: ansible
  Found existing installation: ansible 2.0.0.1
    Uninstalling ansible-2.0.0.1:
      Successfully uninstalled ansible-2.0.0.1
  Running setup.py install for ansible ... done
Successfully installed ansible-2.2.0.0
[root@ansibleserver nskselvan]#

[root@ansibleserver nskselvan]# ansible --version
ansible 2.2.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
[root@ansibleserver nskselvan]#

Note : For safer side, please take the backup of all necessary files.

Tuesday, June 26, 2018

Solved : Sendmail stat=Service unavailable

Tuesday, June 26, 2018 0
Situation : Maillog says Service unavailable

Jun 24 06:43:54 testserver sendmail[24622]: w5O4hsFN024620: to=<testuser@remotetest.com> ctladdr=<oratest@testserver.mail.com> (20001/20001), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=150623, relay=relayserver.com. [10.0.34.1], dsn=5.0.0, stat=Service unavailable

Solution:




Go to /etc/mail path 

 
Step1 : generics-domains file should be below format.

[root@testserver mail]# cat generics-domains
testserver
testserver.mail.com
mail.com
testserver.mail.com

Step2 : genericstable file should be below format

[root@testserver mail]# cat /etc/mail/genericstable


@testserver.mail.com auth_mail_id@relaydomain.com
@mail.com auth_mail_id@relaydomain.com

Map the genericstable by running below command.


# makemap hash /etc/mail/genericstable < /etc/mail/genericstable

Here,
auth_mail_id@relaydomain.com    : Change to your relay server authentication mail id
@testserver.mail.com                      : Your smtp server name
testuser@remotetest.com                : Where you want to send mails
oratest@testserver.mail.com           : smtp server mail id

Now mail will be accepted by relay server.