k8s记录-docker源码安装mysql5.7.20

1.下载mysql源码

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz 

2.新建my.cnf文件

[client]                            
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]                           
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]                          
user = mysql                  
basedir = /usr/local/mysql      
datadir = /usr/local/mysql/data    
port = 3306                    
character_set_server=utf8          
pid-file = /usr/local/mysql/mysqld.pid     
socket = /usr/local/mysql/mysql.sock    
server-id = 1

3.新建dockerfile文件

FROM centos:7
ADD mysql-boost-5.7.20.tar.gz /opt
WORKDIR /opt/mysql-5.7.20/
RUN yum -y update
RUN yum -y install \
cmake \
ncurses \
ncurses-devel \
bison \
gcc gcc-c++ \
make
RUN useradd -s /sbin/nologin mysql
RUN cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc/ \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
RUN make && make install
RUN chown -R mysql:mysql /usr/local/mysql/
RUN rm -rf /etc/my.cnf
ADD my.cnf /etc
ENV PATH /usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
WORKDIR /usr/local/mysql
RUN bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql/ \
--datadir=/usr/local/mysql/data
RUN cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
EXPOSE 3306
RUN echo -e "#!/bin/sh  \nsystemctl enable mysqld" > /run.sh
RUN chmod 755 /run.sh
RUN sh /run.sh
CMD ["init"]

nginx-14.2

 

FROM centos:7
RUN yum -y install vim net-tools bridge-utils firewalld bc iotop bc gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel zip unzip zlib-devel lrzsz tree ntpdate telnet lsof tcpdump wget libevent libevent-devel systemd-devel bash-completion traceroutepsmisc
RUN mkdir -p /data/projects/common/nginx
RUN useradd nginx -s /sbin/nologin -u 2000
ADD nginx-1.14.2.tar.gz /data/projects/common
RUN cd /data/projects/common/nginx-1.14.2 && ./configure --prefix=/data/projects/common/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module && make && make install && ln -sv /data/projects/common/nginx/sbin/nginx /usr/sbin/nginx
CMD ["nginx","-g","daemon off;"]
EXPOSE 80
EXPOSE 443

 

mysql5.6

 

FROM centos:7
RUN mkdir -p /data/projects/common/mysql
ADD mysql-5.6.20.tar.gz /data/projects/common
WORKDIR /data/projects/common/mysql-5.6.20/
RUN yum -y update
RUN yum -y install \
cmake \
ncurses \
ncurses-devel \
bison \
gcc gcc-c++ \
perl \
autoconf \
make
RUN useradd -s /sbin/nologin mysql
RUN cmake \
-DCMAKE_INSTALL_PREFIX=/data/projects/common/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DSYSTEMD_PID_DIR=/data/projects/common/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/data/projects/common/mysql/data 
RUN make && make install
RUN chown -R mysql:mysql /data/projects/common/mysql/
RUN rm -rf /etc/my.cnf
ADD my.cnf /etc
ENV PATH /data/projects/common/mysql/bin:/data/projects/common/mysql/lib:$PATH
WORKDIR /data/projects/common/mysql 
RUN scripts/mysql_install_db --user=mysql --basedir=/data/projects/common/mysql/ --datadir=/data/projects/common/mysql/data
EXPOSE 3306
CMD ["/data/projects/common/mysql/bin/mysqld_safe"]

 

4.执行

build:docker build -t mysql:centos .
运行:docker run --name=mysql_server -d -P --privileged mysql:centos
进入容器:docker exec -it 容器id /bin/bash
修改密码:
mysql -u root -p
Enter password:                #此处直接回车
grant all privileges on *.* to 'root'@'%' identified by 'abc123';
grant all privileges on *.* to 'root'@'localhost' identified by 'abc123';
flush privileges
exit
posted @ 2020-05-13 11:22  信方  阅读(806)  评论(0编辑  收藏  举报