[MySQL] automated installation and deployment of MySQL

Source: Internet
Author: User

Anyone who has been using MySQL O & M should be clear that online MySQL usually uses source code compilation, because this allows you to select the function to be compiled based on your own needs, although the MySQL source code compilation is quite simple, just think about it. If you have hundreds of servers and want to install MySQL at the same time, do you still need to manually compile and compile configuration files? This is obviously too inefficient. This article discusses the automated installation and deployment of MySQL.

1. To create an RPM package that meets your needs, compile the RPM package that meets your enterprise needs based on the MySQL source code. The command for getting the source code is as follows:
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
We obtained the source code above and created the rpm directory under the main directory of the source code. Then we created the mysql. spec file under the directory:
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: zhuxj@guahao.comAutoreq: 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) database server. MySQL Serveris intended for mission-critical, heavy-load production systems as wellas for embedding into mass-deployed software.%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_PARTITION_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_ENGINE:BOOL=ON               \  -DDEFAULT_CHARSET=utf8                                 \  -DDEFAULT_COLLATION=utf8_general_ci                    \  -DWITH_EXTRA_CHARSETS=all                              \  -DENABLED_LOCAL_INFILE:BOOL=ON                         \  -DWITH_EMBEDDED_SERVER=0                               \  -DINSTALL_LAYOUT:STRING=STANDALONE                     \  -DCOMMUNITY_BUILD:BOOL=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 execute the following command to generate your own RPM package:
rpmbuild -bb ./mysql.spec
2. Compile the my. cnf template my. cnf as follows:
[mysqld_safe]pid-file=/opt/mysql/run/mysqld.pid[mysql]prompt=\\u@\\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
Careful readers should pay attention to the following. the end of cnf is left blank on the server id, and the shell script will be added dynamically. This is because the server IDs of all MySQL instances in an enterprise must maintain global consistency, this will not cause confusion during master-slave replication. In fact, if you want to write this script more commonly, you can leave more parameters to white, such as port, datadir, and memory-related parameters. Here I just take the server id as an example to introduce them. 3. Prepare a MySQL data directory template. You must prepare a MySQL instance in advance. You can store all the common items (such as accounts) as needed ), below is a simple data directory structure of the installed MySQL:
[root@lx25 mysql]# ls -ltotal 12drwxr-xr-x 5 mysql mysql 4096 Jul  2 09:26 datadrwxr-xr-x 2 mysql mysql 4096 Jul  1 18:21 logdrwxr-xr-x 2 mysql mysql 4096 Jul  2 09:26 tmp[root@lx25 mysql]# cd data[root@lx25 data]# ls -ltotal 6314044drwx------ 2 mysql mysql       4096 Jul  1 17:17 mysqldrwx------ 2 mysql mysql       4096 Jul  1 17:17 performance_schemadrwx------ 2 mysql mysql       4096 Jul  1 17:17 test
Use the Tartar package (named data.tar) as the Directory and decompress it to the data directory of the newly installed MySQL instance. 4. Compile the automatic installation and deployment script. Before running this script, we must copy the rpm packages, my. the cnf template and data directory template are placed in a fixed place. In this example, they are placed on the internal ftp of the enterprise. The MySQL automatic installation and deployment script (named mysql_install.sh) is as follows:
#!/bin/sh#Step 1: Prepareyum install cmake gcc g++ bison ncurses-devel zlib groupadd mysqluseradd -g mysql mysql#Step 2: Get 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 /opt/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqldchmod 755 /etc/init.d/mysqldchkconfig mysqld on/etc/init.d/mysqld start


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.