本文共 5433 字,大约阅读时间需要 18 分钟。
本文重点是spec文件,其他步骤比较简单,笔者就不写了
mkdir -pv ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
%define MYSQL_USER mysql
%define MYSQL_GROUP mysqlName: mysqlVersion: 5.7.18Release: msxf_v2Summary: MySQL-5.7.18 RPMGroup: applications/databaseLicense: GPL URL: Source0: mysql-5.7.18.tar.gzPackager: xxxx@gmail.comBuildRoot: %{_topdir}/%{name}-%{version}-msxfBuildRequires: cmakeAutoReqProv: no%description
MySQL 5.7.18%prep
%setup -n mysql-%{version}%build
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 \-DMYSQL_DATADIR=/home/mysql/mysql3306/data \-DSYSCONFDIR=/home/mysql/mysql3306 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_EXAMPLE_STORAGE_ENGINE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \-DMYSQL_UNIX_ADDR=/home/mysql/mysql3306/mysql3306.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DENABLED_LOCAL_INFILE=ON \-DDOWNLOAD_BOOST=1 \-DWITH_BOOST=../boost_1_59_0/make %{?_smp_mflags}
%install
rm -rf %{buildroot}make install DESTDIR=$RPM_BUILD_ROOT%pre
IS_CONFIG=$( cat /etc/security/limits.conf | grep mysql | wc -l )if [ $IS_CONFIG -lt 1 ];thencat >> /etc/security/limits.conf << EOFmysql soft nproc 2047mysql hard nproc 16384mysql soft nofile 1024mysql hard nofile 65536EOFfiecho 0 > /proc/sys/vm/swappinessmkdir -p /home/mysql/mysql3306/{data,log,binlog}TOTAL_SIZE=$( free -g | grep Mem | awk '{print $2}' )ALLOC_SIZE=$(( $TOTAL_SIZE * 64 / 100 ))BUFFER_SIZE=$( echo $ALLOC_SIZE | awk -F. '{print $1}')"G"SERVER_ID=$( ip addr | grep inet | grep "255 scope global" |head -1|awk '{print $2}'|cut -d "." -f 4|cut -d "/" -f 1 )"3306"cat > /home/mysql/mysql3306/my.cnf <<EOF[mysql]default-character-set=utf8mb4[mysqld]socket=/home/mysql/mysql3306/mysql3306.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0port = 3306
#extra_port=13306basedir = /usr/local/mysql57datadir = /home/mysql/mysql3306/datapid-file = /home/mysql/mysql3306/mysql.piduser = mysqlserver-id =$SERVER_ID#rpl_semi_sync_master_enabled=1#rpl_semi_sync_master_timeout=1000#rpl_semi_sync_slave_enabled=1relay_log_purge=0read_only=0super_read_only=0slave-skip-errors=1396binlog_row_image=full# parallel replicationbinlog_group_commit_sync_delay=10binlog_group_commit_sync_no_delay_count=1000master_info_repository='TABLE'#slave_parallel_type = LOGICAL_CLOCK slave_parallel_workers = 10relay_log_info_repository='TABLE'#log_slave_updates=1
lower_case_table_names = 1character-set-server=utf8mb4skip-name-resolveskip-external-lockingback_log = 500max_connections = 2000max_connect_errors = 2000open_files_limit = 65535table_open_cache = 128 max_allowed_packet = 64Mkey_buffer_size = 128M
read_buffer_size = 64Mread_rnd_buffer_size = 16Msort_buffer_size = 32Mjoin_buffer_size = 32Mtmp_table_size = 96Mmax_heap_table_size = 96Mquery_cache_size = 16Mquery_cache_limit = 16Mthread_cache_size = 64log_bin = /home/mysql/mysql3306/binlog/mysql-bin
binlog_format = rowbinlog_cache_size = 16Msync_binlog = 1max_binlog_cache_size = 1000Mmax_binlog_size = 1Gexpire_logs_days = 10log_error = /home/mysql/mysql3306/log/mysql-error.log
slow_query_log = 1long_query_time = 0.1slow_query_log_file = /home/mysql/mysql3306/log/mysql-slow.logrelay_log=/home/mysql/mysql3306/binlog/slave-relay-binrelay_log_index=slave-relay-bin.indexdefault_storage_engine = InnoDB
innodb_buffer_pool_size = $BUFFER_SIZEinnodb_file_per_table = 1innodb_data_home_dir = /home/mysql/mysql3306/datainnodb_data_file_path = ibdata1:500M;ibdata2:1G:autoextendinnodb_log_group_home_dir = /home/mysql/mysql3306innodb_log_file_size = 500Minnodb_log_buffer_size = 96Minnodb_flush_log_at_trx_commit = 1innodb_print_all_deadlocks = 1skip-slave-start=1
gtid-mode=onenforce-gtid-consistency=trueslave-parallel-workers=8sql_mode='NO_ENGINE_SUBSTITUTION'log_timestamps=SYSTEMEOFuseradd mysqlchown -R mysql:mysql /home/mysql/mysql3306%post
/usr/local/mysql57/bin/mysqld --defaults-file=/home/mysql/mysql3306/my.cnf --initialize-insecure --user=mysqlHAVE_PROFILE_PATH=$( cat /etc/profile | grep /usr/local/mysql57 | wc -l )if [ $HAVE_PROFILE_PATH -lt 1 ];thenecho "export PATH=/usr/local/mysql57/bin:\$PATH" >> /etc/profilefiHAVE_SELF_PATH=$( cat ~/.bash_profile | grep /usr/local/mysql57 | wc -l )if [ $HAVE_SELF_PATH -lt 1 ];thenecho "export PATH=/usr/local/mysql57/bin:\$PATH" >> ~/.bash_profilefi/usr/local/mysql57/bin/mysqld_safe --defaults-file=/home/mysql/mysql3306/my.cnf &IP_ADDR=$( ip addr | grep inet | grep "255 scope global" |head -1|awk '{print $2}' | cut -d "/" -f 1 )sleep 10/usr/local/mysql57/bin/mysql -uroot -S /home/mysql/mysql3306/mysql3306.sock <<EOFcreate database if not exists temp_dba_db;alter user 'root'@'localhost' identified by 'mysql@123';flush privileges;reset master;EOFsource ~/.bash_profile
%preun%postun
rm -rf /usr/local/mysql57%clean
rm -rf %{buildroot}%files
%defattr(-, %{MYSQL_USER}, %{MYSQL_GROUP})%attr(755, %{MYSQL_USER}, %{MYSQL_GROUP}) /usr/local/mysql57/*%changelog
转载于:https://blog.51cto.com/songhl/2152087