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
Related
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.
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/
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?
I've installed VirtualBox, Vagrant and chef-solo on my MBP laptop running Mountain Lion. I've downloaded recipes from opscode and have 'vagrant up' working. The VM is successfully create and I get a mostly working LAMP stack.
Where I am stuck is creating a database and user to access the database.
What I've done:
Created a development folder that includes Vagrantfile and the directory cookbooks. In cookbooks I have
README.md
apache2
apt
aws
build-essential
database
hnnapp
mysql
openssl
php
postgresql
xfs
xml
'hnnapp' contains my own recipe to launch my virtual machine. I used knife to initialize the folder and then edited metadata.rb to include
depends "apt"
depends "apache2"
depends "database"
depends "mysql"
depends "xml"
depends "openssl"
depends "php"
depends "build-essential"
and in recipes/default.rb I have include
include_recipe "apt"
include_recipe "apache2"
include_recipe "xml"
include_recipe "openssl"
include_recipe "database::mysql"
include_recipe "mysql"
include_recipe "mysql::client"
include_recipe "mysql::server"
include_recipe "mysql::ruby"
include_recipe "php"
include_recipe "php::module_mysql"
include_recipe "apache2::mod_php5"
include_recipe "apache2::mod_rewrite"
apache_site "default" do
enable true
end
mysql_database node['hnnapp']['database'] do
connection ({:host => 'localhost', :username => 'root', :password => node['mysql']['server_root_password']})
action :create
end
mysql_database_user node['hnnapp']['db_username'] do
connection ({:host => 'localhost', :username => 'root', :password => node['mysql']['server_root_password']})
password node['hnnapp']['db_password']
database_name node['hnnapp']['database']
privileges [:select, :update, :insert, :cretae, :delete]
action :create
end
Finally, my Vagrantfile includes
config.vm.provision :chef_solo do |chef|
chef.add_recipe "hnnapp"
chef.json = {
"hnnapp" => {
"db_password" => "test",
"db_username" => "testuser",
"database" => 'testdatabase'
},
"mysql" => {
"server_root_password" => "098f6bcd4621d373cade4e832627b4f6",
"server_debian_password" => "098f6bcd4621d373cade4e832627b4f6",
"server_repl_password" => "098f6bcd4621d373cade4e832627b4f6"
}
}
end
When I 'vagrant ssh' into the VM I see apache, php and mysql is installed. MySQL has no other databases except for test and information schema. I can use 'mysql' to get into mysql client, but I have no privileges to create any databases or users. sudo mysql doesn't work either.
I'd like to find out two things:
Am I going about this the right way? Putting the right commands in the right files?
What mistakes do I have in my scripts.
Does it make any difference if you add :grant to your actions in the mysql_database_user block?
action [:create, :grant]
I found this tutorial quite helpful with provisioning mysql with a user and privileges, although I am still a bit confused with the directory structure of chef-solo.
http://misheska.com/blog/2013/06/23/getting-started-writing-chef-cookbooks-the-berkshelf-way-part2/
I have mysql server installed and it contains data also. I was trying to connect to mysql from ruby code. For that purpose I installed mysql gem using gem install mysql. The connection part in my program is giving below
require 'rubygems'
require 'mysql'
require 'csv'
$user_name = "root"
$pas_wrd = "password"
def mysql_connect(db_name)
begin
db = Mysql.real_connect("localhost", "#{$user_name}", "#{$pas_wrd}", "#{db_name}")
return db
rescue Mysql::Error => e
puts "Error code: #{e.errno}"
puts "Error message: #{e.error}"
puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
end
end
It was written some day before and done the job. But when I try to use the same code It shows a mysql gem error,something like 'initialize' not found. By searching I found a solution like re-installing the gem. for re-installing I user the command rvmsudo gem install mysql. The above problem was solved. But it showing another error like
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I tried manually using mysql -u root -p
it is also showing the same error.
My mysql my.cnf content is given below.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
tmpdir = /home/presoft/Documents
skip-external-locking
The mysql is not running in my system.
ps aux | grep mysql
presoft 3823 0.0 0.0 4368 816 pts/0 S+ 10:41 0:00 grep --color=auto mysql
I tried to start using using sudo /etc/init.d/mysql start which gave the result of
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql start
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mysql
start: Job failed to start
Can any one help me to find a solution because db containing large amount of valuable data.
Thanks
Regards.
Use
service mysql start
This will start mysql service. newer linux machine consider mysql as service
I solved the problem from the above answer tip. The problem was my mysql server was corrupted.
So I first run the command
sudo apt-get purge mysql-common mysql-server
It will remove the all mysql files and configurations with out deleting the data. After running please carefully watch the process and do the need full any warning or error come.
I got a warning like
dpkg: warning: while removing mysql-common, directory '/etc/mysql' not empty so not removed.
So I removed the file and re run the above command. After the successful execution. I re-installed the mysql using
sudo apt-get install mysql-common mysql-server
then set the root password. After getting in to server The data is safe.