自建mysql8 yum源服务器
使用mysql官方yum 库来安装mysql,因网络原因,安装较慢,且易超时。 于是使用自建的yum源来提供安装,提高安装效率。
下文以yum 安装mysql8.0.20为例介绍自建yum源服务器
1、从mysql官网找到rpm安装包,以下以版本8.0.20为例
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/
找到下面6个rpm包,下载下来之后上传至centos7 web 服务器上,如我上传到目录/usr/local/nginx/soft/mysql8.0.20/
mysql-community-client-8.0.20-1.el7.x86_64.rpm
mysql-community-common-8.0.20-1.el7.x86_64.rpm
mysql-community-devel-8.0.20-1.el7.x86_64.rpm
mysql-community-libs-8.0.20-1.el7.x86_64.rpm
mysql-community-server-8.0.20-1.el7.x86_64.rpm
mysql80-community-release-el7-6.noarch.rpm
2、创建mysql-yum源
使用命令 createrepo 创建mysql的yum源,若命令不存在,使用 yum -y install createrepo来安装createrepo
cd /usr/local/nginx/soft/mysql8.0.20/ && createrepo .
或者
createrepo /usr/local/nginx/soft/mysql8.0.20/
执行命令后,会在该目录下生成repodata 目录,有repodata 目录的才可以作为 yum 源。
后期如果有新的rpm包更新,执行以下命令即可:
cd /usr/local/nginx/soft/mysql8.0.20/ && createrepo --update .
3、 编写安装脚本
脚本文件 /usr/local/nginx/html/soft/mysql8.0.20/install.sh , 内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #!/bin/bash cat > /etc/yum.repos.d/mysql8.0.20.repo <<EOF [mysql-community-server] name=MySQL 8.0.20 Community Server baseurl=http://repo.huadingyun.cn/yum/mysql8.0.20/ enabled=1 gpgcheck=0 EOF yum clean all yum makecache all yum remove mariadb* -y yum install mysql-community-server -y echo lower_case_table_names=1 >> /etc/my.cnf echo max_connections=1000 >> /etc/my.cnf echo sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION >> /etc/my.cnf /bin/systemctl start mysqld.service /bin/systemctl enable mysqld.service echo -e "\033[42m get password 'cat /var/log/mysqld.log' \033[0m" |
4、搭建repo http服务器,提供yum库服务
以nginx为例, repo站点配置如下
cat /usr/local/nginx/conf/vhost/repo.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | server { listen 80; listen 443 ssl http2; charset utf-8; server_name repo.huadingyun.cn; access_log logs/repo.access.log main; error_log logs/repo_error.log error; location /yum/ { alias /usr/local/nginx/html/soft/; autoindex on; #打开目录浏览功能 autoindex_format html; #以html风格将目录展示在浏览器中 autoindex_localtime on; #默认为off,显示的文件时间为GMT时间, 改为on后,显示的文件时间为文件的服务器时间 index index.htm index.html; } ssl_certificate ssl/6491511__huadingyun.cn.pem; ssl_certificate_key ssl/6491511__huadingyun.cn.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl_prefer_server_ciphers on; } |
5、 使用方法
在需要安装mysql8.0.20的主机上,执行下面的命令进行安装
1 | curl -sSL https://repo.huadingyun.cn/yum/mysql8.0.20/install.sh | bash |
curl命令参数说明
curl -s 静默模式,不输出任何东西; -S 显示错误, 在选项-s中,当 curl 出现错误时将显示; -L 跟踪重定向。