Postfix part 6 courier authdaemond,pop/ pops ,imap/imapssl ,Squirrelmail

yum groupinstall  'Development Tools'
yum install expect
yum install gdbm*
yum install libtool-ltdl libtool-ltdl-devel -y

wget ftp://ftp.muug.mb.ca/mirror/redhat/redhat/linux/6.2/en/os/i386/RedHat/RPMS/gdbm-devel-1.8.0-3.i386.rpm

yum install gdbm-devel-1.8.0-3.i386.rpm
yum install gdb

                Download Courier AUTHLIB                   
wget http://cznic.dl.sourceforge.net/project/courier/authlib/0.66.1/courier-authlib-0.66.1.tar.bz2
tar xjvf courier-authlib-0.66.1.tar.bz2
cd /home/salman/courier-authlib-0.66.1
./configure                        #nonroot user
make install                     # root user
make install-configure      # root user

[root@server1 sbin]# pwd
/usr/local/sbin
[root@server1 sbin]# ls -al
total 152
drwxr-xr-x.  2 root root  4096 Jun 21 23:52 .
drwxr-xr-x. 12 root root  4096 Jun 21 23:52 ..
-rwxr-xr-x.  1 root root   433 Jun 21 23:52 authdaemond
-rwxr-xr-x.  1 root root 10933 Jun 21 23:52 authenumerate
-rwxr-xr-x.  1 root root 10806 Jun 21 23:52 authpasswd
-rwxr-xr-x.  1 root root 15304 Jun 21 23:52 authtest
-rwxr-xr-x.  1 root root 29157 Jun 21 23:52 courierlogger
-rwxr-xr-x.  1 root root  3293 Jun 21 23:52 makeuserdb
-rwxr-xr-x.  1 root root  1620 Jun 21 23:52 pw2userdb
-rwxr-xr-x.  1 root root  4792 Jun 21 23:52 userdb
-rwxr-xr-x.  1 root root 48011 Jun 21 23:52 userdbpw
-rwxr-xr-x.  1 root root  2095 Jun 21 23:52 userdb-test-cram-md5

The entire process installs the binaries and configuration files. Binary named “authdaemond” under “/usr/local/sbin” directory is executing as the authlib daemon. This consults the /usr/local/etc/authlib/authdaemonrc configuration file.

Starting the authlib daemon            
  [root@server1 ~]# /usr/local/sbin/authdaemond start
Starting authdaemond at startup     
# ln -s /usr/local/sbin/authdaemond /etc/init.d/
# ln -s /etc/init.d/authdaemond   /etc/rc.d/rc3.d/S24authdaemond

Installing courier imap (Installs the IMAP and POP3 service)
yum install openssl openssl-devel
\\\\\   As   Non Root user
                Download Courier IMAP                   
wget http://cznic.dl.sourceforge.net/project/courier/imap/4.15/courier-imap-4.15.tar.bz2

tar -xjvf courier-imap-4.15.tar.bz2
cd  courier-imap-4.15
./configure
make
# make install
# make install-configure


[root@server1 authlib]# pwd
/usr/local/etc/authlib
[root@server1 authlib]# ls
authdaemonrc  authdaemonrc.dist
The authdaemon consults authdaemonrc file ,we can change values like number of daemons and other performance related values
Starting authdaemond
# /usr/local/libexec/courier-authlib/authdaemond start


[root@server1 libexec]# pwd
/usr/lib/courier-imap/libexec
 [root@server1 libexec]# ./pop3d.rc start

allow necessary ports and disable selinux ,also check mynetworks,inet_interfaces= in main.cf

POP-SSL
Change the file /usr/lib/courier-imap/etc/pop3d.cnf  contents like email, CN etc for certificate
 Run the script:-
#./usr/lib/courier-imap/share/mkpop3dcert
cert file will be in same dir of script
#ls -l /usr/lib/courier-imap/share/
 total 24
drwxr-xr-x. 4 root root 4096 Jun 22 00:25 man
-rwxr-xr-x. 1 root root 1292 Jun 24 22:56 mkdhparams
-rwxr-xr-x. 1 root root 2319 Jun 24 22:56 mkimapdcert
-rwxr-xr-x. 1 root root 2179 Jun 24 22:56 mkpop3dcert
-rw-------. 1 root root 5463 Jun 24 23:00 pop3d.pem

To run pop-ssl we have to run the script /usr/lib/courier-imap/libexec/pop3d-ssl.rc
=>
# ./pop3d-ssl.rc start

TO enable pop3 and pop3ssl at runlevel/ startup we have to create sym-links to /etc/init.d/  and rc.d/
 for   pop
 [root@server1 ~]# ln -s /usr/lib/courier-imap/libexec/pop3d.rc /etc/init.d/
for pop-SSL
[root@server1 ~]# ln -s /usr/lib/courier-imap/libexec/pop3d-ssl.rc  /etc/init.d/
#ls -l /etc/init.d/
 ..
lrwxrwxrwx. 1 root root    38 Jun 24 23:18 pop3d.rc -> /usr/lib/courier-imap/libexec/pop3d.rc 
lrwxrwxrwx. 1 root root    42 Jun 24 23:20 pop3d-ssl.rc -> /usr/lib/courier-imap/libexec/pop3d-ssl.rc
..
...
above will only create shortcut now creating symlink to symlink @ runlevel directory thats /etc/rc.d/
[root@server1 ~]# ls /etc/rc.d/
init.d/     rc0.d/      rc2.d/      rc4.d/      rc6.d/      rc.sysinit 

rc          rc1.d/      rc3.d/      rc5.d/      rc.local 

Running in runlevel 3 :

ln -s /etc/init.d/pop3d-ssl.rc /etc/rc.d/rc3.d/S20pop3dssl
the name should be unique "S20pop3dssl"   , note=>S=start 

Starting pop and pop-ssl
[root@server1 rc3.d]# ./S21pop3d start
[root@server1 rc3.d]# ./S20pop3dssl start
 Check if port is listening by netstat -antpl

Setting up imap and imap ssl to run at runlevel 3 at start up
ln -s /usr/lib/courier-imap/libexec/imapd.rc /etc/init.d/
ln -s /etc/init.d/imapd.rc /etc/rc.d/rc3.d/S22imapd
ln -s /usr/lib/courier-imap/libexec/imapd-ssl.rc /etc/init.d/ln -s /etc/init.d/imapd-ssl.rc /etc/rc.d/rc3.d/S23imapssld



Install squirrel mail
#yum install httpd   mod_ssl
#yum install squirrelmail
To  deal with ERROR: Could not complete request. Query: CREATE "Sent" Reason Given: Invalid mailbox name. Follow below steps:-
      * If you use Courier and SquirrelMail Fedora RPM (1.4.4-2) - remove $default_folder_prefix override from /etc/squirrelmail/config_local.php
#vim /etc/squirrelmail/config_local.php
<?php
/**
 * Local config overrides.
 *
 * You can override the config.php settings here.
 * Don't do it unless you know what you're doing.
 ....
#comment below line if it is not
#$default_folder_prefix         = '';
?>
Configuring squirrel mail :-
cd /usr/share/squirrelmail/config
 [root@server1 config]# ./conf.pl
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages
D.  Set pre-defined settings for specific IMAP servers
C   Turn color off
S   Save data
Q   Quit

Command >> D
SquirrelMail Configuration : Read: config.php
---------------------------------------------------------
Please select your IMAP server:
    bincimap    = Binc IMAP server
    courier     = Courier IMAP server
    cyrus       = Cyrus IMAP server
    dovecot     = Dovecot Secure IMAP server
    exchange    = Microsoft Exchange IMAP server
    hmailserver = hMailServer
    macosx      = Mac OS X Mailserver
    mercury32   = Mercury/32
    uw          = University of Washington's IMAP server
    gmail       = IMAP access to Google mail (Gmail) accounts
    quit        = Do not change anything
Command >>courier    <press enter>

Configuring  SSL for squirrelmail
Generating private key :-
openssl genrsa -des3 -out privatekey22.pem 2048
Generate SSL certificate
openssl req -new -key privatekey22.pem -out self-ssl.csr

Remove passphrase for nginx (optional)

# openssl rsa -in privatekey22.pem -out privatekey.key    

# 
openssl x509 -req -days 365 -in self-ssl.csr -signkey privatekey.key -out selfsign.crt  


#vim /etc/httpd/conf.d/ssl.conf
 ##replace below value with --
SSLCertificateFile   /etc/httpd/ssl/selfsign.crt
SSLCertificateKeyFile /etc/httpd/ssl/privatekey.key


#service httpd start
#chkconfig httpd on


 




resync master-slave replication

root@rsus [~]# ls -al /root/
-rw-------   1 root root     39 Dec 18  2013 .my.cnf
 root@rs03us [~]# cat .my.cnf
[client]
password="#$6pqo<4"
user=root



=====================

This is the full step-by-step procedure to resync a master-slave replication from scratch:
At the master:
RESET MASTER; FLUSH TABLES WITH READ LOCK; SHOW MASTER STATUS;
And copy the values of the result of the last command somewhere.
Wihtout closing the connection to the client (because it would release the read lock) issue the command to get a dump of the master:
mysqldump -uroot -p --all-databases > /a/path/mysqldump.sql

NOTE: With INNODB typed dabatase and other complex column types like BLOB and DATE defined, recommend using the following switches: --opt --single-transaction --comments --hex-blob --dump-date --no-autocommit --all-databases

Now you can release the lock, even if the dump hasn't end. To do it perform the following command in the mysql client:
UNLOCK TABLES;
Now copy the dump file to the slave using scp or your preferred tool.
At the slave:
Open a connection to mysql and type:
STOP SLAVE;
Load master's data dump with this console command:
mysql -uroot -p < mysqldump.sql
Sync slave and master logs:
RESET SLAVE; CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;
Where the values of the above fields are the ones you copied before.
Finally type
START SLAVE;
And to check that everything is working again, if you type
SHOW SLAVE STATUS;
you should see:
Slave_IO_Running: Yes Slave_SQL_Running: Yes

= = = = = = Error : mysql out of resources = = = = = = = 
The mysql error:  Out of resources when opening file... (Errcode: 24)   indicates that the number of files that msyql is permitted to open has been exceeded. 
 Last_SQL_Error: Error 'Out of resources when opening file './thssedu_scl/' (Errcode: 24)' on query. Default database: 'thssedu_scl'. Query: 'ALTER TABLE thss_bsk_pdf_manager_cats CHANGE COLUMN id `id` int(11) NOT NULL AUTO_INCREMENT'

 
root@localhost [~]# mysql -e 'show variables;' | grep open
have_openssl    DISABLED
innodb_open_files    300
open_files_limit    1024    
table_open_cache    400


we have to increase that value:

vim /etc/my.cnf
[mysqld]
open_files_limit = 2024
 
 Then be sure to restart mysql with:   sudo /etc/init.d/mysql restart
A good rule of thumb is to take the current number of files and add 1000 to it. If this doesn't help, add some more.  This number affects the amount of memory that MySQL uses, so setting it to a very high number is not a good idea.

 

Rebuild your the default CentOS yum.repo.d folder

On a dev machine, somehow, I managed to erase my yum.repo.d contents. I wanted to rebuild the repo files back to their default. First you need to figure out what version you are using:
  • cat /etc/redhat-release
Then visit the correct release at : http://vault.centos.org/
  • navigate to the correct os/x86_64/CentOS/ directory (could be os/x86_64/CentOS/ i386/)
  • Download the following files to the server:
    • wget http://vault.centos.org/5.x/os/x86_64/CentOS/centos-release-notes-5.x-0.x86_64.rpm
    • wget http://vault.centos.org/5.x/os/x86_64/CentOS/centos-release-5-x.el5.centos.x86_64.rpm
  • Then install the two rpms:
    • rpm -Uivh *.rpm
Should be back to the original shipping repo files.

openssl update

#yum reinstall openssl
 = = == = == == == == == = =
To manually compile OpenSSL, do as follows:
$ cd /usr/src

$ wget https://www.openssl.org/source/openssl-1.0.1g.tar.gz -O openssl-1.0.1g.tar.gz

$ tar -zxf openssl-1.0.1g.tar.gz

$ cd openssl-1.0.1g

$ ./config

$ make

$ make test

$ make install

$ openssl version
 
If it shows the old version, do the steps below.
$ mv /usr/bin/openssl /root/ $ ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl openssl version OpenSSL 1.0.1g 7 Apr 2014
 

Multiple MySQL Instance on linux



Create multiple mysql instance in CentOS 6.5 and Red Hat 6.5. Multiple instance means in single system we can create multiple MySQL server. These multiple mysql server will run in different ports.
Note:install mysql server
 
To create multiple MySQL instance,follow the given below steps
Login as a root in a system
Step (1): Create a new MySQL data directory.
mkdir -p /var/lib/mysql2

Step 2: Now give permission and ownership .Here we are taking ownership and permission reference from original /var/lib/mysql data directory.
Note: /var/lib/mysql is bydefault data directory path

chmod --reference /var/lib/mysql /var/lib/mysql2
chown --reference /var/lib/mysql /var/lib/mysql2
Step 3: Now create a new my2.cnf file and paste the below given contents. We will run the new mysql instance in port no. 3337.

Copy the my.cnf file and make it blank
cp -p /etc/my.cnf /etc/my2.cnf
Now edit with vi editor or your favorite editor.
vi /etc/my2.cnf

Edit in [mysqld] and [mysqld_safe] section as given below in my2.cnf file

[mysqld]
datadir=/var/lib/mysql2
socket=/var/lib/mysql/mysql2.sock
port=3337

[mysqld_safe]
log-error=/var/log/mysqld2.log
pid-file=/var/run/mysqld/mysqld2.pid

Step 4: Now install the database in the new mysql data directory
mysql_install_db --user=mysql --datadir=/var/lib/mysql2

Below given is the output from my server (as a Reference)
[root@localhost etc]# mysql_install_db --user=mysql --datadir=/var/lib/mysql2
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

= = = = = = = = = = = = = = = = =
Step 5: Now the new instance is ready.Now in below section we will learn how to start,stop the mysql instance and how to connect with it.
Note: new mysql instance is running in port no. 3337 as per this tutorial
To start new mysql instance,use below given command
mysqld_safe --defaults-file=/etc/my2.cnf &
Now check the port no. 3337 is listening or not
netstat -tanp |grep 3337
To connect new mysql instance
Syntax:  mysql -u username -p -h 127.0.0.1 -P port-no.
As per our tutorial:
mysql -u root -p -h 127.0.0.1 -P 3337
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.71 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
It will ask password,hit enter because root password is blank
Now set root password (It is upto your choice, for security reason it is recommended).You can see mysql prompt.
mysql > use mysql;
mysql > update user set password=PASSWORD("Give-here-new-root-PASSWORD") where user='root';
mysql > flush privileges;
mysql > exit
Recheck if MySQL root password is applied or not

mysql -u root -p -h 127.0.0.1 -P 3337
To stop new mysql instance use below given command
mysqladmin -S /var/lib/mysql/mysql2.sock shutdown -p
Note: By using same method you can create multiple instance ,only you have to change the values like mysql2 to mysql3 or so on