Fpm 之 Mysql-5.7.21 rpm 包制作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Fpm 之 Mysql-5.7.21 rpm 包制作相关的知识,希望对你有一定的参考价值。
Fpm 之 mysql-5.7.21 rpm 包制作
一、首先将mysql-5.7.21编译安装包,安装到自定义的目录
1. 下载安装包
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21.tar.gz
2.安装依赖包
yum -y install gcc gcc-c++ ncurses ncurses-devel cmake
3.添加mysql 用户与组
groupadd mysql
useradd -r -g mysql mysql
4.新建MYSQL的安装目录,与数据存放目录
mkdir -p /app/mysql
mkdir -p /app/data
5.解压安装
tar -zxvf boost_1_59_0.tar.gz
tar -zxvf mysql-5.7.21.tar.gz
cd mysql-5.7.21 #进入mysql的解压目录
6.使用cmake 编译mysql
cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql -DMYSQL_DATADIR=/app/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/root/boost_1_59_0 -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1
7.编译安装mysql
make && make install
8.设置开机自动启动脚本
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
9.修改MYSQL的环境变量
vi /etc/profile
export PATH=$PATH:/app/mysql/bin
source /etc/profile
10.修改MYSQL所在目录权限
chown -R mysql:mysql /app/mysql
11.初始化MYSQL数据库
[[email protected] ~]# /app/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data
2018-03-26T07:31:17.298033Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-26T07:31:18.332278Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-03-26T07:31:18.436844Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-03-26T07:31:18.453099Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: ac7149bc-30c7-11e8-999a-005056804f18.
2018-03-26T07:31:18.458082Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2018-03-26T07:31:18.458468Z 1 [Warning] [email protected] is created with an empty password ! Please consider switching off the --initialize-insecure option.
[[email protected] ~]# ll /app/data/
total 110620
-rw-r-----. 1 mysql mysql 56 Mar 26 15:31 auto.cnf
-rw-r-----. 1 mysql mysql 420 Mar 26 15:31 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 Mar 26 15:31 ibdata1
-rw-r-----. 1 mysql mysql 50331648 Mar 26 15:31 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 Mar 26 15:31 ib_logfile1
drwxr-x---. 2 mysql mysql 4096 Mar 26 15:31 mysql
drwxr-x---. 2 mysql mysql 4096 Mar 26 15:31 performance_schema
drwxr-x---. 2 mysql mysql 12288 Mar 26 15:31 sys
12.修改配置文件,如下:
vi /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
user = mysql
basedir = /app/mysql
datadir = /app/mysql/data
port=3306
server-id = 1
socket=/tmp/mysql.sock
character-set-server = utf8
#log-error = /var/log/mysql/error.log
#pid-file = /var/log/mysql/mysql.pid
general_log = 1
skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 28M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
myisam_sort_buffer_size = 8M
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES
[mysqldump]
quick
max_allowed_packet = 16M
13.创建错误日志与PID存放位置
mkdir -p /var/log/mysql/
chown -R mysql:mysql /var/log/mysql/
14.启动mysql
[[email protected] mysql]# service mysqld start
Starting MySQL.[ OK ]
[[email protected] mysql]# netstat -tlnp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 27565/mysqld
二、制作rpm包安装后的运行脚本
[[email protected] mysql]#mkdir -p /app/mysql/script #存放安装后的运行脚本
[[email protected] mysql]#cp /etc/my.cnf . #将mysql的配置文件复制到该目录
[[email protected] mysql]#vi server.sh #rpm包安装后的要运行的脚本
#!/bin.bash
#add mysql user
groupadd mysql
useradd -r -g mysql mysql
#制作自启动服务
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
#添加环境变量
echo "export PATH=$PATH:/app/mysql/bin" >> /etc/profile
#环境变量生效,但貌似不起作用,需后续在客户端运行
source /etc/profile
#修改mysql安装目录的权限
chown -R mysql:mysql /app/mysql
#复制配置文件到相应路径
cp /app/mysql/script/my.cnf /etc/
三、生成rpm包
fpm -s dir -t rpm -n mysql -v 5.7.21 -d ‘gcc,gcc-c++,ncurses,ncurses-devel,cmake‘ --post-install /app/mysql/script/server.sh -f /app/mysql/
四、到客户端测试安装rpm包
[[email protected] ~]# ll | grep mysql-5.7.21-1.x86_64.rpm
-rw-r--r-- 1 root root 469765290 Jun 13 20:57 mysql-5.7.21-1.x86_64.rpm
[[email protected] ~]# yum -y localinstall mysql-5.7.21-1.x86_64.rpm
五、安装完后的效果
[[email protected] ~]# ll /app/ #指定了安装目录
total 8
drwxr-xr-x 12 mysql mysql 4096 Jun 13 20:07 mysql
drwxr-xr-x 4 root root 4096 Jun 13 16:53 software
[[email protected] ~]# chkconfig | grep mysqld #添加了自启动服务
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[[email protected] ~]# service mysqld start #启动成功
Starting MySQL.[ OK ]
以上是关于Fpm 之 Mysql-5.7.21 rpm 包制作的主要内容,如果未能解决你的问题,请参考以下文章