Step 6 of automated MySQL5.6 deployment
Before preparation, you must set up ftpserver.
yum install vsftpd service vsftpd start
In this way, the ftp service is up. It is simple to use, so no configuration file is used. In this way, you only need to place the required files in the/var/ftp/pub/folder, and anonymous users can copy the files to the local machine.
Install rpm-build
Rpm-build is required for build. You can simply install it here.
yum install rpm-build
Start rpm packaging below
mget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.21.tar.gzcd /u01/mysql-5.6.21mkdir rpmcd rpm
Modify mysql. spec
Name: mysql-rpmVersion:5.6.21Release: renfengjunLicense: GPLURL: http://dev.mysql.com/Group: applications/databaseBuildRoot:%{_tmppath}/%{name}-%{version}-%{release}-rootBuildRequires: cmakePackager: dexter.ren.jl@gmail.comAutoreq: noprefix: /u01/mysqlSummary: mysql-5.6.21.tar.gz %descriptionThe 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-loadproduction 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 CXXFLAGS cmake . \ -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}/* %premkdir -p /u01/mysql/datamkdir -p /u01/mysql/runmkdir -p /u01/mysql/loggroupadd mysqluseradd -g mysql mysqlchown -R mysql:mysql /u01/mysql/datachown -R mysql:mysql /u01/mysql/logchown -R mysql:mysql /u01/mysql/runecho "exportPATH=$PATH:/u01/mysql/bin" >> /home/mysql/.bash_profile %postln -s %{prefix}/lib %{prefix}/lib64cp /u01/mysql/support-files/mysql.server/etc/init.d/mysqlchkconfig mysql on %preunchkconfig --del mysqlrm -rf /u01userdel mysqlrm -rf /var/spool/mail/mysqlrm -rf /etc/init.d/mysqlrm -rf /home/mysql %changelog
Run the packaging command
Rpmbuild-bb./mysql. spec
Output:
Requires(pre): /bin/shRequires(post): /bin/shRequires(preun): /bin/shChecking for unpackaged file(s):/usr/lib/rpm/check-files /var/tmp/mysql-rpm-5.6.21-renfengjun-rootwarning: Could not canonicalize hostname:centos511Wrote:/usr/src/redhat/RPMS/x86_64/mysql-rpm-5.6.21-renfengjun.x86_64.rpmExecuting(%clean): /bin/sh -e /var/tmp/rpm-tmp.62530+ umask 022+ cd /usr/src/redhat/BUILD+ rm -rf/var/tmp/mysql-rpm-5.6.21-renfengjun-root+ exit 0
The generated rpm package is here:
/Usr/src/redhat/RPMS/x86_64/mysql-rpm-5.6.21-renfengjun.x86_64.rpm
Packaging data templates
When packaging, remember to close mysql. Here we have written some test data:
mysql> select * from dexdb.t ;+------+------------+| id |name |+------+------------+| 1 |renfengjun |+------+------------+1 row in set (0.00 sec)
Pack the data template. Remember to package ibdata1
Cd/u01/mysql/data
Tar cf data.tar ibdata1 mysql/dexdb/performance_schema/test/
Modify my. cnf
My. cnf file content:
[mysqld_safe]pid-file=/u01/mysql/run/mysqld.pid#malloc-lib=/u01/mysql/lib/libjemalloc.so [mysql]port=3306prompt=\\u@\\d \\r:\\m:\\s>default-character-set=gbkno-auto-rehash [client]port=3306socket=/u01/mysql/run/mysql.sock [mysqld]#dirbasedir=/u01/mysqldatadir=/u01/mysql/datatmpdir=/tmplc_messages_dir=/u01/mysql/sharelog-error=/u01/mysql/log/alert.logslow_query_log_file=/u01/mysql/log/slow.loggeneral_log_file=/u01/mysql/log/general.logsocket=/u01/mysql/run/mysql.sock #innodbinnodb_data_home_dir=/u01/mysql/datainnodb_log_group_home_dir=/u01/mysql/datainnodb_data_file_path=ibdata1:12Minnodb_buffer_pool_size=10Ginnodb_buffer_pool_instances=4innodb_log_files_in_group=2innodb_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=1000innodb_thread_concurrency=16innodb_read_io_threads=8innodb_write_io_threads=8innodb_open_files=60000innodb_file_format=Barracudainnodb_file_per_table=1innodb_flush_method=O_DIRECTinnodb_change_buffering=insertsinnodb_adaptive_flushing=1innodb_old_blocks_time=1000innodb_stats_on_metadata=0innodb_read_ahead=0innodb_use_native_aio=0innodb_lock_wait_timeout=5innodb_rollback_on_timeout=0innodb_purge_threads=1innodb_strict_mode=1transaction-isolation=READ-COMMITTED #myisamkey_buffer=64Mmyisam_sort_buffer_size=64Mconcurrent_insert=2delayed_insert_timeout=300 #replicationmaster-info-file=/u01/mysql/log/master.inforelay-log=/u01/mysql/log/relaylogrelay_log_info_file=/u01/mysql/log/relay-log.inforelay-log-index=/u01/mysql/log/mysqld-relay-bin.indexslave_load_tmpdir=/u01/mysql/tmpslave_type_conversions="ALL_NON_LOSSY"slave_net_timeout=4skip-slave-startsync_master_info=1000sync_relay_log_info=1000 #binloglog-bin=/u01/mysql/log/mysql-bin#server_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=1#sqlmod="STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE"performance_schema=0 log_slow_admin_statements=1log_warnings=1long_query_time=1slow_query_log=1general_log=0 query_cache_type=0query_cache_limit=1Mquery_cache_min_res_unit=1K table_definition_cache=65536#table_cache=65536 thread_stack=512Kthread_cache_size=256read_rnd_buffer_size=128Ksort_buffer_size=256Kjoin_buffer_size=128Kread_buffer_size=128K port=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
Serverid is automatically generated in the automated installation script.
Copy the existing data.tar, my. cnf, and generated rpm packages to the ftp pub directory.
/Var/ftp/pub/
Automated installation script
Auto_install_mysql.sh:
#!/bin/shyum install -y cmake gcc g++ bisonncurses-devel zlib ftp -n<<EOFopen 192.168.0.33user anonymous dexterbinarycd pubpromptmget *EOF rpm -ivh mysql-rpm-5.6.21-renfengjun.x86_64.rpmtar -xvf data.tar -C /u01/mysql/data/chown -R mysql:mysql /u01/mysql/ unique_id=`date "+%Y%m%d%M%S"`echo 'server_id='$unique_id >> my.cnf cp my.cnf /u01/mysql/
Run the remote automatic installation command
Execute remote copy (the dcli command is the script I took out from the all-in-one machine, which is written in py. In fact, it is similar to scp and can send emails if necessary)
For batch installation, use the-k option to initialize ssh.
Copy the script to a remote device
[Root @ centos511 ~] #./Dcli-l root-c192.168.0.36-f./auto_install_mysql.sh
Attackers can execute remote commands in the background.
[Root @ centos511 ~] #./Dcli-l root-c192.168.0.36/root/auto_install_mysql.sh
Output:
[[root@centos511 ~]# ./dcli -l root -c192.168.0.36 /root/get_rpm.shroot@192.168.0.36's password:192.168.0.36: Address 192.168.0.36 maps tolocalhost, but this does not map back to the address - POSSIBLE BREAK-INATTEMPT!192.168.0.36: Loaded plugins: fastestmirror,security192.168.0.36: Loading mirror speeds from cachedhostfile192.168.0.36: * base: mirrors.btte.net192.168.0.36: * extras: mirrors.btte.net192.168.0.36: * updates: mirrors.yun-idc.com192.168.0.36: Setting up Install Process192.168.0.36: Packagecmake-2.6.4-5.el5.4.x86_64 already installed and latest version192.168.0.36: Package gcc-4.1.2-55.el5.x86_64already installed and latest version192.168.0.36: No package g++ available.192.168.0.36: Package bison-2.3-2.1.x86_64already installed and latest version192.168.0.36: Packagencurses-devel-5.5-24.20060715.x86_64 already installed and latest version192.168.0.36: Packagencurses-devel-5.5-24.20060715.i386 already installed and latest version192.168.0.36: Package zlib-1.2.3-7.el5.x86_64already installed and latest version192.168.0.36: Package zlib-1.2.3-7.el5.i386already installed and latest version192.168.0.36: Nothing to do192.168.0.36: Please login with USER and PASS.192.168.0.36: Please login with USER and PASS.192.168.0.36: KERBEROS_V4 rejected as anauthentication type192.168.0.36: Interactive mode off.192.168.0.36: Preparing... ##################################################192.168.0.36: mysql-rpm ##################################################.......
End.
Verify
[root@study2 ~]# service mysql startStarting MySQL.......................[ OK ] [root@study2 ~]# su - mysqlmys[mysql@study2 ~]$ mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.21-r5436-log Sourcedistribution Copyright (c) 2000, 2014, Oracle and/or itsaffiliates. All rights reserved. Oracle is a registered trademark of OracleCorporation and/or itsaffiliates. Other names may be trademarks oftheir respectiveowners. Type 'help;' or '\h' for help. Type '\c' toclear the current input statement. root@(none) 12:29:11>show databases ;+--------------------+| Database |+--------------------+| information_schema || dexdb || mysql || performance_schema || test |+--------------------+5 rows in set (0.37 sec) root@(none) 12:29:14>use dexdb ;Database changedroot@dexdb 12:29:17>select * from t ;+------+------------+| id |name |+------+------------+| 1 |renfengjun |+------+------------+1 row in set (0.19 sec) root@dexdb 12:29:19>quitBye [root@study2 ~]# service mysql stopShutting down MySQL.[ OK ]
It's rough and there's something to improve. Complete it slowly.