使用 docker-compose 编排 lnmp(dockerfile) 完成 wordpress

embedded/2024/11/25 17:58:49/

一、使用 docker-compose 编排 lnmp(dockerfile) 完成 wordpress

环境准备

##修改主机名
hostnamectl set-hostname lyh
bash
[root@lyh ~]###关闭防火墙及核心防护
systemctl stop firewalld     ##关闭核心防护
setenforce 0                 ##关闭核心防护##安装Docker-20版本
yum install -y yum-utils device-mapper-persistent-data lvm2           ##下载依赖环境
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo                          ##设置阿里云镜像源
yum install -y docker-ce-20.10.18 docker-ce-cli-20.10.18 containerd.io       ##安装docker-20版本systemctl start docker.service    ##开启docker服务
systemctl enable docker.service   ##开启docker开机自启##下载centos:7镜像
docker pull centos:7 docker images

1.1、创建相关的文件夹

mkdir /opt/compose_lnmp/nginx -p
mkdir /opt/compose_lnmp/php -p
mkdir /opt/compose_lnmp/mysql -p
ls /opt/compose_lnmp/
mysql  nginx  php

1.2、docker-compose编排nginx

1.2.1在nginx下创建Dockerfile文件

vim Dockerfile    ##编写Dockerfile文件FROM centos:7
MAINTAINER this is nginx image <lyh>
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make && 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;" ]

1.2.2修改nginx.conf的配置文件

[root@lyh nginx]#ls
Dockerfile
[root@lyh nginx]#rz -E
rz waiting to receive.
[root@lyh nginx]#ls
Dockerfile  nginx.conf
[root@lyh nginx]#vim nginx.conf

1.2.3上传相关压缩包

[root@lyh nginx]#ls
Dockerfile  nginx.conf##上传相关压缩包
[root@lyh nginx]#ls
Dockerfile  nginx-1.12.0.tar.gz  nginx.conf  wordpress-4.9.4-zh_CN.tar.gz

1.2.4创建html目录

将wordpress-4.9.4-zh_CN.tar.gz压缩包解压到 html文件夹内

[root@lyh nginx]#ls
Dockerfile  nginx-1.12.0.tar.gz  nginx.conf  wordpress-4.9.4-zh_CN.tar.gz
[root@lyh nginx]#mkdir html
[root@lyh nginx]#cd html/
[root@lyh html]#ls
[root@lyh html]#tar xf ../wordpress-4.9.4-zh_CN.tar.gz -C /opt/compose_lnmp/nginx/html/
[root@lyh html]#ls
wordpress
[root@lyh html]#cd wordpress/
[root@lyh wordpress]#ls
index.php    wp-activate.php     wp-comments-post.php  wp-cron.php        wp-load.php   wp-settings.php   xmlrpc.php
license.txt  wp-admin            wp-config-sample.php  wp-includes        wp-login.php  wp-signup.php
readme.html  wp-blog-header.php  wp-content            wp-links-opml.php  wp-mail.php   wp-trackback.php
[root@lyh wordpress]#ls /opt/compose_lnmp/nginx/
Dockerfile  html  nginx-1.12.0.tar.gz  nginx.conf  wordpress-4.9.4-zh_CN.tar.gz

1.3、docker-compose编排mysql

1.3.1准备压缩包

[root@lyh html]#pwd
/opt/compose_lnmp/nginx/html
[root@lyh html]#cd /opt/compose_lnmp/mysql/
[root@lyh mysql]#ls##上传相关文件及压缩包
mysql-boost-5.7.20.tar.gz

1.3.2编写Dockerfile文件

#vim DockerfileFROM centos:7
MAINTAINER this is mysql image <lyh1>
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 && 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"]

1.3.3编写my.cnf文件

vim my.cnf[client]
port = 3306
socket=/usr/local/mysql/mysql.sock[mysql]
port = 3306
socket = /usr/local/mysql/mysql.sock
auto-rehash[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
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1sql_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

1.4、docker-compose编排php

1.4.1准备php相关配置文件及压缩包

##上传相关压缩包及配置文件
[root@lyh php]#ls
php-7.1.10.tar.bz2  php-fpm.conf  php.ini  www.conf

1.4.2编写Dockerfile文件

[root@docker php]# vim Dockerfile FROM centos:7
MAINTAINER this is php image <lnmp>
RUN yum install -y gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel \
gcc gcc-c++ make pcre-devel;useradd -M -s /sbin/nologin nginx
ADD php-7.1.10.tar.bz2 /usr/local/src/
WORKDIR /usr/local/src/php-7.1.10
RUN ./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip && make -j 4 && make install
ENV PATH /usr/local/php/bin:/usr/local/php/sbin:$PATH
ADD php.ini     /usr/local/php/lib/
ADD php-fpm.conf /usr/local/php/etc/
ADD www.conf /usr/local/php/etc/php-fpm.d/
EXPOSE 9000
CMD /usr/local/php/sbin/php-fpm -F

1.4.3修改php相关配置文件

1.4.3.1修改php.ini

该配置文件模板位于安装目录的php-7.1.10/php.ini-development位置

[root@lyh php]# vim php.ini#939行,取消注释,修改
date.timezone = Asia/Shanghai
#1170行,修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
[root@lyh php]# egrep -v "^;" php.ini | egrep -v "^$"

1.4.3.2修改php-fpm.conf

该配置文件模板位于/usr/local/php/etc/php-fpm.conf.default

[root@lyh php]# vim php-fpm.conf #17行,删除注释符号“;”
pid = run/php-fpm.pid[root@lyh php]# egrep -v "^;" php-fpm.conf | egrep -v "^$"

1.4.3.3修改www.conf

该配置文件模板位于usr/local/php/etc/php-fpm.d/www.conf.default

[root@lyh php]# vim www.conf #23、24行,修改用户和组
user = nginx
group = nginx
#36行,修改监听IP和端口为容器IP:9000端口
listen = 172.19.0.30:9000
[root@lyh php]# egrep -v "^;" www.conf | egrep -v "^$"

1.5、安装docker-compose

1.5.1下载或上传docker-compose

[root@lyh opt]#pwd
/opt
[root@lyh opt]#ls
compose_lnmp  containerd  rh
[root@lyh opt]#rz -E          ##上传Docker-compose文件
rz waiting to receive.
[root@lyh opt]#ls
compose_lnmp  containerd  docker-compose  rh

1.5.2给docker-compose添加权限

[root@lyh opt]#ls
compose_lnmp  containerd  docker-compose  rh
[root@lyh opt]#chmod +x docker-compose 
[root@lyh opt]#ls
compose_lnmp  containerd  docker-compose  rh

1.5.3将docker-compose移动到/usr/local/bin路径下

[root@lyh opt]#ls
compose_lnmp  containerd  docker-compose  rh
[root@lyh opt]#mv docker-compose /usr/local/bin/
[root@lyh opt]#ls
compose_lnmp  containerd  rh
[root@lyh opt]#ls /usr/local/bin/
docker-compose

1.5.4查看docker-compose的版本

[root@lyh opt]#ls /usr/local/bin/
docker-compose
[root@lyh opt]#docker-compose --version
docker-compose version 1.21.1, build 5a3f1a3

1.6、编写docker-compose.yml文件

如果粘贴,vim编辑器请输入  :set paste

version: '3'
services:nginx:container_name: nginx     #指定容器的名称为nginx hostname: nginx           #容器的主机名为nginxbuild:                    #构建上下文和Dockerfile的位置context: /opt/compose_lnmp/nginx/dockerfile: Dockerfileports:- 80:80- 443:443 #将宿主机的80端口映射到容器的80端口,将宿主机的443端口映射到容器的443端口#设置数据卷挂载volumes:- /opt/compose_lnmp/nginx/html:/usr/local/nginx/htmlnetworks:lnmp:ipv4_address: 172.18.0.10mysql:container_name: mysqlbuild:context: /opt/compose_lnmp/mysqldockerfile: Dockerfileports:- 3306:3306networks:lnmp:ipv4_address: 172.18.0.22
volumes:- db-data:/usr/local/mysqlprivileged: truephp:container_name: phpbuild:context: /opt/compose_lnmp/phpdockerfile: Dockerfileports:- 9000:9000networks:lnmp:ipv4_address: 172.18.0.33volumes:- db-data:/usr/local/mysql- ./nginx/html:/usr/local/nginx/htmldepends_on:- nginx- mysqlnetworks:lnmp:driver: bridgeipam:config:- subnet: 172.18.0.0/16volumes:db-data:

1.7、启动服务

##在当前路径下运行下行命令
docker-compose -f docker-compose.yml up -d 

1.7.1报错

ittp://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86 64/repodata/repomd.xml: [Errno 14l curl#6"Could not resolve host: mirrors,ustc.edu.cn: Unknown error.rying other mirror.##大概意思就是网络的问题,需要修改DNS以及添加路由

##修改网络及域名
vim /etc/sysconfig/network-scripts/ifcfg-ens33  DNS2=114.114.114.114##添加路由
vim /etc/sysctl.confnet.ipv4.ip_forward=1##退出后,生效路由
sysct -p##然后加载、重启网络及Docker服务systemctl daemon-reload
systemctl restart network
systemctl restart docker.service

1.8、进入容器登录mysql授权

[root@lyh php]#docker exec -it mysql /bin/bash
[root@28af5fe9d022 mysql-5.7.20]# mysql
mysql> mysql> create database wordpress;
Query OK, 1 row affected (0.01 sec)mysql>  grant all privileges on wordpress.* to 'wordpress'@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> grant all privileges on *.* to 'root'@'%' identified by 'abc123';
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

1.9、创建一个新的配置文件 wp-config.php

// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');/** MySQL数据库用户名 */
define('DB_USER', 'wordpress');/** MySQL数据库密码 */define('DB_PASSWORD', 'Abc123');

1.10、验证结果

##在浏览器输入 192.168.10.100/wordpress/index.php


http://www.ppmy.cn/embedded/34130.html

相关文章

前端之深拷贝

前提&#xff1a; 就是在实际开发中&#xff0c;我有一个编辑的弹窗&#xff0c;可以查看和编辑&#xff0c;因为弹窗里面是一个步骤条&#xff0c;点击下一步就要向对应的接口发送请求&#xff0c;考虑到就比如我点击下一步&#xff0c;此次表箱信息其实不需要修改&#xff0…

抓包证书安装到安卓7.0+手机

前言: 首先理解一下,这个不只是证书到浏览器,而是抓包证书到安卓7.0+手机上的文章; 还有一点区分,在浏览器上装的证书,只是让抓包工具可以抓取手机浏览器的包,而不是抓取手机app上的包; 如果你的证书只是简单的在浏览器下进行安装,那么你的手机app是走不了代理网络的…

探索CSS3文本效果:打造魅力无限的网页排版

CSS3为网页设计带来了革命性的变化&#xff0c;特别是在文本效果方面&#xff0c;它赋予了开发者前所未有的创意空间。本文将带你深入了解CSS3中一些令人兴奋的文本效果&#xff0c;从基本的阴影处理到复杂的动画效果&#xff0c;每个技巧都将通过实际代码示例展现其魅力所在。…

Linux——命名管道

管道特点 只能用于具有具体祖先的进程之间的通信&#xff0c;通常&#xff0c;一个管道由一个进程创建&#xff0c;然后该进程调用fork&#xff0c;创建子进程&#xff0c;关闭相应的读写端&#xff0c;然后父子进程就可以通信了管道提供流式服务一般而言&#xff0c;进程退出…

UDP通信

文章目录 recvfrom和sendto函数UDP通信server和client流程UDP实现的并发服务器和客户端 recvfrom和sendto函数 ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,struct sockaddr *src_addr, socklen_t *addrlen);sockfd&#xff1a; 套接字buf&#xff1a;缓冲…

PC端Discord设置代理2022

开始使用 方法非常简单&#xff0c;在此下载release.zip并解压version.dll https://github.com/aiqinxuancai/discord-proxy/releases​github.com/aiqinxuancai/discord-proxy/releases 将version.dll放在Discord.exe所在目录&#xff08;如Discord有更新&#xff0c;则可能…

自适应调节Q和R的自适应UKF(AUKF_QR)的MATLAB程序

简述 基于三维模型的UKF&#xff0c;设计一段时间的输入状态误差较大&#xff0c;此时通过对比预测的状态值与观测值的残差&#xff0c;在相应的情况下自适应调节系统协方差Q和观测协方差R&#xff0c;构成自适应无迹卡尔曼滤波&#xff08;AUKF&#xff09;&#xff0c;与传统…

Eclipse中开启服务,网页无法打开 运行程序显示404

一、eclipse中开启服务后&#xff0c;网页无法打开的问题 当你在eclipse中开启服务后&#xff0c;如果网页无法打开&#xff0c;可能是以下几个原因导致的&#xff1a; 1. 端口冲突&#xff1a;请确保你所使用的端口没有被其他程序占用。可以尝试更换一个未被占用的端口。 2…