Tuesday, September 22, 2015

Replacing ifconfig with ip


f you’ve been around Linux long enough, you know tools come and go. This was assumed to be the case back around 2009 when the debian-devel mailing list announced plans on deprecating the net-tools package due to lack of maintenance. It is now 2015 and net-tools is still around. In fact, as of Ubuntu 14.10, you can still issue the ifconfig command to manage your network configuration.
However, in some instances (e.g., Ubuntu Docker container), the net-tools suite isn’t installed by default. This means the ifconfig command isn’t available. Although you can install net-tools with the command
sudo apt-get install net-tools
it is most often recommended to move forward with the command that has replaced ifconfig. That command is ip, and it does a great job of stepping in for the out-of-date ifconfig.
Thing is, ip is not a drop-in replacement for ifconfig. There are differences in the structure of the commands. Even with these differences, both commands are used for similar purposes. In fact, ip can do the following:
  • Discover which interfaces are configured on a system
  • Query the status of a network interface
  • Configure the network interfaces (including local loop-back, and Ethernet)
  • Bring an interface up or down
  • Manage both default and static routing
  • Configure tunnel over IP
  • Configure ARP or NDISC cache entry
With all of that said, let’s embark on replacing ifconfig with ip. I’ll offer a few examples of how the replacement command is used. Understand that this command does require admin privileges (so you’ll either have to su to root or make use of sudo — depending upon your distribution). Because these commands can make changes to your machine’s networking information, use them with caution.
NOTE: All addresses used in this how-to are examples. The addresses you will use will be dictated by your network and your hardware.
Now, on with the how-to.

Gathering Information

The first thing most people learn with the ifconfig command is how to find out what IP address has been assigned to an interface. This is usually done with the command ifconfig and no flags or arguments. To do the same with the ip command, it is run as such:
ip a
This command will list all interfaces with their associated information (Figure 1 above).
Let’s say you only want to see IPv4 information (for clarity). To do this, issue the command:
ip -4 a
Or, if you only want to see IPv6 information:
ip -6 a
What if you only want to see information regarding a specific interface? You can list information for a wireless connection with the command:
ip a show wlan0
You can even get more specific with this command. If you only want to view IPv4 on the wlan0 interface, issue the command:
ip -4 a show wlan0
You can even list only the running interface using:
ip link ls up

Modifying an Interface

Now we get into the heart of the command… using it to modify an interface. Suppose you wanted to assign a specific address to the first ethernet interface, eth0. With the ifconfig command, that would look like:
ifconfig eth0 192.168.1.101
With the ip command, this now looks like:
ip a add 192.168.1.101/255.255.255.0 dev eth0
You could shorten this a bit with:
ip a add 192.168.1.101/24 dev eth0
Clearly, you will need to know the subnet mask of the address you are assigning.
What about deleting an address from an interface? With the ip command, you can do that as well. For example, to delete the address just assigned to eth0, issue the following command:
ip a del 192.168.1.101/24 dev eth0
What if you want to simply flush all addresses from all interfaces? The ip command has you covered with this command:
ip -s -s a f to 192.168.1.0/24
Another crucial aspect of the ip command is the ability to bring up/down an interface. To bring eth0 down, issue:
ip link set dev eth0 down
To bring eth0 back up, use:
ip link set dev eth0 up
With the ip command, you can also add and delete default gateways. This is handled like so:
ip route add default via 192.168.1.254
If you want to get really detailed on your interfaces, you can edit the transmit queue. You can set the transmit queue to a low value for slower interfaces and a higher value for faster interfaces. To do this, the command would look like:
ip link set txqueuelen 10000 dev eth0
The above command would set a high transmit queue. You can play around with this value to find what works best for your hardware.
You can also set the Maximum Transmission Unit (MTU) of your network interface with the command:
ip link set mtu 9000 dev eth0
Once you’ve made the changes, use ip a list eth0 to verify the changes have gone into effect.

Managing the Routing Table

With the ip command you can also manage the system’s routing tables. This is a very powerful element of the ip command, and you should use it with caution.
Suppose you want to view all routing tables. To do this, you would issue the command:
ip r
Now, say you want to route all traffic via the 192.168.1.254 gateway connected via eth0 network interface: To do that, issue the command:
ip route add 192.168.1.0/24 dev eth0
To delete that same route, issue:
ip route del 192.168.1.0/24 dev eth0
This article should serve as merely an introduction to the ip command. This, of course, doesn’t mean you must immediately jump from ifconfig. Because the deprecation of ifconfig has been so slow, the command still exists on many a distribution. But, on the occasion of ifconfig finally vanishing from sight, you’ll be ready to make the transition with ease. For more detailed information on the ip command, take a look at the ip man page by issuing the command man ip from a terminal window.

How to Rescue a Non-booting GRUB 2 on Linux


Once upon a time we had legacy GRUB, the Grand Unified Linux Bootloader version 0.97. Legacy GRUB had many virtues, but it became old and its developers did yearn for more functionality, and thus did GRUB 2 come into the world.
GRUB 2 is a major rewrite with several significant differences. It boots removable media, and can be configured with an option to enter your system BIOS. It's more complicated to configure with all kinds of scripts to wade through, and instead of having a nice fairly simple /boot/grub/menu.lst file with all configurations in one place, the default is /boot/grub/grub.cfg. Which you don't edit directly, oh no, for this is not for mere humans to touch, but only other scripts. We lowly humans may edit /etc/default/grub, which controls mainly the appearance of the GRUB menu. We may also edit the scripts in /etc/grub.d/. These are the scripts that boot your operating systems, control external applications such as memtest and os_prober, and theming./boot/grub/grub.cfg is built from /etc/default/grub and /etc/grub.d/* when you run the update-grub command, which you must run every time you make changes.
The good news is that the update-grub script is reliable for finding kernels, boot files, and adding all operating systems to your GRUB boot menu, so you don't have to do it manually.
We're going to learn how to fix two of the more common failures. When you boot up your system and it stops at the grub> prompt, that is the full GRUB 2 command shell. That means GRUB 2 started normally and loaded the normal.mod module (and other modules which are located in /boot/grub/[arch]/), but it didn't find your grub.cfg file. If you see grub rescue> that means it couldn't find normal.mod, so it probably couldn't find any of your boot files.
How does this happen? The kernel might have changed drive assignments or you moved your hard drives, you changed some partitions, or installed a new operating system and moved things around. In these scenarios your boot files are still there, but GRUB can't find them. So you can look for your boot files at the GRUB prompt, set their locations, and then boot your system and fix your GRUB configuration.

GRUB 2 Command Shell

The GRUB 2 command shell is just as powerful as the shell in legacy GRUB. You can use it to discover boot images, kernels, and root filesystems. In fact, it gives you complete access to all filesystems on the local machine regardless of permissions or other protections. Which some might consider a security hole, but you know the old Unix dictum: whoever has physical access to the machine owns it.
When you're at the grub> prompt, you have a lot of functionality similar to any command shell such as history and tab-completion. The grub rescue> mode is more limited, with no history and no tab-completion.
If you are practicing on a functioning system, press C when your GRUB boot menu appears to open the GRUB command shell. You can stop the bootup countdown by scrolling up and down your menu entries with the arrow keys. It is safe to experiment at the GRUB command line because nothing you do there is permanent. If you are already staring at the grub> or grub rescue>prompt then you're ready to rock.
The next few commands work with both grub> and grub rescue>. The first command you should run invokes the pager, for paging long command outputs:
grub> set pager=1
There must be no spaces on either side of the equals sign. Now let's do a little exploring. Type ls to list all partitions that GRUB sees:
grub> ls
(hd0) (hd0,msdos2) (hd0,msdos1)
What's all this msdos stuff? That means this system has the old-style MS-DOS partition table, rather than the shiny new Globally Unique Identifiers partition table (GPT). Now let's snoop. Use the ls command to see what files are on your system:
grub> ls (hd0,1)/
lost+found/ bin/ boot/ cdrom/ dev/ etc/ home/  lib/
lib64/ media/ mnt/ opt/ proc/ root/ run/ sbin/ 
srv/ sys/ tmp/ usr/ var/ vmlinuz vmlinuz.old 
initrd.img initrd.img.old
Hurrah, we have found the root filesystem. You can omit the msdos and gpt labels. If you leave off the slash it will print information about the partition. You can read any file on the system with the cat command:
grub> cat (hd0,1)/etc/issue
Ubuntu 14.04 LTS \n \l
Reading /etc/issue could be useful on a multi-boot system for identifying your various Linuxes.

Booting From grub>

This is how to set the boot files and boot the system from the grub> prompt. We know from running the ls command that there is a Linux root filesystem on (hd0,1), and you can keep searching until you verify where /boot/grub is. Then run these commands, using your own root partition, kernel, and initrd image:
grub> set root=(hd0,1)
grub> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1
grub> initrd /boot/initrd.img-3.13.0-29-generic
grub> boot
The first line sets the partition that the root filesystem is on. The second line tells GRUB the location of the kernel you want to use. Start typing /boot/vmli, and then use tab-completion to fill in the rest. Type root=/dev/sdX to set the location of the root filesystem. Yes, this seems redundant, but if you leave this out you'll get a kernel panic. How do you know the correct partition? hd0,1 = /dev/sda1. hd1,1 = /dev/sdb1. hd3,2 = /dev/sdd2. I think you can extrapolate the rest.
The third line sets the initrd file, which must be the same version number as the kernel.
The fourth line boots your system.
On some Linux systems the current kernels and initrds are symlinked into the top level of the root filesystem:
$ ls -l /
vmlinuz -> boot/vmlinuz-3.13.0-29-generic
initrd.img -> boot/initrd.img-3.13.0-29-generic
So you could boot from grub> like this:
grub> set root=(hd0,1)
grub> linux /vmlinuz root=/dev/sda1
grub> initrd /initrd.img
grub> boot

Booting From grub-rescue>

If you're in the GRUB rescue shell the commands are different, and you have to load thenormal.mod andlinux.mod modules:
grub rescue> set prefix=(hd0,1)/boot/grub
grub rescue> set root=(hd0,1)
grub rescue> insmod normal
grub rescue> normal
grub rescue> insmod linux
grub rescue> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1
grub rescue> initrd /boot/initrd.img-3.13.0-29-generic
grub rescue> boot
Tab-completion should start working after you load both modules.

Making Permanent Repairs

When you have successfully booted your system, run these commands to fix GRUB permanently:
# update-grub
Generating grub configuration file ...
Found background: /usr/share/images/grub/Apollo_17_The_Last_Moon_Shot_Edit1.tga
Found background image: /usr/share/images/grub/Apollo_17_The_Last_Moon_Shot_Edit1.tga
Found linux image: /boot/vmlinuz-3.13.0-29-generic
Found initrd image: /boot/initrd.img-3.13.0-29-generic
Found linux image: /boot/vmlinuz-3.13.0-27-generic
Found initrd image: /boot/initrd.img-3.13.0-27-generic
Found linux image: /boot/vmlinuz-3.13.0-24-generic
Found initrd image: /boot/initrd.img-3.13.0-24-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
# grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
When you run grub-install remember you're installing it to the boot sector of your hard drive and not to a partition, so do not use a partition number like /dev/sda1.

But It Still Doesn't Work

If your system is so messed up that none of this works, try the Super GRUB2 live rescue disk. The official GNU GRUB Manual 2.00 should also be helpful.

Monday, September 21, 2015

How to speed up your internet connection on Linux



The speed of your internet connection is something that is affected by a lot of different elements, most of which are out of your reach and/or jurisdiction. That said, there isn't a way to transform a slow internet connection into a lighting-speed one if your provider is just not giving you enough bandwidth, no matter what you do. This post is only aiming to provide generic advice on how to make things a little bit better if possible, and if applicable to each case.

DNS

Sometimes browsing websites seems to be somewhat “clunky” with images not loading correctly, large latency values between your computer and the DNS resolving server, and online cache issues. This may be a sign that your internet provider's DNS are not up to the task, so you may have to change to an alternative option. The two most popular DNS server alternatives are the Google Public DNS and the OpenDNS, but there are a lot more free to use alternatives as well.
Here's how to change to the Google Public DNS on Ubuntu-based distributions. Open your network settings and hop onto the “Advanced Settings”. This will open up a new window where you will find the “IPv4 and IPv6 Settings” tabs. Navigate to both and change the “Method” from Automatic (DHCP) to Automatic (DHCP) Addresses only. Then insert “8.8.8.8” on the DNS servers box of the IPv4 tab, and “2001:4860:4860::8888” on the IPv6 tab. Now, click the “Save” button and you're done.
To test whether your new DNS settings are working properly or not, insert any fixed IP address that points to a website and see if it gets correctly resolved. Insert “91.189.94.40” on your browser address bar and if it gets resolved to ubuntu.com, then you have done things right. You may always revert to your default DNS by leaving the DNS servers box blank and setting the method back to “Automatic (DHCP)”. You can also benchmark your new DNS by using the namebench open source DNS benchmarking utility, and see how much faster your internet browsing really got. It is worth noting that changing your DNS also improves your privacy, security, and may potentially open up access to geoblocked content.

Firewall and Security

It is often the case that aggressive firewalls cause bottlenecks to your regular browsing and downloading. If you don't really need them, change their settings to allow more traffic to pass back and forth without proactive checking, or completely disable them. You can open a terminal and give “sudo iptables -L” to determine what is you Linux kernel-level firewall settings. For higher-level firewalls, you will need to check your router settings and the specific software tools you are using for this purpose.
If you're using Fedora or CentOS, chances are SELinux will be enabled by default. This otherwise magnificent piece of software could possibly cause increased latencies so you may want to disable it. To do so, open the /etc/sysconfig/selinux configuration file as root and find the line that contains “SELINUX=enforcing” and change it to “SELINUX=disabled” and save the file. Hopefully, things will get somewhat faster by doing this, but you should consider the required security level in your system before disabling SELINUX. A median solution would be the “SELINUX=permissive” option that keeps the security module active, but limited to the printing of warning messages.

MTU Setting

MTU stands for Maximum Transmission Unit and it is basically a parameter that determines the maximum size of data packets that are allowed to be transferred from the network to your system. If the MTU value is too small, then you are crippling your speed by dealing with large number of packages, and if it is too large, you are letting the data transmission occupy significant portions of your bandwidth for larger periods of time, essentially causing lag. So, there is a golden ratio as in everything really and if you want to squeeze the maximum performance out of your internet connection, you can determine and set your MTU to an optimal value.
Open a new terminal session and start ping tests to see what the optimal MTU value is. Use the following command:
ping -M do -s 1472 howtoforge.com
Start with 1472 and drop 10 by 10 until you find the highest value that is indicating 0% packet loss, using “Ctrl+C” to cancel each ping.
After you have determined the optimal MTU value, go to /etc/network/interfaces:
nano /etc/network/interfaces
And add a line “mtu 1462” (or whatever value you found as the best) and save the file. Note that you need to open the configuration file as the system administrator or else you won't be able to save your changes. Hopefully, this will speed things up a bit without causing network data package errors.

Browser

If all of the above has failed to deliver anything truly noteworthy, you may want to resort to the browser settings as a final attempt to give your internet browsing a small boost to the better. Firefox and Chrome/Chromium have started to tentatively use a simpler and faster caching method that may speed up your regular browsing a little bit. To enable them do the following:
On Chrome, insert the following on the address bar and press enter:
chrome://flags/#enable-simple-cache-backend
Then locate the “Simple Cache for HTTP” and choose the enable option.
On Firefox, insert the following on the address bar and press enter:
about:config
Then search for browser.cache.use_new_backend and double click it to open a new config window. Change the “0” value to “1” and press “OK” and you're done.
Finally, you can use the Opera browser that offers an up to date Linux version. Opera features a “Turbo mode” that when enabled activates a server-side compression of images on a rate to up to 80%, essentially letting you browse more comfortably on slower internet connections.


Setting up Master-Master Replication with MySQL on Debian


This tutorial describes a replicated MySQL setup (Mater/Master replication) with 2 nodes where data can be read and written to both nodes at the same time. MySQL takes care to replicate the data to the other node and ensures that primary auto increment keys don't collide.
Since version 5, MySQL comes with built-in support for master-master replication, solving the problem that can happen with self-generated keys. In former MySQL versions, the problem with master-master replication was that conflicts arose immediately if node A and node B both inserted an auto-incrementing key on the same table. The advantages of master-master replication over the traditional master-slave replication are that you don't have to modify your applications to make write accesses only to the master, and that it is easier to provide high-availability because if the master fails, you still have the other master.

1 Preliminary Note

In this tutorial I will show how to replicate the database exampledb from the server server1.example.com with the IP address 192.168.1.101 to the server server2.example.com with the IP address 192.168.1.102 and vice versa. Each system is the slave of the other master and the master of the other slave at the same time. Both systems are running Debian 8; however, the configuration should apply to almost all distributions with little or no modifications.

2 Installing MySQL 5.5

If MySQL isn't already installed on server1 and server2, install it now:
server1/server2:
apt-get -y install mysql-server-5.5 mysql-client-5.5
To make sure that the replication can work, we must make MySQL listen on all interfaces, therefore we comment out the line bind-address = 127.0.0.1 in /etc/mysql/my.cnf:
server1/server2:
nano /etc/mysql/my.cnf
[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1
[...]
Restart MySQL afterwards:
server1/server2:
service mysql restart
Then check with
server1/server2:
netstat -tap | grep mysql
that MySQL is really listening on all interfaces:
netstat -tap | grep mysql
tcp 0 0 *:mysql *:* LISTEN 15437/mysqld
server1:~#
Now we set up a replication user slave2_user that can be used by server2 to access the MySQL database on server1.
server1:
Login to the MySQL shell:
mysql --defaults-file=/etc/mysql/debian.cnf
On the MySQL shell, run the following commands:
server1:
GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'secretpassword';
FLUSH PRIVILEGES;
quit;
Replace the word "secretpassword" with a secure password of your choice. Now we do the last two steps again on server2:
server2:
mysql --defaults-file=/etc/mysql/debian.cnf
GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'secretpassword';
FLUSH PRIVILEGES;
quit;
Replace the word "secretpassword" with a secure password here as well. Note down the passwords as we need them later. 

3 Some Notes

In the following I will assume that both MySQL servers are empty (don't contain any database yet except of the 'mysql' database).
If that's not the case on your server, then you have to lock and dump the databases on the first server and import them on the second one before you continue. Don't unlock the databases before the replication is setup. Below a few commands that show how to copy over all databases to a new server in case you don't start with a "clean" MySQL setup.
Example on how to lock all database tables in a MySQL database.
FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = ON;
 Example on how to dump all databases into a file all_databases.sql.
mysqldump --defaults-file=/etc/mysql/debian.cnf -cCeQ --hex-blob --quote-names --routines --events --triggers --all-databases -r all_databases.sql
Example on how to import all tables on the second server from file all_databses.sql.
mysql --defaults-file=/etc/mysql/debian.cnf < all_databases.sql

4 Setting Up Replication

Now we set up master-master replication in /etc/mysql/my.cnf. The crucial configuration options for master-master replication areauto_increment_increment and auto_increment_offset:
  • auto_increment_increment controls the increment between successive AUTO_INCREMENT values.
  • auto_increment_offset determines the starting point for AUTO_INCREMENT column values.
Let's assume we have N MySQL nodes (N=2 in this example), then auto_increment_increment has the value N on all nodes, and each node must have a different value for auto_increment_offset (1, 2, ..., N).
Now let's configure our two MySQL nodes:
server1:
nano /etc/mysql/my.cnf
Search for the section that starts with [mysqld], and put the following options into it (commenting out all existing conflicting options):
[...]
[mysqld]

# Unique Server ID
server-id = 1

# Do not replicate the following databases
binlog-ignore-db = mysql
replicate-ignore-db = mysql

# Auto increment offset
auto-increment-increment = 2

# Do not replicate sql queries for the local server ID
replicate-same-server-id = 0

# Beginne automatisch inkrementelle Werte mit 1
auto-increment-offset = 1

# Delete binlog data after 10 days
expire_logs_days = 10

# Max binlog size
max_binlog_size = 500M

# Binlog file path
log_bin = /var/log/mysql/mysql-bin.log

[...]
Then restart MySQL:
server1:
service mysql restart
Now do the same on server2:
server2:
nano /etc/mysql/my.cnf
[...]

# Unique Server ID
server-id = 2

# Do not replicate the following databases
binlog-ignore-db = mysql
replicate-ignore-db = mysql

# Auto increment offset
auto-increment-increment = 2

# Do not replicate sql queries for the local server ID
replicate-same-server-id = 0

# Beginne automatisch inkrementelle Werte mit 1
auto-increment-offset = 2

# Delete binlog data after 10 days
expire_logs_days = 10

# Max binlog size
max_binlog_size = 500M

# Binlog file path
log_bin = /var/log/mysql/mysql-bin.log

[...]
server2:
service mysql restart
Next we lock the exampledb database on server1, find out about the master status of server1, create an SQL dump of exampledb (that we will import into exampledb on server2 so that both databases contain the same data), and unlock the database so that it can be used again:
server2:
Now we start the replication on Server 2. Open the MySQL shell:
mysql --defaults-file=/etc/mysql/debian.cnf
And execute the following SQL command to activate the replication from server1 to server2:
CHANGE MASTER TO MASTER_HOST='192.168.1.101', MASTER_USER='repl', MASTER_PASSWORD='secretpassword';
Replace secretpassword with the password for the repl MySQL user that you have set in chapter 2.
Now check the slave status by executing the command "show slave status\G" in the MySQL shell.
show slave status\G
The output will be similar to this:
mysql> show slave status\G
*************************** 1. row ***************************
 Slave_IO_State:
 Master_Host: 192.168.1.101
 Master_User: repl
 Master_Port: 3306
 Connect_Retry: 60
 Master_Log_File: mysql-bin.000001
 Read_Master_Log_Pos: 107
 Relay_Log_File: mysqld-relay-bin.000003
 Relay_Log_Pos: 253
 Relay_Master_Log_File: mysql-bin.000001
 Slave_IO_Running: No
 Slave_SQL_Running: No
 Replicate_Do_DB:
 Replicate_Ignore_DB: mysql
 Replicate_Do_Table:
 Replicate_Ignore_Table:
 Replicate_Wild_Do_Table:
 Replicate_Wild_Ignore_Table:
 Last_Errno: 0
 Last_Error:
 Skip_Counter: 0
 Exec_Master_Log_Pos: 107
 Relay_Log_Space: 410
 Until_Condition: None
 Until_Log_File:
 Until_Log_Pos: 0
 Master_SSL_Allowed: No
 Master_SSL_CA_File:
 Master_SSL_CA_Path:
 Master_SSL_Cert:
 Master_SSL_Cipher:
 Master_SSL_Key:
 Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
 Last_IO_Errno: 0
 Last_IO_Error:
 Last_SQL_Errno: 0
 Last_SQL_Error:
 Replicate_Ignore_Server_Ids:
 Master_Server_Id: 1
1 row in set (0.00 sec)
The Lines that you should check are these:
Master_Host: 192.168.1.101
Master_User: repl
Master_Port: 3306
Master_Log_File: mysql-bin.000001
Relay_Log_File: mysqld-relay-bin.000003
Slave_IO_Running: No
Slave_SQL_Running: No
Now start the replication with this command on the MySQL shell:
start slave;
and then check the slave status again:
show slave status\G
The following two lines should show "yes" now:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
If "Seconds_Behind_Master" is not 0, then wait a few seconds and check the status again. This field shows if master and slave are in sync.
For the next step, we need to know the values of "Master_Log_File" and "Read_Master_Log_Pos" the "show slave status\G" command. In my case these are:
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 107
Write down the values that you get on your server, we need it for the next step on server 1.
Afterward you can leave the MySQL shell:
quit
server1:
We continue on the first server, open the MySQL shell on server1:
mysql --defaults-file=/etc/mysql/debian.cnf
And execute the following MySQL command:
CHANGE MASTER TO MASTER_HOST='192.168.1.102', MASTER_USER='repl', MASTER_PASSWORD='secretpassword', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107;
You have to replace a few things in the above command:
  1. The IP address has to be the IP of your second MySQL server.
  2. The password "secretpassword" has to be the one that you have choosen in chapter 2 for the user repl.
  3. The MASTER_LOG_FILE and MASTER_LOG_POS have to be the values that we have written down in the last step.
Now check with:
show slave status\G
on the MySQL shell if there are no errors.
mysql> show slave status\G
*************************** 1. row ***************************
 Slave_IO_State:
 Master_Host: 192.168.1.102
 Master_User: repl
 Master_Port: 3306
 Connect_Retry: 60
 Master_Log_File: mysql-bin.000001
 Read_Master_Log_Pos: 107
 Relay_Log_File: mysqld-relay-bin.000001
 Relay_Log_Pos: 4
 Relay_Master_Log_File: mysql-bin.000001
 Slave_IO_Running: No
 Slave_SQL_Running: No
 Replicate_Do_DB:
 Replicate_Ignore_DB: mysql
 Replicate_Do_Table:
 Replicate_Ignore_Table:
 Replicate_Wild_Do_Table:
 Replicate_Wild_Ignore_Table:
 Last_Errno: 0
 Last_Error:
 Skip_Counter: 0
 Exec_Master_Log_Pos: 107
 Relay_Log_Space: 107
 Until_Condition: None
 Until_Log_File:
 Until_Log_Pos: 0
 Master_SSL_Allowed: No
 Master_SSL_CA_File:
 Master_SSL_CA_Path:
 Master_SSL_Cert:
 Master_SSL_Cipher:
 Master_SSL_Key:
 Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
 Last_IO_Errno: 0
 Last_IO_Error:
 Last_SQL_Errno: 0
 Last_SQL_Error:
 Replicate_Ignore_Server_Ids:
 Master_Server_Id: 0
1 row in set (0.00 sec)
And start the slave.
start slave;
Check the slave status again:
show slave status\G
The following two lines should show "yes" now:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Afterward you can leave the MySQL shell:
quit
If nothing went wrong, MySQL master-master replication should now be working. If it isn't, please check /var/log/syslog for MySQL errors onserver1 and server2.

5 Test the Replication

 Now it's time to test our replication setup. I will create a database exampledb1 on server1 and then check on server2 if the database has been replicated to the second server:
server1:
Login to the MySQL console on server1 and create the database:
mysql --defaults-file=/etc/mysql/debian.cnf
CREATE DATABASE exampledb1;
server2
Now login to the MySQL console on server2 and check if exampledb1 exists there now:
mysql --defaults-file=/etc/mysql/debian.cnf
show databases;
As we can see, the new database shows up on server2 as well.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| exampledb1 |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
Next I'll test if the replication works in the other direction as well. We are still logged in on server2 and create there a database exampledb2:
CREATE DATABASE exampledb2;
Now go back to server1 and run "show databases" in the MySQL console:
server1
show databases;
The result shows our new database exampledb2, so the replication is working in both directions.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| exampledb1 |
| exampledb2 |
| mysql |
| performance_schema |
+--------------------+
5 rows in set (0.01 sec)

Best CPM Ad Networks For Publishers 2019

It is an undeniable fact that the mid-market publishers have always been looking for the ideal CPM ad networks to partner with. You c...