Setting up MaxScale read/write split routing with MySQL - mysql

I am attempting to setup MaxScale read/write split routing with MySQL.
My vagrant setup is as follows:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.define 'maxscale' do |haproxy_instance|
haproxy_instance.vm.provision "shell", path: 'provision_maxscale.sh'
haproxy_instance.vm.network "forwarded_port", guest: 80, host: 9901
haproxy_instance.vm.network "forwarded_port", guest: 3306, host: 9906
haproxy_instance.vm.network 'private_network', ip: '192.168.50.101'
end
config.vm.define 'mysql-primary' do |mysql_primary_instance|
mysql_primary_instance.vm.provision "shell", path: 'provision_mysql_primary.sh'
mysql_primary_instance.vm.network "forwarded_port", guest: 3306, host: 9907
mysql_primary_instance.vm.network 'private_network', ip: '192.168.50.100'
end
config.vm.define 'mysql-slave' do |mysql_slave_instance|
mysql_slave_instance.vm.provision "shell", path: 'provision_mysql_primary.sh'
mysql_slave_instance.vm.network "forwarded_port", guest: 3306, host: 9908
mysql_slave_instance.vm.network 'private_network', ip: '192.168.50.99'
end
end
provision_maxscale.sh :
wget https://downloads.mariadb.com/enterprise/pbc3-8y0m/generate/10.0/mariadb-enterprise-repository.deb
dpkg -i mariadb-enterprise-repository.deb
sudo apt-get update
sudo apt-get --force-yes --yes install maxscale
sudo systemctl start maxscale.service
cp /vagrant/maxscale.cnf /etc/maxscale.cnf
sudo systemctl start maxscale.service
sudo service maxscale stop
sudo service maxscale start
maxscale.cnf :
[maxscale]
threads=4
[qla]
type=filter
module=qlafilter
options=/tmp/QueryLog
[fetch]
type=filter
module=regexfilter
match=fetch
replace=select
[RW]
type=service
localhost_match_wildcard_host=1
router=readwritesplit
servers=server1,server2
user=lorefnon
passwd=password
max_slave_connections=100%
router_options=slave_selection_criteria=LEAST_CURRENT_OPERATIONS
[RR]
type=service
localhost_match_wildcard_host=1
router=readconnroute
router_options=synced
servers=server1,server2
user=lorefnon
passwd=password
[Debug Interface]
type=service
router=debugcli
[CLI]
type=service
router=cli
[RWlistener]
type=listener
service=RW
protocol=MySQLClient
# address=10.69.179.54
port=3307
[RRlistener]
type=listener
service=RR
protocol=MySQLClient
# address=10.69.179.54
port=3308
[Debug Listener]
type=listener
service=Debug Interface
protocol=telnetd
address=127.0.0.1
port=4442
[CLI Listener]
type=listener
service=CLI
protocol=maxscaled
address=127.0.0.1
port=6603
[server1]
type=server
address=192.168.50.100
port=3306
protocol=MySQLBackend
[server2]
type=server
address=192.168.50.99
port=3306
protocol=MySQLBackend
The provisioners for setting up mysql replications are taken from this article. And I have verified that replication is functional and the maxscale instance can connect to each of the two mysql instances.
The following error message appears when I try to connect to the split router:
mysql -u lorefnon -p -P3307 -h 127.0.0.1
-----------------------------------------------------------------------
MariaDB Corporation MaxScale /var/log/maxscale/error1.log Sat Nov 28 11:38:02 2015
-----------------------------------------------------------------------
--- Logging is enabled.
2015-11-28 11:38:13 Error : Couldn't find suitable Master from 2 candidates.
2015-11-28 11:38:13 Error : Failed to create RW session.
Any help regarding figuring out the problem, or even pointing to where I can investigate why a suitable candidate is not being found is highly appreciated.

for me the most important information is missing or too abstract (how you really configured your database servers).
When I had these kind of issues the slave wasn't configured properly as slave (means no master was set).
What happens when you execute:
show slave status
Could it be, that you missed to execute https://mariadb.com/kb/en/library/change-master-to/

Related

Vagrantfile with docker provider portfoward error

I want to set up an environment with Vagrant. I defined 2 mysql in Vagrantfile, one for development, and one for integration tests. To differentiate these 2 instance I want to expose different ports.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.100.138", nic_type: "82545EM"
config.vm.define "mysql" do |m|
config.vm.provider "docker" do |d|
d.name = "mysql"
d.image = "mysql:8"
d.ports = ["3306:3306"]
d.env = {"MYSQL_DATABASE" => "development", "MYSQL_ROOT_PASSWORD" => "root"}
d.remains_running = true
end
end
config.vm.define "mysql-integration-test" do |mit|
config.vm.provider "docker" do |d|
d.name = "mysql-integration-test"
d.image = "mysql:8"
d.ports = ["3406:3306"]
d.env = {"MYSQL_DATABASE" => "development-it", "MYSQL_ROOT_PASSWORD" => "root"}
d.remains_running = true
end
end
end
The problem is when I started it I got an error than the port is already in use:
jmecsei#jmecsei:~/Work/vagrant$ vagrant up
Bringing machine 'mysql' up with 'docker' provider...
Bringing machine 'mysql-integration-test' up with 'docker' provider...
==> mysql: Creating and configuring docker networks...
==> mysql-integration-test: Creating and configuring docker networks...
==> mysql: Creating the container...
mysql: Name: mysql-integration-test
mysql: Image: mysql:8
mysql: Volume: /home/jmecsei/Work/vagrant:/vagrant
mysql: Port: 3406:3306
mysql:
mysql: Container created: 94c0f18c6938365f
==> mysql-integration-test: Fixed port collision for 22 => 2222. Now on port 2200.
==> mysql-integration-test: An error occurred. The error will be shown after all tasks complete.
==> mysql: Enabling network interfaces...
==> mysql: Starting container...
An error occurred while executing multiple actions in parallel.
Any errors that occurred are shown below.
An error occurred while executing the action on the 'mysql-integration-test'
machine. Please handle this error then try again:
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 3406 is already in use
on the host machine.
To fix this, modify your current project's Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:
config.vm.network :forwarded_port, guest: 3306, host: 1234
Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding. You could
try 'vagrant reload' (equivalent of running a halt followed by an up)
so vagrant can attempt to auto-correct this upon booting. Be warned
that any unsaved work might be lost.

Docker proxy for MySQL: "Lost connection" message from host machine

What I want
There is the https://github.com/jwilder/nginx-proxy package. This is very useful for "HTTP", but I want to use it to TCP too. (MySQL)
Here are my changes: https://github.com/fchris82/nginx-proxy/commit/33d80ea4d4be5d511e4dab0413d516770aa15262
As you can see, I have added stream {} block to nginx.conf and the /etc/nginx/stream.conf.d directory. Here is the generated default.conf for stream block:
access_log off;
error_log /var/log/nginx/debug.log debug;
resolver 127.0.0.11;
# whoami.loc
upstream whoami.loc {
## Can be connect with "nginxproxy_default" network
# nginxproxy_mysql_1
server 192.168.32.2:3306;
}
server {
listen whoami.loc:81;
proxy_pass whoami.loc;
}
What I did, how can you reproduce the error
# Set host
> sudo echo "127.0.0.1 whoami.loc" >> /etc/hosts
# Start containers
> docker-compose up -d
# "Login" the proxy container
> docker-compose exec nginx-proxy /bin/bash
# Test connect to MySQL from proxy container
root> mysql -u root -proot -h whoami.loc -P 81
# --> OK, it works! Let's exit.
mariadb> \q
# Exit from container
root> exit
# Check host
> ping whoami.loc
# --> OK, 127.0.0.1
# Check docker ports
> docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------------------------
nginxproxy_mysql_1 docker-entrypoint.sh mysqld Up 3306/tcp
nginxproxy_nginx-proxy_1 /app/docker-entrypoint.sh ... Up 0.0.0.0:180->80/tcp, 0.0.0.0:81->81/tcp
nginxproxy_whoami_1 /app/http Up 8000/tcp
# --> OK
# Try to direct connection from host (You can read the IP from the /etc/nginx/stream.conf.d/default.conf file)
> mysql -u root -proot -h 192.168.32.2
# --> OK, exit
mysql> \q
# Try to connect from host with "domain" through docker proxy
> mysql -u root -proot -H whoami.loc -P 81 --protocol=tcp
# ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
So, has anybody idea why works from container but why doesn't work from host?
The "solution"
There isn't solution for what I realy wanted. I wanted something like this: Nginx TCP forwarding based on hostname . Tarun's answer solved the error message, thank you.
You need to make sure that
server {
listen whoami.loc:81;
proxy_pass whoami.loc;
}
I getting generated as
server {
listen 81;
proxy_pass whoami.loc;
}
Because for your original config to work, it needs a host entry in /etc/hosts for whoami.loc. And if you make the host entry as 127.0.0.1 then it will only listen to localhost inside the container. And the connections from outside won't be answered.
That is the reason after making the host entry and restart nginx, it worked from inside the container but not from the host. Because it became a effect listen as 127.0.0.1:81

MongoDB: Fail when I tried to start a mongos

I have started two mongod processes for a shard server and a config server, here are the commands:
mongod --shardsvr --dbpath \data\a1\ --port 27018 --logpath \data\logs\loga1.a1
and
mongod --configsvr --dbpath \data\configdb\ --port 27019 --logpath \data\logs\log-config.a1
When I tried to run a mongos I got an error:
C:\mongodb\bin>mongos --configdb CTLDBADEL18:27019
2014-11-10T14:00:03.662-0600 warning: running with 1 config server
should be done only for testing purposes and is not recommended for
production 2014-11-10T14:00:03.671-0600 [mongosMain] MongoS version
2.6.4 starting: pid=5688 port=27017 64-bit host=CTLDBADEL18 (--help for usage) 2014-11-10T14:00:03.672-0600 [mongosMain] db version v2.6.4
2014-11-10T14:00:03.672-0600 [mongosMain] git version:
3a830be0eb92d772aa855ebb711ac91d658ee910 2014-11-10T14:00:03.672-0600
[mongosMain] build info: windows sys.getwindowsversion(major=6,
minor=1, build=7601, platform=2, service_pack='Service Pack 1')
BOOST_LIB_VERSION=1_49 2014-11-10T14:00:03.673-0600 [mongosMain]
allocator: system 2014-11-10T14:00:03.673-0600 [mongosMain] options: {
sharding: { configDB: "CTLDBADEL18:27019" } }
2014-11-10T14:00:03.688-0600 [mongosMain] creating WriteBackListener
for: CTLDBADEL18:27019 serverID: 000000000000000000000000
2014-11-10T14:00:03.706-0600 [mongosMain] scoped connection to
CTLDBADEL18:27019 not being returned to the pool
2014-11-10T14:00:03.707-0600 [mongosMain] ERROR: listen(): bind()
failed errno:10048 Only one usage of each socket address
(protocol/network address/port) is normally permitted. for socket:
0.0.0.0:27017 2014-11-10T14:00:03.707-0600 [Balancer] about to contact config servers and shards 2014-11-10T14:00:03.708-0600 [mongosMain]
dbexit: rc:48
Can you help me and see what I am doing wrong? I have tried with different names and commands:
>mongos --port 27017 --configdb CTLDBADEL18:27019
>mongos --configdb CTLDBADEL18:27019 --port 27017
>mongos --configdb 10.11.82.103:27019 --port 27017
>mongos --configdb 10.11.82.103:27019
Start mongos on a different than port 27017:
mongos --port 27077 --configdb CTLDBADEL18:27019
Or alternatively, check the process that is using port 27017 and kill it, then start mongos with port 27017.
In Windows you can use Start > All Programs > Accessories > System Tools > Resource Monitor (or Run resmon.exe) and select tab 'Network' and click on 'Listening Ports' to check the process using 27017

Chef MySql Cookbook: MySql does not start after reboot

I'm trying to install mysql recipe in vagrant. I use this cookbook for that.
MySql service starts after vagrant up, but after reboot I can't perform neither vagrant provision or vagrant up, because the server fails to start.
I have realized, that Vagrant wipes /var/run directory; it creates mysqld directory (for socket), but not mysql (for pid file). MySql can't find the directory and can't create pid file.
How can I make it work? Why Vagrant creates mysqld, but not mysql?
I also tried it with different boxes (precise32, cloud daily precise64).
Box: http://files.vagrantup.com/precise32.box
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.omnibus.chef_version = :latest
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.network :forwarded_port, guest: 8000, host: 8080
config.vm.provider :virtualbox do |vb|
vb.gui = true
end
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "./chef-repo/cookbooks"
chef.add_recipe "apt"
chef.add_recipe "mysql::server"
chef.json = {
"mysql" => {
"server_root_password" => "password",
"server_repl_password" => "password",
"server_debian_password" => "password"
}
}
end
end
The problem is in MySql cookbook: somehow /var/run/mysqld is not wiped, so the workaround would be: change in <mysql_cookbook>/libraries/provider_mysql_service_ubuntu.rb
pid_file = '/var/run/mysql/mysql.pid'
to
pid_file = '/var/run/mysqld/mysqld.pid'
I make also an issue on github, so in the future the bug could be fixed in master
eviltnan is correct. Here's a scripted workaround for a first run ubuntu 12.04.
ruby_block "ensure mysql server starts on reboot" do
block do
fe = Chef::Util::FileEdit.new("/etc/mysql/my.cnf")
fe.search_file_replace_line(/pid-file/, 'pid-file = /var/run/mysqld/mysql.pid')
Chef::Log.warn("Edited /etc/mysql/my.cnf to re-enable start on reboot.") if fe.write_file
end
end

Mysql Access Denied error after server crash

Our Server crashed with a power failure. After restarting, we are not able to log in to mysql.
mysql -uxxxx -pxxx gives the error:
ERROR 1045 (28000): Access denied for user 'xxxx'#'localhost' (using
password: YES)
We ran namp localhost nad the output was
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
23/tcp open telnet
80/tcp open http
443/tcp open https
3306/tcp open mysql
Gave service mysqld restart and got this error.
Stopping MySQL: [ OK ]
Initializing MySQL database: [ OK ]
Timeout error occurred trying to start MySQL Daemon.
Starting MySQL: [FAILED]
mysqld log file has this:
130309 11:56:10 mysqld started
/usr/libexec/mysqld: ready for connections.
Version: '4.1.7' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
and there is enough space in harddisk.
i am sure we are giving the correct password. Any suggestions would be really helpful.
Run these :
$ service mysqld stop; mysqld_safe &
Then read these. Post your findings
# tail -n 60 /var/log/messages
# tail -n 60 /var/log/mysqld.log
# tail -n 60 /var/lib/mysql/*.err
# tail -n 60 /var/log/mysql/error.log