当前位置:   article > 正文

docker搭建LNMP+wordpress

docker搭建LNMP+wordpress

一、前期准备

  1.1 搭建项目环境

    公司在实际的生产环境中需要使用Docker技术在一台主机上创建LNMP服务并运行Wordpress网站平台。然后对此服务进行相关的性能调优和管理工作。

  1.2 安装包下载

wget http://101.34.22.188/lnmp_wordpress/mysql-boost-5.7.20.tar.gz
wget http://101.34.22.188/lnmp_wordpress/nginx-1.12.0.tar.gz
wget http://101.34.22.188/lnmp_wordpress/php-7.1.10.tar.bz2
wget http://101.34.22.188/lnmp_wordpress/wordpress-4.9.4-zh_CN.tar.gz
> 或者
wget -r -np http://101.34.22.188/lnmp_wordpress/

  1.3 服务器环境

容器操作系统IP地址主要软件
nginxCentOS  7172.20.0.10Docker-Nginx
mysqlCentOS  7172.20.0.20Docker-Mysql
phpCentOS  7172.20.0.30Docker-php

  1.4 任务需求

使用 Docker 构建 LNMP 环境并运行 Wordpress 网站平台
限制 Nginx 容器最多使用500MB的内存和1G的 Swap
限制 Mysql 容器写/dev/sda的速率为10MB/s
将所有容器进行快照,然后将 Docker 镜像打包成tar包备份到本地

二、实验部署

  2.1 nginx

  2.1.1 前期准备

    关闭防火墙 

systemctl stop firewalld

setenforce 0 

  2.1.2 创建并进入nginx文件夹,下载压缩包

mkdir /opt/nginx/

cd /opt/nginx/

  2.1.3 编辑Dockerfile

vim Dockerfile

FROM centos:7
MAINTAINER this is nginx image <cht>
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make
RUN useradd -M -s /sbin/nologin nginx
ADD nginx-1.12.0.tar.gz /usr/local/src/
WORKDIR /usr/local/src/nginx-1.12.0
RUN ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module && make -j4 && make install
ENV PATH /usr/local/nginx/sbin:$PATH
ADD nginx.conf /usr/local/nginx/conf/
#ADD wordpress-4.9.4-zh_CN.tar.gz /usr/local/nginx/html/
RUN chmod 777 -R /usr/local/nginx/html/
EXPOSE 80
EXPOSE 443
ENTRYPOINT [ "/usr/local/nginx/sbin/nginx", "-g", "daemon off;" ]

  2.1.4 编辑nginx

vim nginx.conf

  2.1.5 过滤nginx配置文件内容

egrep -v "^(.)*#(.)*$" nginx.conf | grep -v "^$"

  2.1.6 创建html文件夹,压缩文件到创建的文件夹内

mkdir /opt/nginx/html/

tar zxvf wordpress-4.9.4-zh_CN.tar.gz -C /opt/nginx/html/

  2.1.7 生成镜像

docker build -t nginx:lnmp .

  2.1.8 创建容器

docker network create --subnet=172.18.0.0/16 --opt "com.docker.network.bridge.name"="docker" mynetwork

  2.1.9 在后台启动镜像容器:

docker run -d --name nginx -p 80:80 -v /opt/nginx/html:/usr/local/nginx/html --net mynetwork --ip 172.18.0.10 nginx:lnmp

docker ps

  2.2 mysqld

  2.2.1 前期准备

systemctl stop firewalld

setenforce 0

  2.2.2 创建并进入mysqld文件夹

mkdir /opt/mysqld

cd /opt/mysqld

  2.2.3 编辑Docker

vim Dockerfile

FROM centos:7
MAINTAINER this is mysql image <cht>
RUN yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake make
ADD mysql-boost-5.7.20.tar.gz /usr/local/src/
WORKDIR /usr/local/src/mysql-5.7.20/
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 && make -j 2 && make install
ADD my.cnf /etc/
ENV PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
RUN useradd -M -s /sbin/nologin  mysql
RUN chown mysql:mysql /etc/my.cnf
RUN chown -R mysql:mysql /usr/local/mysql/
RUN /usr/local/mysql/bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
EXPOSE 3306
CMD ["/usr/local/mysql/bin/mysqld"] 

  2.2.4 编辑mysql核心文件

vim my.cnf

[client]
port = 3306
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
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

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

  2.2.5 查看mysql文件下的内容

  2.2.6 生成镜像

docker build -t mysql:lnmp .

  2.2.7 启动容器并初始化

docker run --name=mysql -d --privileged -v /usr/local/mysql --net mynetwork --ip 172.18.0.20 mynetwork

  2.2.8 查看mysqld状态

    这里需要退出容器,再查看mysql状态

exit

systemctl status mysqld

  2.3 php

  2.3.1 前期准备

systemctl stop firewalld

setenforce 0

  2.3.2 创建并切换到文件夹下

mkdir /opt/php

cd /opt/php/

ls

  2.3.3 编辑Dockerfile

egrep -v "^;" www.conf | egrep -v "^$"

  2.3.4 编辑php-fpm配置文件

vim php-fpm.conf

egrep -v "^;" php-fpm.conf | egrep -v "^$"

  2.3.5 编辑www配置文件

egrep -v "^;" www.conf | egrep -v "^$"

  2.3.6 编辑php.ini

egrep -v "^;" php-ini | egrep -v "^$"

  2.3.7 生成镜像

dcoker build -t php:lnmp

  2.3.8 查看所有镜像状态

docker images

  2.3.9 创建容器并在后台启动

dcoekr run --name=php -d -p 9000:9000 --volumes-from mysql --volumes-from nginx --net mynetwork --ip 172.18.0.30 php:lnmp

  2.3.10 查看当前镜像

docker ps

  2.3.11 切换到mysql下查看进程

docker exec -it mysql /bin/bash

  2.4 测试

    这里加上您的IP地址/wordpress/index.php

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/565179
推荐阅读
相关标签
  

闽ICP备14008679号