MySQL Ops people should be aware that the online MySQL is generally based on the source code compiled, because this talent is sufficient according to the individual needs of the enterprise to choose the function to compile, although MySQL source code compilation is very simple, but imagine, Suppose you have hundreds of servers to install MySQL at the same time, do you still have to manually compile and write the configuration files on a single station? This is obviously too inefficient, this article discusses MySQL's own proactive installation deployment.
1, production to meet their own needs of the RPM package we want to compile according to MySQL source code to meet the needs of the enterprise RPM package, source commands such as the following:
wget HTTP://DOWNLOADS.MYSQL.COM/ARCHIVES/GET/FILE/MYSQL-5.6.16.TAR.GZTAR-ZXVF MYSQL-5.6.16.TAR.GZCD Mysql-5.6.16mkdir rpmcd rpm
In the above we get the source code and create the RPM folder under the source Code home folder, then we create the Mysql.spec file under this folder:
name:mysqlversion:5.6.16release:guahaolicense:gplurl:http://downloads.mysql.com/archives/get/file/ Mysql-5.6.16.tar.gzgroup:applications/databasebuildroot:%{_tmppath}/%{name}-%{version}-%{release}-root Buildrequires:cmakepackager: [Email protected]autoreq:noprefix:/opt/mysqlsummary:mysql 5.6.16%description The MySQL (TM) software delivers a very fast, multi-threaded, Multi-user,and robust SQL (structured Query Language) databas E server. MySQL Serveris intended for mission-critical, heavy-load production systems as wellas in embedding into mass-deployed SOF Tware.%define mysql_user mysql%define mysql_group mysql%define __os_install_post%{nil}%buildcd $OLDPWD/... /cflags= "-o3-g-fno-exceptions-static-libgcc-fno-omit-frame-pointer-fno-strict-aliasing" CXX=g++CXXFLAGS= "-o3-g- Fno-exceptions-fno-rtti-static-libgcc-fno-omit-frame-pointer-fno-strict-aliasing "Export CFLAGS CXX CXXFLAGScmake. -dsysconfdir:path=%{prefix} -dcmake_install_prefix:path=%{prefix}-dcmake_build_type:string=release -denable_profiling:bool=on-dwith_debug:bool=off -dwith_valgrind:bool=off-denable_debug_sync:bool=off -dwith_extra_charsets:string=all-dwith_ssl:string=bundled-dwith _unit_tests:bool=off-dwith_zlib:string=bundled-dwith_partiti On_storage_engine:bool=on-dwith_innobase_storage_engine:bool=on-dwith_archive_storage _engine:bool=on-dwith_blackhole_storage_engine:bool=on-dwith_perfschema_storage_engi Ne:bool=on-ddefault_charset=utf8-ddefault_collation=utf8_general_ci -dwitH_extra_charsets=all-denabled_local_infile:bool=on-dwith_embedd Ed_server=0-dinstall_layout:string=standalone-dcommunity_build:boo l=on-dmysql_server_suffix= '-r5436 '; make-j ' Cat/proc/cpuinfo | grep processor| Wc-l '%INSTALLCD $OLDPWD/... /make destdir= $RPM _build_root install%cleanrm-rf $RPM _build_root%files%defattr (-,%{mysql_user},%{MYSQL_GROUP})% attr (755,%{mysql_user},%{mysql_group})%{prefix}/*%pre%postln-s%{prefix}/lib%{prefix}/lib64%preun%changelog
With this spec file, you can run the following command to generate our own RPM package:
Rpmbuild-bb./mysql.spec
2, write my.cnf template my.cnf template such as the following:
[Mysqld_safe]pid-file=/opt/mysql/run/mysqld.pid[mysql]prompt=\\[email protected]\\d \\r:\\m:\\s> DEFAULT-CHARACTER-SET=GBKNO-AUTO-REHASH[CLIENT]SOCKET=/OPT/MYSQL/RUN/MYSQL.SOCK[MYSQLD] #dirbasedir =/opt/ mysqldatadir=/data/mysql/datatmpdir=/data/mysql/tmplog-error=/data/mysql/log/alert.logslow_query_log_file=/ data/mysql/log/slow.loggeneral_log_file=/data/mysql/log/general.logsocket=/opt/mysql/run/mysql.sock# Innodbinnodb_data_home_dir=/data/mysql/datainnodb_log_group_home_dir=/data/mysql/datainnodb_data_file_path= Ibdata1:2g;ibdata2:16m:autoextendinnodb_buffer_pool_size=10ginnodb_buffer_pool_instances=4innodb_log_files_in_ Group=4innodb_log_file_size=1ginnodb_log_buffer_size=200minnodb_flush_log_at_trx_commit=1innodb_additional_mem _pool_size=20minnodb_max_dirty_pages_pct=60innodb_io_capacity=200innodb_thread_concurrency=32innodb_read_io_ threads=8innodb_write_io_threads=8innodb_open_files=60000innodb_file_format=barracudainnodb_file_per_table= 1innodb_flush_method=o_directinnodb_change_Buffering=allinnodb_adaptive_flushing=1innodb_old_blocks_time=1000innodb_stats_on_metadata=0innodb_read_ahead= 0innodb_use_native_aio=0innodb_lock_wait_timeout=50innodb_rollback_on_timeout=0innodb_purge_threads=1innodb_ Strict_mode=1transaction-isolation=read-committed#myisamkey_buffer_size=100mmyisam_sort_buffer_size= 64mconcurrent_insert=2delayed_insert_timeout=300#replicationmaster-info-file=/data/mysql/log/ master.inforelay-log=/data/mysql/log/mysql-relayrelay_log_info_file=/data/mysql/log/ Mysql-relay.inforelay-log-index=/data/mysql/log/mysql-relay.indexslave_load_tmpdir=/data/mysql/tmpslave_type_ conversions= "All_non_lossy" slave_net_timeout=4skip-slave-startsync_master_info=1000sync_relay_log_info=1000# Binloglog-bin=/data/mysql/log/mysql-binserver_id=2552763370binlog_cache_size=32kmax_binlog_cache_size=2gmax_ binlog_size=500mbinlog_format=rowsync_binlog=1000log-slave-updates=1expire_logs_days=0# Serverdefault-storage-engine=innodbcharacter-set-server=gbklower_case_table_names=1skip-external-lockingopen_files_limit=65536safe-user-createlocal-infile=1performance_schema=0log_slow_admin_statements= 1log_warnings=1long_query_time=1slow_query_log=1general_log=0query_cache_type=0query_cache_limit=1mquery_cache _min_res_unit=1ktable_definition_cache=65536thread_stack=512kthread_cache_size=256read_rnd_buffer_size= 128ksort_buffer_size=256kjoin_buffer_size=128kread_buffer_size=128kport=3306skip-name-resolveskip-sslmax_ Connections=4500max_user_connections=4000max_connect_errors=65536max_allowed_packet=128mconnect_timeout=8net_ Read_timeout=30net_write_timeout=60back_log=1024#server ID
Attentive readers should note that at the end of the my.cnf, there is a blank space on the server ID, and the shell script in the back is added dynamically, because all MySQL server IDs within an enterprise must maintain global consistency so that no confusion occurs when the primary and standby replicates. In fact, suppose that you want to write this script more general, can completely leave a lot of other parameters to white, such as Port, DataDir, memory-related parameters, and so on, here I just take the server ID as an example, to offer. 3. Prepare MySQL Data folder template you have to prepare a MySQL, according to your own needs, to put the common things on top (such as accounts, etc.), the following is the simplest installed MySQL Data folder structure:
[[email protected] mysql]# ls-ltotal 12drwxr-xr-x 5 mysql mysql 4096 Jul 2 09:26 datadrwxr-xr-x 2 mysql mysql 4096 Ju L 1 18:21 logdrwxr-xr-x 2 mysql mysql 4096 Jul 2 09:26 tmp[[email protected] mysql]# CD data[[email protected] Dat a]# ls-ltotal 6314044drwx------2 mysql mysql 4096 Jul 1 17:17 mysqldrwx------2 mysql mysql 4096 Jul 1 1 7:17 performance_schemadrwx------2 mysql mysql 4096 Jul 1 17:17 test
Pack the folder in tar (named Data.tar), and then extract the template to the newly installed MySQL instance Data folder. 4. Write your own proactive installation deployment script before executing this script, we have to put the previous RPM packages, my.cnf templates and Data folder templates in a fixed place, in this case, on an intra-enterprise FTP. MySQL self-proactively installs the deployment script (named: mysql_install.sh) For example:
#!/bin/sh#step 1:prepareyum Install cmake gcc g++ bison ncurses-devel zlib groupadd mysqluseradd-g mysql mysql#step 2:g ET sourceftp-n<<eofopen 10.10.100.254user zhuxianjie zxj321binarycd mysqlpromptmget *eof#step 3:installunique_ Id= ' Date ' +%y%m%d%m%s "' echo ' server_id= ' $unique _id >> my.cnfrpm-ivh MYSQL-5.6.16-GUAHAO.X86_64.RPMCP my.cnf/ Opt/mysqlchown-r Mysql:mysql/opt/mysqltar xvf data.tar-c/datachown-r mysql:mysql/data/mysql#step 4:start mysqlcp/o Pt/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqldchmod 755/etc/init.d/mysqldchkconfig mysqld on/etc/ Init.d/mysqld start