postfix part 7 - Setting up Mailwatch for Mailscanner/postfix



MailWatch for MailScanner is a open source or free web-based front-end to Mailscanner that use to displays the inbound/outbound mail queue, spam, viruses and blocked content on each page header. MailWatch has been written in PHP, MySQL and JpGraph. By using Mailwatch, it allows you to delete, release or run sa-learn across any messages that was quarantined. This post describes how to setup MailWatch on CentOS 6.3 and assumed that you already installed MailScanner and postfix.

1. Install required php and mysql :
[root@mx1 ~]# yum install httpdphpmysql-server mysqlphp-gdphp-mysql -y

2. Modify the php.ini :
[root@mx1 ~]# vim /etc/php.ini

PHP should have the following set in php.ini
short_open_tag = On
safe_mode = Off
register_globals = Off
magic_quotes_gpc = On
magic_quotes_runtime = Off
session.auto_start = 0

3. Download the latest version from mailwatch.sourceforge.net :
[root@mx1 ~]# wget http://sourceforge.net/projects/mailwatch/files/mailwatch/1.1.5.1/mailwatch-1.1.5.1.tar.gz

4. Extract downloaded mailwatchpackage :
[root@mx1 ~]# tar xzvf mailwatch-1.1.5.1.tar.gz

5. Start mysqlservice :
[root@mx1 ~]# servicemysqld start

6. Enter extracted mailwatch-x.xdirectory :
[root@mx1 mailwatch-1.1.5.1]# ls
CHANGELOG   fix_quarantine_permissions  LICENSEmailscanner               Remote_DB.txt  upgrade.php  USER_FILTERS
create.sql  INSTALLluserMailScanner_perl_scripts  tools          UPGRADING
[root@mx1 mailwatch-1.1.5.1]# mysql -p <create.sql

7. Create the database and import create.sql. The following commands below should be run as the ‘root’ :
[root@mx1 mailwatch-1.1.5.1]# mysql -p <create.sql
Enter password:

8. Login to mysql as a root :
[root@mx1 mailwatch-1.1.5.1]# mysql -u root -p
Enter password:


9. Proceed to create a MySQL user and then set password and configure MailScanner for SQL logging :
mysql> GRANT ALL ON mailscanner.* TO mailwatch@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT FILE ON *.* TO mailwatch@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mailscanner        |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)


10. Edit MailWatch.pm and change the database values accordingly :
a. Enter to the perl_scripts’sfolder :
[root@mx1 mailwatch-1.1.5.1]# cdMailScanner_perl_scripts
[root@mx1 MailScanner_perl_scripts]# pwd
/root/mailwatch-1.1.5.1/MailScanner_perl_scripts
b. Edit MailWatch.pm :
[root@mx1 MailScanner_perl_scripts]# vim MailWatch.pm
c.Modify this as necessary for your configuration
my($db_name) = 'mailscanner';
my($db_host) = 'localhost';
my($db_user) = 'mailwatch';
my($db_pass) = 'password';
11. Move MailWatch.pm to /usr/lib/MailScanner/MailScanner/CustomFunctions :
[root@mx1 MailScanner_perl_scripts]# cp MailWatch.pm /usr/lib/MailScanner/MailScanner/CustomFunctions


12. Create a MailWatch web user. This user will able to monitor the mailscanner through MailWatch web interface.
[root@mx1 ~]# mysqlmailscanner -u mailwatch -p
Enter password:

mysql>INSERT INTO users SET username = 'admin', password = md5('password'), fullname = 'MAilwatch Administrator', type ='A';
 
Query OK, 1 row affected (0.00 sec)

13. Install &Configure MailWatch :
a. Enter to mailwatch directory :
[root@mx1 ~]# cd mailwatch-1.1.5.1
b. Move mailscanner folder for web root folder. For apache, default root folder is /var/www/html :
[root@mx1 mailwatch-1.1.5.1]# mvmailscanner /var/www/html/
c. Enter to mailscanner folder in web root directory :
[root@mx1 ~]# cd /var/www/html/mailscanner

d. Verify and check the permissions of /var/www/html/mailscanner/images and /var/www/html/images/cache. The permissions and ownerships should be as below :
[root@mx1 mailscanner]# chownroot:apache images
[root@mx1 mailscanner]# chmodug+rwx images
[root@mx1 mailscanner]# chownroot:apache images/cache
[root@mx1 mailscanner]# chmodug+rwx images/cache
14. Create conf.php by copying conf.php.example. Edit the values to any details as you created earlier :
a. Copy the conf.php :
[root@mx1 mailscanner]# cpconf.php.exampleconf.php
b. Open conf.php :
[root@mx1 mailscanner]# vimconf.php
c. Edit the details as below :
define('DB_TYPE', 'mysql');
define('DB_USER', 'mailwatch');
define('DB_PASS', 'password');
define('DB_HOST', 'localhost');
define('DB_NAME', 'mailscanner');
15. Before setup the mailscanner, make sure it’s Stopped. Run 3 to 4 times to ensure the mailscanner completely stop. The status will FAILED if mailscanner completely stop.
[root@mx1 ~]# serviceMailScanner stop
Shutting down MailScanner daemons:
MailScanner:                                      [  OK  ]
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
[root@mx1 ~]# serviceMailScanner stop
Shutting down MailScanner daemons:
MailScanner:                                      [  OK  ]
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
[root@mx1 ~]# serviceMailScanner stop
Shutting down MailScanner daemons:
MailScanner:                                      [  OK  ]
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
[root@mx1 ~]# serviceMailScanner stop
Shutting down MailScanner daemons:
MailScanner:                                      [  OK  ]
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
[root@mx1 ~]# serviceMailScanner stop
Shutting down MailScanner daemons:
MailScanner:                                      [FAILED]
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
16. Edit /etc/MailScanner/MailScanner.conf
[root@mx1 ~]# vim /etc/MailScanner/MailScanner.conf
Make sure that the following options are set:
 Always Looked Up Last = &MailWatchLogging
 Detailed Spam Report = yes
 Quarantine Whole Message = yes
 Quarantine Whole Message As Queue Files = no
 Include Scores InSpamAssassin Report = yes
 Quarantine User = root
 Quarantine Group = apache (this should be the same group as your web server)
 Quarantine Permissions = 0660
17. Start MailScanner :
[root@mx1 ~]# serviceMailScanner start
Starting MailScanner daemons:
incoming postfix:                                 [  OK  ]
outgoing postfix:                                 [  OK  ]
MailScanner:                                      [  OK  ]
18. Restart httpdservice :
[root@mx1 ~]# servicehttpd restart
19. Make sure all the related service such as httpd, mysql and MailScanner configured to start at boot :
[root@mx1 ~]# chkconfigmysqld on
[root@mx1 ~]# chkconfighttpd on
[root@mx1 ~]# chkconfigMailScanner on
[root@mx1 ~]# chkconfigspamassassin on
[root@mx1 ~]# chkconfig postfix on
20. Check the mail log.
[root@mx1 ~]# tail -f /var/log/maillog
Mar  5 22:14:42 mx1 MailScanner[1718]: Using locktype = flock
Mar  5 22:14:43 mx1 MailScanner[1697]: Requeue: C297BA1C3F.AA850 to E7373A1DD6
Mar  5 22:14:43 mx1 postfix/qmgr[1687]: E7373A1DD6: from=<root@mx1.ehowstuff.local>, size=609, nrcpt=1 (queue active)
Mar  5 22:14:43 mx1 MailScanner[1697]: Uninfected: Delivered 1 messages
Mar  5 22:14:43 mx1 MailScanner[1697]: Deleted 1 messages from processing-database
Mar  5 22:14:43 mx1 MailScanner[1697]: Logging message C297BA1C3F.AA850 to SQL
Mar  5 22:14:43 mx1 postfix/local[1768]: E7373A1DD6: to=<root@mx1.ehowstuff.local>, orig_to=, relay=local, delay=166894, delays=166894/0.13/0/0.02, dsn=2.0.0, status=sent (delivered to mailbox)
Mar  5 22:14:43 mx1 postfix/qmgr[1687]: E7373A1DD6: removed
Mar  5 22:56:25 mx1 postfix/postfix-script[1869]: fatal: the Postfix mail system is already running
Mar  5 23:01:08 mx1 update.bad.phishing.sites: Delaying cron job up to 600 seconds

21. Login to mailwatch web interface :



5.9.240.232/mailscanner
 
                                 Solution   if you get error !!!  :-                   
Please verify read permissions on /var/spool/postfix/hold and /var/spool/postfix/incoming
Do-check permissions

sudo chown postfix:apache /var/spool/postfix/incoming
sudo chown postfix:apache /var/spool/postfix/hold
sudo chmod 740 /var/spool/postfix/incoming
sudo chmod 740 /var/spool/postfix/hold


cd /var/spool/MailScanner/

chown -R postfix.clam *
chmod -R 750 *

# ls -ltrh

total 12K
drwxr-x---  2 postfix  clam   4.0K Jul 16 06:11 spamassassin
drwxr-x--- 14 postfix  apache 4.0K Aug  5 01:58 quarantine
drwxr-x---  9 postfix  clam   4.0K Aug  5 01:59 incoming


For ubuntu 14.04LTS
# ls -l /var/spool/MailScanner
total 16
drwxrwx---  2 postfix clamav   4096 Apr  6 16:24 archive
drwxrwx--- 29 postfix clamav   4096 Jun  1 12:32 incoming
drwxr-x---  4 postfix www-data 4096 May 28 16:33 quarantine
drwxr-x---  2 postfix clamav   4096 Apr 12 01:39 spamassassin



http://www.netmium.com.au/category/how-tos/

Postfix ip rotation

[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.180
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.181
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.182
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.183
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.184
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.185
[root@mail2 ~]# iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth1 -m statistic --mode nth --every 7 -j SNAT --to-source  192.168.140.186

for 7 ip address 180-186
change --> every _#num of ip__

md5sum check compare

# md5sum  file_A file_B

lkjsdf98sd7fsdkjfnsdf98s7d    file_A
joiuiuyiuwe7weiury8iujsdCj    file_B      
 = = =  = = = = = = =  = = = = =   = = =  =
To check /verify the md5sum comparision
= = = = ==  = = =  == = =  = = =  = =  = =
# md5sum  file_A file_B  > md5summary.file


#md5sum -c md5summary.file

file_A:  OK
file_B:  OK

displays ok if md5sum matches.

Linux boot process and Grub2 Fundas

Highlevel boot stages:-

  1. The machine’s BIOS or boot firmware loads and runs a boot loader.
  2. The boot loader finds the kernel image on disk, loads kernel into memory and starts it. 
  3. The kernel initializes the devices and its drivers. 
  4. The kernel mounts the root filesystem.
  5. The kernel starts a program called init with a process ID of 1. This point is the user space start.
  6. init sets the rest of the system processes in motion. 
  7. init starts a process allowing you to log in, usually at the end or near the end of the boot sequence.

Running journalctl -k displays the messages from the current boot, but you can view previous boots with the -b

grub2 supports various filesystems like Linux ext2/ext3/ext4, LVM ,btrfs, zfs etc.(reference) with the help of its own drivers. GRUB2 disk drivers are essential for the boot loader's functionality. They allow GRUB2 to access configuration files, such as the grub.cfg file, which contains important boot configuration parameters. Additionally, the disk drivers enable GRUB2 to locate and load the kernel image, initial RAM disk (initrd), and any other necessary boot files.

To determine if your system uses a BIOS or UEFI, run command efibootmgr. If you get a list of boot targets, your system has UEFI otherwise its bios.

GRUB2 uses its own set of drivers to enable communication with various hardware components during the boot process. These drivers are specifically designed for GRUB and are responsible for tasks such as reading the filesystem, accessing storage devices, and interacting with input/output devices. GRUB2 drivers are typically lightweight and have limited functionality compared to the drivers used by the kernel.

  1. Power-On: When the power button is pressed, the system's power supply is activated, and the firmware (UEFI or BIOS) initializes the hardware components.
  2. Firmware Initialization: The firmware performs a Power-On Self-Test (POST) to check the hardware components' functionality, such as the CPU, memory, storage devices, and peripherals. It also initializes system buses and interfaces.
  3. Boot Firmware: If the system uses UEFI firmware, the UEFI firmware takes control. It loads UEFI drivers, initializes hardware, and prepares the system for the boot process. If the system uses legacy BIOS, the BIOS performs similar tasks.
  4. Bootloader: The bootloader, usually GRUB2 (Grand Unified Bootloader), is loaded. GRUB2 presents a boot menu to the user if multiple operating systems are installed. The user can select the desired entry, or the default entry is automatically booted.
  5. Kernel Loading: The bootloader locates and loads the Linux kernel (vmlinuz) into memory. The kernel is the core of the operating system that manages hardware resources, provides system services, and initializes essential components.
  6. Initial RAM Disk (initrd): The bootloader also loads an initial RAM disk (initrd or initramfs) into memory. The initrd contains essential modules, drivers, and scripts required for early system initialization. It allows the kernel to access necessary drivers and file systems to mount the root file system.
  7. Kernel Initialization: The kernel is decompressed and starts executing. It initializes the system by setting up various components, such as the memory manager, CPU scheduler, device drivers,  and file systems.
  8. udev: The kernel starts udev (userspace device manager), which detects and configures hardware devices in the system. udev assigns device names (like /dev/sda for storage devices) and loads the necessary device drivers.
  9. Mounting the Root File System: The kernel mounts the root file system, which contains the main Ubuntu installation. The root file system can be on a variety of storage devices, such as hard drives, solid-state drives, or network-mounted storage.
  10. Init System: The init system is started, which is responsible for initializing user-space processes and managing system services. In modern distro, the default init system is systemd. The init system executes a series of startup scripts and starts essential system services.
  11. User Space Initialization: Once the init system completes its tasks, user-space processes are started, including essential system daemons and services. These processes provide various functionalities, such as networking, logging, time synchronization, and graphical interface management (if a desktop environment is installed).
  12. Login Prompt or Graphical Display Manager: Finally, the system is ready to present a login prompt in the console or a graphical login screen through a display manager

Replication Tips and Tricks in MySQL

Replication Tips and Tricks in MySQL

In March's "LAMP Post" column, we started to look at MySQL's replication subsystem. We covered how replication works, as well as putting it to use by configuring the master and slave(s). This month, in this inaugural "MySQL" column, let's spend some time looking at the lesser known aspects of MySQL replication, including filtering and log inspection.


In March’s “LAMP Post” column, we started to look at MySQL’s replication subsystem. We covered how replication works, as well as putting it to use by configuring the master and slave(s). This month, in this inaugural “MySQL” column, let’s spend some time looking at the lesser known aspects of MySQL replication, including filtering and log inspection.


Filtering on the Master


There are times when you’d rather not replicate all the data from a master to its slave(s). For instance, your master database server may contain test or pre-production databases and typically these databases, much like the /tmp directory on Linux, really don’t need to survive after a disaster. Rather than wasting the bandwidth and disk space to replicate them, you can tell MySQL to simply ignore them. You can accomplish this by adding one or more configuration directives to the my.cnf file on the master.


Let’s assume that you’re using the test database on your master, but don’t wish to log any changes to tables in test to the master’s binary log. Simple add a line like binlog-ignore -db=test to my.conf file. Of course, you’ll need to restart MySQL for the change to take effect. If you want to ignore multiple databases, either specify a list…



binlog-ignore-db=test,scratch



… or add one entry per database:



binlog-ignore-db=test

binlog-ignore-db=scratch



If, on the other hand, you’d rather provide a list of databases to replicate and let MySQL ignore the rest, use the binlog-do-db directive to specify them.



binlog-do-db=catalog

binlog-do-db=users

binlog-do-db=sessions



binlog-do-db tends to be the most practical if you have a small, fixed number of databases to replicate or when it’s likely that someone will be creating temporary databases on the master that need not be replicated.


Now, you may be wondering how MySQL decides what to do when filtering is involved. Typically, you’re not going to specify a database in every query you issue. You can do so by fully qualifying every table or column in dbname.tablename.colname format, but that’s tedious and not necessary.


Instead, most software connects to a specific database and uses that one database for the duration of the connection. In PHP, for example, you might issue a mysql_connect() call followed by a mysql_select_db() to set the default database for that connection. Or, if you’re using the mysql command-line client, you may specify a database name on the command-line or employ the USE command to switch databases after connecting, as in USE testdb;.


No matter how you do it, MySQL considers only the database you’ve selected as the default database when evaluating binary log filtering rules. While this works quite well 98 percent of the time, there may be times when you need to perform cross-database operations or when you’re lazy and change data in one database while actually using a different one as your default.


To make this more concrete, let’s assume you’ve connected to MySQL and are using the sessions database. If the last three binlog-do-db rules (above) are in effect and you issue a query like this…



DELETE FROM oldstuff.user_list



… MySQL will still write the query to the binary log. Why? Because you were connected to (or USEing) the sessions database, which is in the list of database you asked it to log changes to.


MySQL does not evaluate the query you’re executing when deciding whether to log it. Even though this query affected only a database that you asked it not to log, it doesn’t bother to notice.


The correct approach is to use the correct database when issuing queries that change data:



USE oldstuff

DELETE FROM user_list



Otherwise you’ll end up with a nasty surprise. Because the query was logged to the binary log, the slave’s I/O thread copies it to its relay log and the slave’s SQL thread attempts to execute it. However, odds are that the slave doesn’t have a copy of the oldstuff database (otherwise you’d probably have asked for it to be replicated), so the SQL thread will record an error in the MySQL error log and then stop executing queries from the relay log. You’ll then need to fix the problem.


The easiest solution is to ask the slave to skip ahead to the next query in the relay log and then continue executing:



SET SQL_SLAVE_SKIP_COUNTER = 1;

SLAVE START SQL_THREAD;



Then, of course, go find out what (or who) was too lazy to change databases when executing the DELETE in the first place.


Filtering on the Slave


So far, we’ve only considered filtering on the master’s end of replication. However, it’s also possible to apply filtering on the slave. This is important because you may need to have different policies for different slaves.


For example, your backup master may need to replicate everything that the master has, while your slaves that live 1,500 miles away need only a subset of the data. The good news is that you have quite a bit more flexibility on the slave’s side of things.


To start with, you can perform per-database filtering, just like on the master. The difference is that the directives begin with replicate rather than binlog. So, to allow the database users to replicate from a master, you could specify:



replicate-do-db=users



Or, to prevent replication of temporary, you could use:



replicate-ignore-db=temporary



But on the slave end you have even more granularity. Filtering (inclusive and exclusive) can be done down to the table level using these two directives…



replicate-do-table=dbname.tablename

replicate-do-ignore=dbname.tablename



… and to make things even more interesting, you can provide wildcard base “do” and “ignore” rules too.



replicate-wild-do-table=dbname.tablename

replicate-wild-ignore-table=dbname.tablename



In the wildcard directives, you may use the standard SQL wildcard characters (_ (“underscore”) for a single character and % for multiple characters) in both the database and table names.


Finally, you even have the option of rewriting the database name on the fly:



replicate-rewrite-db=oldname->newname



That tells the slave that any queries run in the oldname database on the master should be executed against newname on the slave.


One important aspect of slave-side filtering is that the slave has to see the queries before it can decide to either skip or execute them. That means slave filtering still uses up some of your network bandwidth. The slave’s I/O thread must copy all of the queries from the master’s binary log into the slave’s relay log. Only then can the slave’s SQL thread check each query against the “do” and “ignore” rules.


Log Inspection


Have you ever wondered what’s inside the binary log? In addition to the SQL for each query, the master records a few extra bits of metadata as well. You can use the mysqlbinlog tool to convert binary logs back into human- (and machine-) readable format.



$ mysqlbinlog binary-log.002



That command might produce output that looks like this (wrapped and reformatted for readability):



#040304 5:34:04 server id 103 log_pos

  32050 Intvar

SET INSERT_ID=277;



That first entry provides, as a comment, the date and time of the query, the id of the server it was first executed on, the log position, and the type of event. In this case, Intvar means that one of MySQL’s internal variables is being set — the INSERT_ID is used to tell a slave the auto-increment ID to be used in the next query it sees.



#040304 5:34:04 server id 103 log_pos

  32078 Query

thread_id=26993141 exec_time=0

  error_code=0

SET TIMESTAMP=1078407244;

insert into history values (NULL,

  1014193,20040303,0.5,0.5,0.5,0.5,0,1);



This second entry again provides some interesting metadata as a comment before the query.


In this case, since it’s a Query event, we also see the id of the thread that originally executed it, as well as the execution time (in seconds) and the error code.


Then we see a timestamp being set. The server records the time at which every query is executed. Finally, we see the actual query. The NULL is presumably going to be replaced by the insert id seen in the first entry.

Reset the MYSQL root password after error 1045 Cannot log in to the MySQL server

How to reset the MYSQL root password after error 1045 Cannot log in to the MySQL server

How to reset the MYSQL root password.
The MYSQL root is a different account with a different password than the Linux root. This tripped us up when we recently installed Mantis bug tracker and got a #1045 Cannot log in to the MySQL server error from PHPMYADMIN and the command line MYSQL login.
Here's how we reset the password on a Debian Linux system from an SSH command prompt.

Procedure

First check in /root/.my.cnf
below is permission
-rw-------.  1 root root       39 May 22 17:09 .my.cnf
cat /root/.my.cnf
[client]
password="p@ssw0rD&"
user=root
 
sudo /etc/init.d/mysql stop  

First stop MYSQL. Any part of your site that uses the database will return an error, so be ready to proceded quickly.
sudo mysqld_safe --skip-grant-tables --skip-networking &

Start MYSQL in safe mode with with passwords and network access disabled.
  • --skip-grant-tables option disables password protection for the database
  • --skip-networking disables network access to prevent attacks while passwords are disabled
  • & runs the process in the background
You might have to hit space to return to the command prompt.
sudo mysql -u root
Login as root, a password is not required.

MYSQL> use mysql;  ##note##optional
MYSQL> UPDATE user SET Password=PASSWORD('new_pass') WHERE User='root';
MYSQL> FLUSH PRIVILEGES;
MYSQL> exit;
Run these SQL statements at the MYSQL> prompt. Don't type MYSQL>...
  1. First set the new password for the root user. replace new_pass with your password
  2. Flush the privileges to reset everything
  3. Quit the MYSQL prompt
sudo /etc/init.d/mysql stop
Now stop MYSQL again.
sudo /etc/init.d/mysql start
Start MYSQL in normal mode.
sudo mysql -u root -p
To test the new password login as root with the password (-p) option enabled.
That's it, you're done!

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