Vagrantfile with docker provider portfoward error - mysql

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.

Related

Impossible to connect my symfony 5 app with mysql: postgresql is forced

I'm using mamp the latest php7.4.12 and Apache, i don't understand what is it, i search for this error : "An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?"
In my .env
DATABASE_URL="mysql://root:#db_docker_symfony:3306/test_docker?serverVersion=5.7"
and doctrine.yaml
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
I had the same problem and basically you might have the postgresql uncommented... this port 5432 is related to the postgresql connection, so you just need to comment this line out using "#" ... as you can see below,
#DATABASE_URL="postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
leave only you mysql connection uncommented and boom! Happy days hey \o/...
I reackon .env comes with postgresql as a default connection.
Hopefully works for you as well.

Trying to make browsersync work within vagrant using gulp

I've been stuck in trying to make browsersync work within vagrant using gulp. I can connect to the UI of browsersync but I can never connect to my development site. If tried connecting using the address http://localhost:3000, I keep getting the error below:
Cannot GET /
Here are my configurations for vagrant:
# IP Address to access the server 10.0.0.3
config.vm.network "private_network", ip: "10.0.0.3"
config.vm.network "forwarded_port", guest: 3000, host: 3000, auto_correct: true
config.vm.network "forwarded_port", guest: 3001, host: 3001, auto_correct: true
# Sync the server timezone to the host machine
config.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/Asia/Manila /etc/localtime", run: "always"
# Sync File
config.vm.synced_folder "./", "/var/www/html", mount_options: ["dmode=777", "fmode=666"]
Configuration when connecting to SQL
Here are my configurations for Gulp:
browserSync.init(["./assets/css/*.css"],{
server: {
proxy: "http://10.0.0.3/globe-gui/",
open: false,
port: "2222",
injectChanges: true,
}
});
I tried searching the net for a solution but can't seem to get an answer.
Browser sync isn't initialized with the correct options.
browserSync.init({
files: ["./assets/css/*.css"],
open: false,
port: "2222",
injectChanges: true,
proxy: "http://10.0.0.3/globe-gui/",
});
Your Vagrantfile configures guest machine (box) to be accessible via IP address 10.0.0.3.
Connect to services running in the box from host through IP address (10.0.0.3).
Set the SSH Host to 10.0.0.3 for a database service running on port 2222 in the box when connecting from host to box, but set localhost when connecting inside of the box.
I take it that BrowserSync is started inside the box.
Configure proxy to have value:
proxy: "http://localhost/globe-gui/",
Connect to BrowserSync from a browser running in the host through private IP address for box (http://10.0.0.3:3000).

Setting up MaxScale read/write split routing with 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/

Why can't I install mysql-server on a fresh Ubuntu 14.04 vagrant box?

Basically what the title asks. I have a very simple vagrant file, as follows:
# -*- mode: ruby -*-
# vi: set ft=ruby :
box_name = "killd"
Vagrant.configure(2) do |config|
config.vm.define box_name do |box|
box.vm.provider "virtualbox" do |v|
v.name = box_name
v.memory = 256
end
box.vm.hostname = box_name
box.vm.box = "ubuntu/trusty64"
#box.vm.network "private_network", type: "dhcp"
box.vm.network "private_network", ip: "10.10.10.10"
box.vm.provision "ansible" do |ansible|
#ansible.verbose = 'vvv'
ansible.playbook = "ansible/playbook.yml"
ansible.limit = "all"
end
#box.vm.synced_folder "./", "/vagrant", type: "nfs"
box.vm.network "forwarded_port", guest: 3306, host:3366
end
end
I have a simple ansible playbook structure that just updates apt's cache and then runs apt-get upgrade with privelege for now (this definitely works). I would like to then go ahead and install the mysql-server package. But when I try to do so, even by just issuing sudo apt-get install mysql-sever through a vagrant-ssh session I receive the following error message:
Unable to set password for the MySQL "root" user
An error occurred while setting the password for the MySQL administrative user. This may have happened because the account already has a password, or because of a communication problem with the MySQL server.
You should check the account's password after the package installation. Please read the /usr/share/doc/mysql-server-5.5/README.Debian file for more information.
I've installed mysql many times before on Ubuntu VMs and never seen that. Most of the answers I've come across relate either to the port number or previous versions of MySQL being installed, which is not the case here. Why am I having issues?

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