Fast implementation of MYSQL deployment and one-machine multi-instance deployment _mysql

Source: Internet
Author: User

MySQL has three versions: binary, source package, RPM.

The installation process for binary packages is as follows

Download Address: http://dev.mysql.com/downloads/mysql/

Select Linux-generic

My choice here is mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz.

After decompression, there is a file install-binary, in fact, gives the binary package deployment process

shell> groupadd MySQL
shell> useradd-r-G mysql-s/bin/false MySQL shell> cd/usr/local shell>
t Ar zxvf/path/to/mysql-version-os.tar.gz
shell> ln-s full-path-to-mysql-version-os mysql
shell> cd MySQL
shell> chown-r MySQL.
Shell> chgrp-r MySQL.
shell> scripts/mysql_install_db--user=mysql
shell> chown-r root.
shell> chown-r mysql data
shell> bin/mysqld_safe--user=mysql &
# Next command is optional
Shel l> CP Support-files/mysql.server/etc/init.d/mysql.server 

As with the deployment of the actual production environment, one less step in initializing the database-that is, specifying the configuration file, and if the configuration file is confirmed, the data directory, the log directory is confirmed, the MySQL binary version deployment is fairly easy.

A script is written below, based on the configuration file provided later, the following format is executed:

SH 4.sh/root/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz/mysql3306 3306

Where 4.sh is script,/root/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz is the absolute path of binary package,/mysql3306 is basedir,3306 is the port that needs to be set,

With this script, you can quickly deploy a MySQL database and deploy multiple instances on a server with just a predefined profile.

#!/bin/bash #需传入三个参数, the first is the path to the MySQL binary compression package (absolute path), such as/root/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz, # The second is MySQL's basedir, that is, which directory to create, and the third is the set port number filename=$1 basedir=$2 port=$3 groupadd mysql useradd-r-G mysql-s/bin/false MySQL cd/usr/local tar zxvf $filename #file是获取mysql二进制包的名称, such as Mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz # Dir is the path to the MySQL compression package, excluding the package name itself, such as/root, because subsequent configuration files My.cnf is also placed under this path file= ' basename $filename ' dir= ' dirname $filename ' #获取解压后的名字 , that is, the mysql-5.6.28-linux-glibc2.5-x86_64 after_tar_file=${file:0:-7} #将二进制包改名为 the mysql+ port number, which makes it easier to distinguish the MV $after _tar_file
MySQL "$port" cd mysql "$port" #将原始的配置文件 (need and MySQL compressed package into the same level directory, in this case is/ROOT/MY.CNF) copy to extract and renamed the MySQL binary directory, modified to my+ port number. cnf CP $dir/my.cnf/my "$port". CNF user_cnf=my "$port". CNF #下面主要是将原始配置文件中的路径修改为自己设定的路径, that is, the second argument passed in #整个的挑战在于传入的路径带有 "/", There is a problem with the SED substitution, all with a tricky idea, which is to replace "/" with "|" for sed replacement and then "|" in the file. Modify back to "/" basedir_new=${basedir/\//|} sed-i "s/\/project\/class2/$basedir _new/g" $user _cnf sed-i "s/|/\//g" $user _cnf #设置 SERVER_ID, take the current second value server_id= ' Date +%s ' sed -I/^server_id/s/.*/server_id= "$server _id"/$user _cnf #设置端口号 sed-i/^port/s/.*/port= "$port"/$user _cnf #创建必要的目录并修改权限 m  Kdir-p "$basedir"/mysql/{run,data,share,log,tmp} chown-r mysql $basedir chgrp-r mysql $basedir #下面这个是非必要的, specifically see the summary of the following CP Share/english/errmsg.sys "$basedir"/mysql/share/#初始化时--force is also unnecessary, concrete visible behind the summary scripts/mysql_install_db--user=
 MySQL--defaults-file= "$user _cnf"--force bin/mysqld_safe--defaults-file= "$user _cnf"--user=mysql &

The following gives a reference to the configuration file, you can make corresponding changes according to the actual situation

[Mysqld_safe] pid-file=/project/class2/mysql/run/mysqld.pid [MySQL] port=3306 prompt=\\u@\\d \\r:\\m:\\s> Default-character-set=utf8 no-auto-rehash [Client] port=3306 Socket=/project/class2/mysql/run/mysql.sock [mysqld] # Dir basedir=/project/class2/mysql datadir=/project/class2/mysql/data tmpdir=/tmp lc_messages_dir=/project/class2/
Mysql/share Log-error=/project/class2/mysql/log/alert.log Slow_query_log_file=/project/class2/mysql/log/slow.log General_log_file=/project/class2/mysql/log/general.log Socket=/project/class2/mysql/run/mysql.sock #innodb InnoDB _data_home_dir=/project/class2/mysql/data Innodb_log_group_home_dir=/project/class2/mysql/data Innodb_data_file_ Path=ibdata1:2g;ibdata2:16m:autoextend innodb_buffer_pool_size=10g innodb_buffer_pool_instances=4 Innodb_log_ files_in_group=2 innodb_log_file_size=1g innodb_log_buffer_size=200m innodb_flush_log_at_trx_commit=1 innodb_ additional_mem_pool_size=20m innodb_max_dirty_pages_pct=60 innodb_io_capacity=1000 Innodb_thread_concuRrency=16 innodb_read_io_threads=8 innodb_write_io_threads=8 innodb_open_files=60000 Innodb_file_format=Barracuda
innodb_file_per_table=1 Innodb_flush_method=o_direct innodb_change_buffering=inserts innodb_adaptive_flushing=1 innodb_old_blocks_time=1000 innodb_stats_on_metadata=0 innodb_read_ahead=0 innodb_use_native_aio=0 innodb_lock_ Wait_timeout=5 innodb_rollback_on_timeout=0 Innodb_purge_threads=1 innodb_strict_mode=1 transaction-isolation= read-committed #myisam key_buffer=64m myisam_sort_buffer_size=64m concurrent_insert=2 delayed_insert_timeout=300 #
Replication Master-info-file=/project/class2/mysql/log/master.info Relay-log=/project/class2/mysql/log/relaylog Relay_log_info_file=/project/class2/mysql/log/relay-log.info relay-log-index=/project/class2/mysql/log/ Mysqld-relay-bin.index slave_load_tmpdir=/project/class2/mysql/tmp slave_type_conversions= "ALL_NON_LOSSY" slave_ net_timeout=4 skip-slave-start sync_master_info=1000 sync_relay_log_info=1000 #binlog log-bin=/project/class2/mysql/log/mysql-bin server_id=2552763370 binlog_cache_size=32k max_binlog_cache_size=2g Max_binlog_size=500M
Binlog-format=row sync_binlog=1000 Log-slave-updates=1 expire_logs_days=0 #server Default-storage-engine=innodb
Character-set-server=utf8 Lower_case_table_names=1 skip-external-locking open_files_limit=65536 safe-user-create local-infile=1 #sqlmod = "Strict_all_tables,no_zero_in_date,no_zero_date" Log_slow_admin_statements=1 log_warnings= 1 long_query_time=1 slow_query_log=1 general_log=0 query_cache_type=0 query_cache_limit=1m query_cache_min_res_unit= 1 k table_definition_cache=65536 thread_stack=512k thread_cache_size=256 read_rnd_buffer_size=128k sort_buffer_size= 256K join_buffer_size=128k read_buffer_size=128k port=3306 skip-name-resolve skip-ssl max_connections=4500 max_user_ connections=4000 max_connect_errors=65536 max_allowed_packet=128m connect_timeout=8 net_read_timeout=30 net_write_

 Timeout=60 back_log=1024

Summarize:

In the initialization process, if the following error is reported:

FATAL error:neither host ' keepalived02 ' nor ' localhost ' could ' be looked ' the up with
/mysql3306/mysql/bin/resolveip
P Lease configure the ' hostname ' command to return a correct
hostname.
If you are want to solve this in a later stage, restart this script with the
--force option

However, the Execute hostname command on the bash terminal does have a value returned, and the--force parameter can be added as follows:

Copy Code code as follows:
scripts/mysql_install_db--user=mysql--defaults-file= "$user _cnf"--force

If you report the following error:

Copy Code code as follows:
[ERROR] Can ' t find messagefile '/mysql3306/mysql/share/errmsg.sys '

You can copy share/english/errmsg.sys files from the binary version to/mysql3306/mysql/share/.

Follow-up: Both of these errors are due to basedir modifications, which are found by default in binary packages.

How to use the script to achieve the rapid deployment of MySQL and a multiple instances of deployment, through this article I hope to learn about the deployment of MySQL help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.