docker部署LNMP

devtools/2024/11/14 0:59:25/

docker部署LNMP

nginx 1.22 172.111.0.10 docker-nginx

mysql 8.0.30 172.111.0.20 docker-mysql

php 8.1.27 172.111.0.30 docker-php

docker:单节点部署,只能在一台机器上部署,如果跨机器容器无法操作,无法通信。

做高可用只能在节点上增加同意服务的容器数量。

docker部署nginx:lnmp

[root@docker1 nginx]# ls
Dockerfile    nginx-1.22.0.tar.gz  wordpress-6.4.2-zh_CN.tar.gz
nginx-1.22.0  nginx.conf
[root@docker1 nginx]# vim nginx.conf 
worker_processes  1;
events {worker_connections  1024;
}
http {
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';
​include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  localhost;charset utf-8;location / {root   html;index  index.html index.php;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}location ~ \.php$ {root           html;fastcgi_pass   172.111.0.30:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;include        fastcgi_params;}
}
}
FROM centos:7
MAINTAINER this is nginx <lnmp>
RUN rm -rf /etc/yum.repos.d/*
ADD  http://mirrors.aliyun.com/repo/Centos-7.repo /etc/yum.repos.d/Centos-7.repo
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make
ADD nginx-1.22.0.tar.gz /usr/local/src/
RUN useradd -M -s /sbin/nologin nginx
WORKDIR /usr/local/src/nginx-1.22.0
RUN ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module && make -j 4 && make install
ENV PATH /usr/local/nginx/sbin/:$PATH
COPY nginx.conf /usr/local/nginx/conf/
ADD wordpress-6.4.2-zh_CN.tar.gz /usr/local/nginx/html/
EXPOSE 80
VOLUME ["/usr/local/nginx/html/"]
CMD ["/usr/local/nginx/sbin/nginx","-g","daemon off;"]
​
#执行脚本开始安装
[root@docker1 nginx]# docker build -t nginx:lnmp .
​
[root@docker1 nginx]# docker network create --subnet=172.111.0.0/16 --opt "com.docker.network.brige.name"="docker1" mynetwork
f68061fa2125dac69c56def834bd3b357df6462c1781d4265e8c406ca988b1fe
[root@docker1 nginx]# docker run -itd --name nginx -p 80:80 -m 512m -v /opt/nhtml:/opt/nginx --net mynetwork --ip 172.111.0.10 nginx:lnmp
bc334a58a6ee7f20ac03492dbf0d039b96808a8800dd4b41f72e2103fb2015cf
#进入容器
[root@docker1 nginx]# docker exec -it nginx bash
#安装检测端口
[root@bc334a58a6ee nginx-1.22.0]# yum -y install net-tools
[root@bc334a58a6ee nginx-1.22.0]# netstat -antp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1/nginx: master pro 
[root@ae62a45a641a nginx-1.22.0]# cd /usr/local/nginx/html/
[root@ae62a45a641a html]# ls
50x.html  index.html  wordpress
[root@ae62a45a641a html]# echo 123 > index.html 

docker部署MySQL:lnmp

[root@docker1 mysql]# ls
Dockerfile  my.conf  mysql-8.0.30-el7-x86_64  mysql-8.0.30-el7-x86_64.tar.gz
[root@docker1 mysql]# vim my.conf
[client]
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
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
​
[root@docker1 mysql]# vim Dockerfile 
FROM centos:7
MAINTAINER this is mysql <lnmp>
RUN rm -rf /etc/yum.repos.d/*
ADD  http://mirrors.aliyun.com/repo/Centos-7.repo /etc/yum.repos.d/Centos-7.repo
RUN yum -y install libaio numactl-libs pcre-devel zlib-devel gcc gcc-c++ make
RUN useradd -M -s /sbin/nologin mysql
ADD mysql-8.0.30-el7-x86_64.tar.gz /usr/local
RUN mv /usr/local/mysql-8.0.30-el7-x86_64 /usr/local/mysql
COPY my.conf /etc/my.cnf
EXPOSE 3306
RUN chown -R mysql:mysql /usr/local/mysql && chown mysql:mysql /etc/my.cnf
ENV PATH=/usr/local/mysql/bin/:/usr/local/mysql/lib:$PATH
WORKDIR /usr/local/mysql/bin
RUN ./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
VOLUME ["/usr/local/mysql"]
ENTRYPOINT ["./mysqld"]
​
#执行脚本开始安装
[root@docker1 mysql]# docker build -t mysql:lnmp .
[root@docker1 mysql]# docker run -itd --name mysql -p 3306:3306 --privileged -v /opt/mysql1:/opt/mysql --net mynetwork --ip 172.111.0.20 mysql:lnmp
c48b556646c6ab48892955a6b8eb3b6e1b2c47561d30fb37b8319c9fc08e18c0
[root@docker1 mysql]# docker exec -it mysql bash
[root@c48b556646c6 bin]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30 MySQL Community Server - GPL
​
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
​
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
​
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
​
mysql> 
​

docker部署php:inmp

[root@docker1 mysql]# cd /opt
[root@docker1 opt]# cd php/
#拖入三个文件
[root@docker1 php]# ls
[root@docker1 php]# rz -E
rz waiting to receive.
[root@docker1 php]# rz -E
rz waiting to receive.
[root@docker1 php]# rz -E
rz waiting to receive.
[root@docker1 php]# ls
php-fpm.conf  php.ini  www.conf
#解压php文件
root@docker1 php]# tar -xf php-8.1.27.tar.gz 
[root@docker1 php]# ls
php-8.1.27  php-8.1.27.tar.gz 
#配置安装过程
[root@docker1 php]# vim Dockerfile 
FROM centos:7
MAINTAINER this is php <lnmp>
RUN rm -rf /etc/yum.repos.d/*
ADD  http://mirrors.aliyun.com/repo/Centos-7.repo /etc/yum.repos.d/Centos-7.repo
RUN yum -y install epel-release
RUN yum -y install gcc gcc-c++ make \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel \
oniguruma-devel \
sqlite-devel
ADD php-8.1.27.tar.gz /usr/local/src
WORKDIR /usr/local/src/php-8.1.27
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-pdo-mysql \
--with-openssl \
--with-sqlite-devel \
--with-oniguruma-devel \
--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/loacl/php/sbin:$PATH
COPY php.ini /usr/local/php/lib/
COPY php-fpm.conf /usr/local/php/etc/
COPY www.conf /usr/local/php/etc/php-fpm.d/
EXPOSE 9000
CMD ["/usr/local/php/sbin/php-fpm","-f"]
​
[root@docker1 php]# docker run -itd --name php --net mynetwork --ip 172.111.0.30 -p 9000:9000 --volumes-from nginx --volumes-from mysql php:lnmp
980cd0abc11a1b2da2137515eb55d204307403e3b62f0e497f45252633ba3e6b
[root@docker1 php]# docker exec -it php bash
[root@980cd0abc11a php-8.1.27]# cd /usr/local/
[root@980cd0abc11a local]# ls
bin  games    lib    libexec  nginx  sbin   src
etc  include  lib64  mysql    php    share
[root@980cd0abc11a local]# cd mysql/
[root@980cd0abc11a mysql]# ls
LICENSE  bin   docs     lib  mysql.sock       mysqld.pid  support-files
README   data  include  man  mysql.sock.lock  share
[root@980cd0abc11a mysql]# cd ..
[root@980cd0abc11a local]# cd nginx/
[root@980cd0abc11a nginx]# ls
html
[root@980cd0abc11a nginx]# cd html/
[root@980cd0abc11a html]# ls
50x.html  index.html  wordpress
#查看端口是否起
[root@980cd0abc11a html]# netstat -antp | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      1/php-fpm: master p 
​
#访问宿主机ip就会出现,

1


http://www.ppmy.cn/devtools/97362.html

相关文章

Python实现GAN(生成对抗网络)图像修复算法

目录 1. GAN简介与图像修复2. PyTorch和CUDA简介3. 数据加载与预处理3.1 安装依赖3.2 数据加载3.3 数据遮挡4. 构建GAN图像修复模型4.1 生成器4.2 判别器5. 训练GAN模型5.1 损失函数与优化器5.2 训练循环6. 测7. 实现GUI进行图像修复8. 总结与扩展扩展方向:1. GAN简介与图像修…

低代码开发平台:技术概览、效率与质量的权衡及挑战与机遇

&#x1f493; 博客主页&#xff1a;倔强的石头的CSDN主页 &#x1f4dd;Gitee主页&#xff1a;倔强的石头的gitee主页 ⏩ 文章专栏&#xff1a;《热点时事》 期待您的关注 目录 一、技术概览 基本概念 主要特点 市场现状 主流平台优缺点分析 二、效率与质量的权衡 提高…

SQL基础——MySQL的触发器、存储引擎、事务

简介&#xff1a;个人学习分享&#xff0c;如有错误&#xff0c;欢迎批评指正。 一、MySQL的触发器 1.概述 介绍 触发器&#xff0c;就是一种特殊的存储过程。触发器和存储过程一样是一个能够完成特定功能、存储在数据库服务器上的SQL片段&#xff0c;但是触发器无需调用&…

人类意识云端备份,未来或下载至机器人重生!

在数字化浪潮的推动下&#xff0c;人工智能&#xff08;AI&#xff09;正成为塑造未来的关键力量。硅纪元视角栏目紧跟AI科技的最新发展&#xff0c;捕捉行业动态&#xff1b;提供深入的新闻解读&#xff0c;助您洞悉技术背后的逻辑&#xff1b;汇聚行业专家的见解&#xff0c;…

面试题:Rabbitmq怎么保证消息的可靠性?

1.消费端消息可靠性保证&#xff1a; 消息确认&#xff08;Acknowledgements&#xff09;&#xff1a;(自动(默认),手动) 消费者在接收到消息后&#xff0c;默认情况下RabbitMQ会自动确认消息&#xff08;autoAcktrue&#xff09;。为保证消息可靠性&#xff0c;可以设置auto…

Java:枚举转换

在Java中&#xff0c;你可以使用Enum.valueOf()方法将字符串转换为枚举常量。但是&#xff0c;如果你想要将枚举转换为其他类型&#xff0c;你需要自定义转换方法。以下是一个简单的例子&#xff0c;演示如何将枚举转换为整数&#xff1a; public enum Color {RED(1), GREEN(2…

电竞蓝牙耳机申请Hi-Res认证指南

电竞蓝牙耳机是专为游戏玩家设计的蓝牙耳机产品&#xff0c;它们结合了出色的音质、低延迟和舒适性&#xff0c;为玩家提供沉浸式的游戏体验。以下是对电竞蓝牙耳机的详细介绍&#xff1a; 1. 音质表现 电竞蓝牙耳机通常具备优质的音质表现&#xff0c;通过多单元动圈设计或先…

超越 RAG 基础:AI 应用的高级策略

作者&#xff1a;来自 Elastic Platform Team 我们最近与 Cohere 举办的线上活动深入探讨了检索增强生成 (Retrieval Augmented Genereation - RAG) 的世界&#xff0c;重点讨论了在概念验证阶段之后构建 RAG 应用程序的关键注意事项。我们的演讲者是 Elastic 的首席解决方案架…