Friday, July 4, 2014

Postfix : Port 25 is not opened in Linux, opened in firewall

Port 25 is not in opened port list

If you have installed postfix mail server and port 25 is not visible in opened port list. 
Have you opened it in iptables ( firewall ) ?
The line should be included in iptables.
-A INPUT -p tcp -m state -m tcp --dport 25 --state NEW -j ACCEPT

Yes, Yes, it is opened in firewall. I do not want this solution. 
Okay Okay

Open configuration file of postfix. /etc/postfix/main.cf
Check the parameter inet_interface, it should be
inet_interface=all
Now restart postfix again. It will be listed in opened port list.

lvm device not found in /dev/mapper

lvm device is missing. lvm Volume status is not available. Missing Volume.

If you are not able to find your logical volume (lvm device), check the status of the device or volume.
Run command
lvdisplay
If LV status is Not Available, it will not be listed in /dev/mapper or your lvm device directory.
Make the status available, Run command
vgchange -a y
It makes status available of all volumes.

Now the device will be visible in /dev/mapper or your lvm device directory.
Mount the device using
mount -t ext4 /path/of/the/lvm/device /path/of/mounted/location
Suppose I want to mount vg-lv_home in /home, I run
mount -t ext4 /dev/mapper/vg-lv_home /home
Now I can see all my files of the volume in /home

lvm commands not found

-bash: pvscan: command not found
-bash: lvdisplay: command not found
-bash: vgcreate: command not found
-bash: lvcreate: command not found
-bash: lvscan: command not found
-bash: pvdisplay: command not found
-bash: lvm: command not found

If you are using CentOS or fedora or RHEL and you are getting these errors again and again when you try to run lvm commands. It means lvm is not installed or corrupted on your system. Reinstall lvm again.
yum install lvm2
If it is not able to find lvm2 package and shows
No package lvm2 available.
It means your repositories do not have this package.
Enable appropriate repository like base, remi, rpmforge or epel and install it again.

If you have enabled all available repositories and still it shows "No package available."
Check the file /etc/yum.conf

The lvm2 package should not be there in exclude packages.
Repos do not list exclude packages and do not install them. If it is under exclude attribute, remove it and run install command again.
It should be installed.

Create Case insensitive databases and tables in mysql

Linux is case sensitive system. You can create Test or test or tesT files in same directory.
That's why you can create Test and teST both databases in mysql.
But if you do not want case sensitivity while creating databases and tables in mysql. Here is solution for you.

Add following attribute in the file my.cnf
lower_case_table_names = 1
Restart mysql.
It disables case sensitivity. Now you can not create linuxamination or Linuxamination or LinuXamination all three databases. You can create any one of three. Same rule is applicable for tables.

If you do not want this feature, remove this line or set the attribute 0.

Configure: error: not found. Please provide a path to MagickWand-config or Wand-config program. ERROR: `/tmp/pear/temp/imagick/configure --with-imagick' failed

/tmp/pear related errors while installing imagick

If you are facing this error in Ubuntu or Debian
sudo apt-get install libmagickwand-dev libmagickcore-dev
If you are facing this error in fedora or CentOS
sudo yum install imagemagick php-magickwand php-pecl-imagick

Install Imagick on Linux

Install Imagick on CentOS, fedora or RHEL
If you are using XAMPP, Run
sudo /opt/lampp/bin/pecl install imagick
If you get any error related to /tmp/pear, it means development packages are not installed in your xampp. Download and install latest version of xampp. It comes with devel packages or find and install devel packages of your version of xampp.

If you have installed httpd/mysqld on CentOS, fedora or RHEL, Run
sudo pecl install imagick
Click here and here to resolve error.

If it installs successfully, add line 
extension=imagick.so
in the file php.ini
Restart apache. 

Install Imagick on Ubuntu or Debian
If you are using XAMPP, Run
sudo /opt/lampp/bin/pecl install imagick
If you get any error related to /tmp/pear, it means development packages are not installed in your xampp. Download and install latest version of xampp. It comes with devel packages or find and install devel packages of your version of xampp.
If you have installed apache2/mysql on Ubuntu or Debian, Run
sudo pecl install imagick
Click here and here to resolve error.

If it installs successfully, add line 
extension=imagick.so
in the file php.ini
Restart apache.

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/imagick.so' - liblcms2.so.2: cannot open shared object file: No such file or directory in Unknown on line 0

Not able to install imagick on CentOS, fedora or RHEL
liblcms2.so.2: cannot open shared object file

Install following packages in RHEL, fedora or CentOS
yum install lcms2

mysql Error : Missing system table mysql.proxies_priv

To remove the error, run following command
sudo mysql_upgrade -u root -p
If your system does not identify mysql_upgrade, you can try these two commands.
mysqlcheck --no-defaults --check-upgrade --all-databases --auto-repair
mysql < fix_priv_tables

InnoDB: Database was not shut down normally!

mysql crashes frequently

Solution : 1
Restart your machine.

If it does not solve the problem and mysql crashes frequently with same error.

Solution : 2
Check attribute max_allowed_packet in the file my.cnf
max_allowed_packet=128M
OR
max_allowed_packet=256M

Restart mysql.
If it is not there, add it and restart mysql.

but if it does not solve the problem and mysql crashes frequently with same error.

Solution : 3
Repair all databases of mysql using following commands.
mysqlcheck --no-defaults --check-upgrade --all-databases --auto-repair
mysqlcheck --no-defaults --all-databases --fix-db-names --fix-table-names

If still your mysql crashes frequently.
Reinstall it again.

Allow / Block ssh / sftp for specific Users / Group

Allow ssh / sftp to selected users
If you want to give ssh / sftp privileges to certain users, here is the solution.
Add following line in the file /etc/sshd_config
AllowUsers username1 username2 username3
If you want to allow certain groups only, add following line in /etc/sshd_config
AllowGroups username1 username2 username3
Restart service ssh.

Block ssh / sftp for selected users
If you want to restrict certain users to access ssh / sftp, here is the solution.
Add following line in the file /etc/sshd_config
DenyUsers username1 username2 username3
If you want to block certain groups only, add following line in /etc/sshd_config
DenyGroups username1 username2 username3
Restart service ssh.

Extract an iso file in Linux using command line

Extract an iso file on terminal in Linux

Run following command
sudo mount -o loop "/path/of/iso/file.iso" /mnt
Example :
sudo mount -o loop "/home/user/Downloadsubuntu-12.04.3-desktop-i386.iso" /mnt


Now the iso file contents will be mounted in /mnt
You can copy them anywhere.
sudo cp -r /mnt /your/desired/destination/directory
Example :
sudo cp -r /mnt /home/user/Documents/files


If you do not want to use command line, you can extract it using Archive Manager.
Right click on the iso file and select "Extract here'.
If you have Archive manager, you can mount it using Archive Mounter and files will be opened as separate drive.