#
# Cookbook Name:: mysql
# Recipe:: default
#
# Copyright 2015, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
mysql_home = "#{node['mysql']['homedir']}"
var_dir = "#{node['mysql']['homedir']}/mysql/var"
var_log = "#{node['mysql']['homedir']}/mysql/var/log"
mysql_user="#{node['mysql']['user']}"
##Creating mysql user
user mysql_user do
shell '/bin/false'
action :create
not_if "grep #{node['mysql']['user']} /etc/passwd", :user => "#{node['mysql']['user']}"
end
#creating mysql home directory
directory mysql_home do
owner mysql_user
group mysql_user
mode "0755"
action :create
recursive true
not_if { File.exist?("#{node['mysql']['homedir']}") }
end
#Taking backup of already existing my.cnf file
#
execute "mv /etc/my.cnf /etc/my.cnf_old" do
only_if { File.exist?("/etc/my.cnf") }
end
## Using remote_file , we are downloading the tar file through apache
remote_file "/tmp/mysql.tar.gz" do
#source 'http://10.72.6.182/tars/mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz'
source 'ftp://192.168.33.10/pub/mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz'
path "/tmp/mysql.tar.gz"
not_if { ::File.exist?("/tmp/mysql.tar.gz") }
end
## Un-tarring downloaded package and renaming it as mysql
execute "Downloading source" do
command <<-EOH
echo "masterone" > /tmp/masterone
tar -zxvf /tmp/mysql.tar.gz -C #{node[:mysql][:homedir]}/
mv -f #{node[:mysql][:homedir]}/mysql-5.6.23* #{node[:mysql][:homedir]}/mysql
cp -rf #{node[:mysql][:homedir]}/mysql /usr/local/
EOH
not_if { ::File.exist?("/usr/local/mysql/bin/mysql")}
end
##creating /AZVOL/mysql/var/log folder
directory var_log do
owner mysql_user
group mysql_user
mode "0755"
action :create
recursive true
not_if { ::File.exist?("#{node['mysql']['homedir']}/mysql/var/log") }
end
##Installing libaio and perl-Data-Dumper ( mysql_install_db script need the following package during installation )
package ['libaio', 'perl-Data-Dumper'] do
action :install
end
#Creating mysqld init services file
#
execute "Changing permission" do
command <<-EOH
chown -R mysql:mysql #{node[:mysql][:homedir]}/mysql
cp -rf #{node[:mysql][:basedir]}/support-files/mysql.server /etc/init.d/mysqld
EOH
end
##Copying all the binarys in /MSVOL/mysql/bin to /usr/local/bin /bin /usr/bin locations
bash "Copying_file" do
code <<-EOH
for i in "#{node['mysql']['basedir']}/bin/*"
do
bas="`basename $i`"
cp -rvf $i /usr/local/bin && chmod 755 /usr/local/bin/$bas && chown mysql:mysql /usr/local/bin/$bas
cp -rvf $i /usr/bin && chmod 755 /usr/bin/$bas && chown mysql:mysql /usr/bin/$bas
cp -rvf $i /bin && chmod 755 /bin/$bas && chown mysql:mysql /bin/$bas
done
EOH
not_if { ::File.exist?("/usr/local/bin/mysql")}
end
##Creating my.cnf file from template
template "/etc/my.cnf" do
source "masterone.cnf.erb"
action :create
not_if { ::File.exist?("/tmp/masterone")}
end
##Installing mysql , using mysql_install_db script
execute "Installing mysql" do
command <<-EOH
cd #{node[:mysql][:basedir]}/
scripts/mysql_install_db --user=#{node['mysql']['user']}
echo "Installation completed" > /tmp/mysql_install
EOH
not_if do File.exists?('/tmp/mysql_install') end
end
service "mysqld" do
action :start
end
#Creating link for socket. ( Mysql failed to start without /tmp/mysql.sock file . So we are creating the link )
execute "#{node[:mysql][:basedir]}/tmp/mysql.sock" do
command <<-EOH
cd /tmp
ln -s #{node[:mysql][:basedir]}/tmp/mysql.sock .
EOH
not_if do File.exists?('/tmp/mysql.sock') end
end
service "mysqld" do
action :restart
end
##Setting mysql user password
bash "Creating user" do
code <<-EOH
#{node['mysql']['basedir']}/bin/mysqladmin -u #{node['mysql']['root-user']} password '#{node['mysql']['root-pass']}'
echo "user created" > /tmp/mysql
EOH
not_if do File.exists?('/tmp/mysql') end
end
#Attribute
default['mysql']['homedir']='/AZVOL'
default['mysql']['basedir']='/AZVOL/mysql'
default['mysql']['bindaddress']='localhost'
default['mysql']['port']='3306'
default['mysql']['user']='mysql'
default['mysql']['masterreplication']='true'
default['mysql']['slavereplication']='false'
default['mysql']['binlog_do_db']='reptest'
default['mysql']['masterone-server-id']=1
default['mysql']['mastertwo-server-id']=2
default['mysql']['slave-server-id']=3
default['mysql']['root-user']='root'
default['mysql']['root-pass']='mysql123'
##My.cnf File
##Mysql Conf
[mysqladmin]
user=<%= node['mysql']['user'] %>
[mysqld]
basedir=<%= node['mysql']['basedir'] %>
datadir=<%= node['mysql']['basedir'] %>/data
port=3306
socket=<%= node['mysql']['basedir'] %>/tmp/mysql.sock
bind-address=<%= node['ipaddress'] %>
skip-name-resolve
key_buffer_size=256M
max_allowed_packet=20M
sort_buffer_size=4M
read_buffer_size=1M
read_rnd_buffer_size=128M
myisam_sort_buffer_size=8M
thread_cache_size=512
innodb_data_home_dir=<%= node['mysql']['basedir'] %>/data
#innodb_log_group_home_dir=/var/lib/mysql/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size=4096M
innodb_additional_mem_pool_size=512M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size=25M
#innodb_log_buffer_size=128M
#innodb_flush_log_at_trx_commit=1
#innodb_lock_wait_timeout=50
net_buffer_length=1000000
### added by xavier
max_connections=500
wait_timeout = 25000
interactive_timeout=25000
tmp_table_size=24M
max_heap_table_size=24M
read_rnd_buffer_size=4M
join_buffer_size=8M
expire_logs_days = 7
key_buffer_size=64M
query_cache_size=128M
query_cache_limit=128M
log-queries-not-using-indexes
join_buffer_size=1M
#log-slow-queries=/AZVOL/mysql/var/log/slow.log
##Replication conf
<% if node['mysql']['masterreplication']=="true" %>
server-id=<%= node['mysql']['masterone-server-id'] %>
binlog_do_db=<%= node['mysql']['binlog_do_db'] %>
log_bin=<%= node['mysql']['basedir'] %>/mysql-bin.log
<% end %>
<% if node['mysql']['slavereplication']=="true" %>
server-id=<%= node['mysql']['slave-server-id'] %>
binlog_do_db=<%= node['mysql']['binlog_do_db'] %>
log_bin=<%= node['mysql']['basedir'] %>/mysql-bin.log
relay-log=<%= node['mysql']['basedir'] %>/mysql-relay-bin.log
<% end %>
# * Query Cache Configuration
#
#query_cache_limit = 512M
#query_cache_size = 512M
[mysqld_safe]
mysqld=mysqld
port=<%= node['mysql']['port'] %>
socket=<%= node['mysql']['basedir'] %>/tmp/mysql.sock
pid-file=<%= node['mysql']['basedir'] %>/tmp/manager.pid
default-mysqld-path=<%= node['mysql']['basedir'] %>/bin/mysqld