[HOW TO] configure MySQL master slave replication

Hello

Yesterday I have been working on MySQL Replication between two servers. And I think you will need it as a reference article. Because of I also re-search a lot before starting.

Some question:
What is MySQL replication?
How to do?
How is Master? is Slave?
How to configure?
MySQL replication for non-standard port?
How to stop MySQL replication?
How it works?

Ok, let's start!

What is MySQL replication?
MySQL replication is a process that allows you to easily maintain multiple copies of a MySQL data by having them copied automatically from a master to a slave database

How to do?
It has two components: master & slave. They have to configure on two servers. The mysql data will be transferred real time between them.

How is Master? is Slave?
Master: it is running on production in your company. The data will be transferred from here to slave server. Slave: The data will be transferred to here. In case of disaster, this will be take over as master (primary database).

How to configure?

MySQL replication for non-standard port?

How to stop MySQL replication?

How it works?


[HOW TO] 2015/10/12 15:39:35 [error] 30666#0: *5 open() "/home/www/html/index.html" failed (13: Permission denied), client: 127.0.0.1, server: **.vn, request: "GET /index.html HTTP/1.1", host: "*.**.vn"

I am creating the backup server to prepare in case of disaster. It seems well until I can not get the index.html. I use nginx as web server.

What happened? Afterwards I come to /var/log/nginx/error.log to totally view.

2015/10/12 15:39:35 [error] 30666#0: *5 open() "/home/www/html/index.html" failed (13: Permission denied), client: 127.0.0.1, server: **.vn, request: "GET /index.html HTTP/1.1", host: "*.**.vn"

Humhumhum nginx has a thorny permission. But where is it?

Because of I chowned "web root server" in nginx configuration is:
$chown -R nginx.nginx /home/www
$chmod -R /home/www

I do not know exactly what happened? Okay, I need to review with mine knowledge. Oh SELINUX, maybe it is root cause of issues. And it right!

$vi /etc/selinux/config


# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

I need to edit as below:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

And I go to reboot the server. Happily, I can open the web page.

Thank you for seeing, see you soon.

Thank you for reading this article, please a comment if you are interested.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success


[HOW TO] Exporting and Importing An Individual MySQL Table

In moving databases from development to production it is sometimes necessary to export individual tables so that they can be imported into another database.
Exporting the Table
To export the table run the following command from the command line:
“mysqldump -p – –user=username dbname tableName > tableName.sql
This will export the tableName to the file tableName.sql.
[NOTE: there should be no space between the two dashes, but I have to write it that way so that it display properly].
Importing the TableTo import the table run the following command from the command line:
mysql -u username -p -D dbname < tableName.sql
The path to the tableName.sql needs to be prepended with the absolute path to that file. At this point the table will be imported into the DB and you are ready to go!
I ran into this issue when attempting to add new tables to my database. I am unable to run the “LOAD DATA INFILE” command, that I had previously used to populate tables, because Webfaction does not give the permission to run the command. Therefore the simplest solution was to export a table from the MySQL database on my personal machine and then import it to the database on the Webfaction server, using the export/import commands seen above.
Hope this helps someone out with exporting individual tables and as always if any clarification is needed or I missed something feel free to let me know.
–Steve
Thank you Steve :)


[HOW TO] What is net.ipv4.conf.default.rp_filter

/usr/share/doc/kernel-doc-2.6.32/Documentation/networking/ip-sysctl.txt

rp_filter - INTEGER
        0 - No source validation.
        1 - Strict mode as defined in RFC3704 Strict Reverse Path 
            Each incoming packet is tested against the FIB and if the interface
            is not the best reverse path the packet check will fail.
            By default failed packets are discarded.
        2 - Loose mode as defined in RFC3704 Loose Reverse Path 
            Each incoming packet's source address is also tested against the FIB
            and if the source address is not reachable via any interface
            the packet check will fail.

        Current recommended practice in RFC3704 is to enable strict mode 
        to prevent IP spoofing from DDos attacks. If using asymmetric routing
        or other complicated routing, then loose mode is recommended.

        The max value from conf/{all,interface}/rp_filter is used 
        when doing source validation on the {interface}.

        Default value is 0. Note that some distributions enable it
        in startup scripts.