• docker中基于centos镜像部署lnmp环境 php7.3 mysql8.0 最新版


    Docker是一个开源的应用容器引擎,基于Go语言并遵从Apache2.0协议开源。

    Docker可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似iPhone的app),更重要的是容器性能开销极低。

    文章就不介绍如何去安装和使用docker了。不会的请大家自行谷歌/百度去学习下~

    最新版的镜像地址,在我的阿里云仓库里面,文章末尾,可以直接使用命令docker pull获取。

    先说下本人docker中部署lnmp环境使用的几个方法:

    方法一:通过百度等方法,分别从一些镜像仓库拉取nginx、mysql、php镜像,然后挂在数据卷并映射端口。

    附参考飞机票:https://learnku.com/articles/9200/centos-7-uses-docker-to-build-a-basic-lnmp-environment

    但由于我想要一个统一的lnmp环境,所以放弃了这个方法。

    方法二:通过Dockerfile,写一些命令,逐步安装各个app及扩展。但由于中途有一些报错,排查了很久,安装过程有些绕,最终放弃。贴出dockerfile代码,大家可以试用一下,如果有能力排除问题,也可以使用。

    # base image
    # 基础镜像
    FROM centos:latest
     
    # MAINTAINER编写者
    LABEL MAINTAINER mengyilingjian@outlook.com
     
    # put nginx-1.16.1.tar.gz into /usr/local and unpack nginx 来吧nginx 和PHP提前都放进基础镜像的/usr/local/src目录下,方便编译安装
    ADD nginx-1.16.1.tar.gz /usr/local
    ADD php-7.3.8.tar.gz /usr/local
     
    # running required command 安装Nginx的一系列乱七八糟的依赖包
    RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel bison libcurl-devel
    RUN yum install -y libxslt-devel -y gd gd-devel GeoIP GeoIP-devel pcre pcre-devel
    RUN useradd -M -s /sbin/nologin nginx
     
    # change dir to /usr/local/nginx-1.16.1
    WORKDIR /usr/local/nginx-1.16.1
    # execute command to compile nginx
    RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
    EXPOSE 80 443
    
    #先装个本地Mysql
    RUN yum install -y wget
    RUN wget http://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
    RUN rpm -ivh mysql80-community-release-el7-3.noarch.rpm --force --nodeps
    RUN yum install -y mysql-server
     
     
    #截止此,开始安装php,宇宙惯例,开始安装一些编译的依赖包
    RUN yum -y install epel-release
    RUN yum -y install libmcrypt-devel
    RUN yum -y install libxml2 libxml2-devel openssl curl-devel libjpeg-devel libpng-devel freetype-devel
    WORKDIR /usr/local/php-7.3.8
    #编译 安装
    RUN ./configure --prefix=/usr/local/php7.3.8 --with-config-file-path=/usr/local/php7.3.8/etc --with-config-file-scan-dir=/usr/local/php7.3.8/etc/php.d --with-mcrypt=/usr/include --enable-mysqlnd --with-mysqli --with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-gd --with-iconv --with-zlib --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache && make && make install 
    && cp /usr/local/php7.3.8/etc/php-fpm.conf.default /usr/local/php7.3.8/etc/php-fpm.conf 
        && cp /usr/local/php7.3.8/etc/php-fpm.d/www.conf.default /usr/local/php7.3.8/etc/php-fpm.d/www.conf 
        && sed -i '/;daemonize/adaemonize = no' /usr/local/php7.3.8/etc/php-fpm.conf 
        && sed -i 's/127.3.8.1/0.0.0.0/g' /usr/local/php7.3.8/etc/php-fpm.d/www.conf 
        && echo "${TIME_ZOME}" > /etc/timezone 
        && ln -sf /usr/share/zoneinfo/${TIME_ZOME} /etc/localtime 
        && yum clean all 
        && yum -y remove gcc gcc-c++ make
    EXPOSE 9000
    CMD ["sbin/php-fpm","-c","etc/php-fpm.conf"]
    
    RUN cp php.ini-production /usr/local/php7.3.8/etc/php.ini
    
    

    方法三:在centos中,通过lnmp一键安装包,进行安装。这个方法貌似可以成功,但是耗费时间会根据网络和服务器配置的高低,变得漫长而痛苦。由于本人服务器自己用,所以配置不高,耗费了接近十多个小时,中途没有报错。所以有点哭笑不得。最后还是放弃。

    1.文章教程使用配置环境:

    [root@izwz91quxhnlk8xexo852xz ~]# docker --version
    Docker version 19.03.1, build 74b1e89
    
    [root@izwz91quxhnlk8xexo852xz ~]# df -hl
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/vda1        40G   19G   19G  51% /
    devtmpfs        909M     0  909M   0% /dev
    tmpfs           920M     0  920M   0% /dev/shm
    tmpfs           920M  556K  919M   1% /run
    tmpfs           920M     0  920M   0% /sys/fs/cgroup
    tmpfs           184M     0  184M   0% /run/user/0
    overlay          40G   19G   19G  51% /var/lib/docker/overlay2/22a5b83dd224ee73588dcbc58c5d618e9d91398f57389ba3a3632aed7e853365/merged
    
    [root@izwz91quxhnlk8xexo852xz ~]# nginx -V
    nginx version: nginx/1.16.0
    built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
    built with OpenSSL 1.1.1b  26 Feb 2019
    

    2.lnmp环境搭建成功的详细信息:

    php7:

    [root@9c73e764fc4b bin]# ./php --version
    PHP 7.3.8 (cli) (built: Aug 22 2019 09:34:04) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies
        with the ionCube PHP Loader + ionCube24 v10.3.7, Copyright (c) 2002-2019, by ionCube Ltd.
        with Zend OPcache v7.3.8, Copyright (c) 1999-2018, by Zend Technologies
        with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans
    Segmentation fault (core dumped)
    
    [root@9c73e764fc4b bin]# ./php -m
    [PHP Modules]
    bcmath
    Core
    ctype
    curl
    date
    dom
    exif
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    intl
    ionCube Loader
    json
    libxml
    mbstring
    memcache
    memcached
    mongodb
    mysqli
    mysqlnd
    openssl
    pcntl
    pcre
    PDO
    pdo_mysql
    pdo_sqlite
    phalcon
    Phar
    posix
    redis
    Reflection
    session
    shmop
    SimpleXML
    soap
    sockets
    sodium
    SPL
    sqlite3
    standard
    swoole
    sysvsem
    tokenizer
    xdebug
    xml
    xmlreader
    xmlrpc
    xmlwriter
    xsl
    yaf
    Zend OPcache
    zip
    zlib
    

    php5.6:

    [root@9c73e764fc4b bin]# ./php --version
    PHP 5.6.40 (cli) (built: Aug 22 2019 10:06:15) 
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
        with the ionCube PHP Loader + ionCube24 v10.3.7, Copyright (c) 2002-2019, by ionCube Ltd.
        with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
        with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
        with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
    [root@9c73e764fc4b bin]# ./php -m
    [PHP Modules]
    bcmath
    Core
    ctype
    curl
    date
    dom
    ereg
    exif
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    intl
    ionCube Loader
    json
    libxml
    mbstring
    mcrypt
    memcache
    memcached
    mhash
    mongodb
    mysql
    mysqli
    mysqlnd
    openssl
    pcntl
    pcre
    PDO
    pdo_mysql
    pdo_sqlite
    phalcon
    Phar
    posix
    redis
    Reflection
    session
    shmop
    SimpleXML
    soap
    sockets
    SPL
    sqlite3
    standard
    swoole
    sysvsem
    tokenizer
    xdebug
    xml
    xmlreader
    xmlrpc
    xmlwriter
    xsl
    Zend Guard Loader
    Zend OPcache
    zip
    zlib
    

    mysql8.0:

    [root@9c73e764fc4b bin]# ./mysql --version
    ./mysql  Ver 8.0.17 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)
    

    nginx:

    [root@9c73e764fc4b sbin]# ./nginx -V
    nginx version: nginx/1.16.0
    built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

    3.宿主机中通过以下命令可拉取我的阿里云仓库里最新的的centos-lnmp镜像,欢迎大家下载使用。有问题可以加微信与我沟通:

    registry.cn-shenzhen.aliyuncs.com/eric_zhou/public:lnmp-v2.0

    [root@izwz91quxhnlk8xexo852xz ~]# docker pull registry.cn-shenzhen.aliyuncs.com/eric_zhou/public:lnmp-v2.0
    [root@izwz91quxhnlk8xexo852xz ~]# docker exec -it [imageID] /bin/bash
    -----------------------------------------------------------------------------------------
    php mysql nginx 已经加入全局变量,需要执行以下命令方可生效:
    source /etc/profile

     不懂地方可留言,或者进微信群内交流。

    群二维码:

       

    群二维码如果过期,请加我个人微信:mengyilingjian.

        

  • 相关阅读:
    【学习】jquery.placeholder.js让IE浏览器支持html5的placeholder
    【特效】体验很好的导航hover效果移出恢复当前位置
    【学习】滚动延迟加载插件scrollLoading用法
    【转载】jQuery全屏滚动插件fullPage.js
    【原创】自用css reset
    【转载】jQuery手机移动端触屏日历日期选择
    【学习】条码扫描器:QuaggaJS
    【学习】苹果iPhone safari浏览器样式重置修复按钮圆角bug
    将SeqReader打包成可执行的jar包
    Java向上转型和向下转型
  • 原文地址:https://www.cnblogs.com/mengyilingjian/p/11699834.html
Copyright © 2020-2023  润新知