经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Docker » 查看文章
docker部署lnmp-wordpress的实现步骤
来源:jb51  时间:2021/9/6 13:21:14  对本文有异议

一、实验环境

系统:centos7 ip:192.168.238.133

  1. #关闭防火墙
  2. [root@localhost ~]# systemctl stop firewalld
  3. [root@localhost ~]# systemctl disable firewalld
  4. [root@localhost ~]# setenforce 0
  5. #添加dns
  6. [root@localhost ~]# cat /etc/resolv.conf
  7. nameserver 114.114.114.114
  8. #修改主机名
  9. [root@localhost ~]# hostnamectl set-hostname docker-lnmp
  10. [root@localhost ~]# su

二、安装docker源

  1. #安装依赖环境
  2. [root@docker-lnmp ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
  3. #安装阿里docker源
  4. [root@docker-lnmp ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

三、安装docker

  1. [root@docker-lnmp ~]# yum install -y docker-ce #安装社区版
  2. [root@docker-lnmp ~]# systemctl enable docker #设置开机自启
  3. Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
  4. [root@docker-lnmp ~]# systemctl start docke #开启服务
  5. #创建dockerfile目录
  6. [root@docker-lnmp ~]# mkdir docker && cd docker
  7. #创建MySQL和Nginx的dockerfile目录
  8. [root@docker-lnmp docker]# mkdir nginx mysql

在这里插入图片描述

四、部署Nginx和PHP

1、上传/解压软件包和配置文件

在这里插入图片描述

  1. #解压软件包
  2. [root@docker-lnmp nginx]# tar zxvf wordpress-4.9.4-zh_CN.tar.gz
  3. [root@docker-lnmp nginx]# tar zxvf nginx-1.12.2.tar.gz
  4. [root@docker-lnmp nginx]# tar zxvf libmcrypt-2.5.7.tar.gz
  5. [root@docker-lnmp nginx]# tar zxvf php-5.5.38.tar.gz

2、创建dockerfile文件

  1. [root@docker-lnmp nginx]# vim Dockerfile
  2. FROM docker.io/centos:7
  3. RUN yum -y update
  4. RUN yum -y install gcc gcc-c++ openssl-devel openssl autoconf cmake autoconf zlib zlib-devel libtool pcre pcre-devel wget net-tools make
  5. RUN groupadd -g 900 nginx && useradd nginx -g nginx -s /sbin/nologin
  6. FROM docker.io/centos:7
  7. RUN yum -y update
  8. RUN yum -y install gcc gcc-c++ openssl-devel openssl autoconf cmake autoconf zlib zlib-devel libtool pcre pcre-devel wget net-tools make
  9. RUN groupadd -g 900 nginx && useradd nginx -g nginx -s /sbin/nologin
  10. ADD nginx-1.12.2 nginx-1.12.2
  11. RUN cd /nginx-1.12.2/ && ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx
  12. RUN cd /nginx-1.12.2/ && make && make install
  13. RUN ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
  14. RUN sed -i '1afastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' /usr/local/nginx/conf/fastcgi_params
  15. ADD nginx.conf /usr/local/nginx/conf/
  16. ADD wordpress /usr/local/nginx/html/wordpress
  17. ADD wp-config.php /usr/local/nginx/html/wordpress
  18. RUN yum -y install gcc gcc-c++ libxml2-devel libcurl-devel openssl-devel bzip2-devel openssl automake make autoconf libtool zlib-devel make pcre-devel wget net-tools
  19. ADD libmcrypt-2.5.7 libmcrypt-2.5.7
  20. RUN cd libmcrypt-2.5.7/&& ./configure --prefix=/usr/local/libmcrypt && make && make install
  21. ADD php-5.5.38 php-5.5.38
  22. RUN cd php-5.5.38/ && ./configure --prefix=/usr/local/php5.5 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts && make && make install
  23. RUN cd php-5.5.38 && cp php.ini-production /etc/php.ini
  24. RUN cd /php-5.5.38 && cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  25. RUN chmod +x /etc/init.d/php-fpm && chkconfig --add php-fpm && chkconfig php-fpm on
  26. RUN cp /usr/local/php5.5/etc/php-fpm.conf.default /usr/local/php5.5/etc/php-fpm.conf
  27. RUN sed -i 's*;pid = run/php-fpm.pid*pid = run/php-fpm.pid*g' /usr/local/php5.5/etc/php-fpm.conf
  28. RUN sed -i 's/user = nobody/user = nginx/g' /usr/local/php5.5/etc/php-fpm.conf
  29. RUN sed -i 's/group = nobody/group = nginx/g' /usr/local/php5.5/etc/php-fpm.conf
  30. RUN sed -i 's/pm.max_children = 5/pm.max_children = 50/g' /usr/local/php5.5/etc/php-fpm.conf
  31. RUN sed -i 's/pm.start_servers = 2/pm.start_servers = 5/g' /usr/local/php5.5/etc/php-fpm.conf
  32. RUN sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 5/g' /usr/local/php5.5/etc/php-fpm.conf
  33. RUN sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 30/g' /usr/local/php5.5/etc/php-fpm.conf
  34. EXPOSE 9000
  35. EXPOSE 80

3、构建镜像

  1. [root@docker-lnmp nginx]# docker build -t "centos:nginx-php" .

查看镜像列表

在这里插入图片描述

4、创建容器并运行

  1. [root@docker-lnmp nginx]# docker run -dit -p 80:80 -m 500m --memory-swap 1G 3efb4e2c79b5 /bin/bash
  2. 49c5b69ce7012579f4b024ef6be88ff5de8057ccc7f81583fcf04f1c3ec6a79c

查看容器列表

在这里插入图片描述

5、开启服务

  1. [root@docker-lnmp nginx]# docker exec -it 49c5b69ce701 /bin/bash
  2. [root@49c5b69ce701 /]# /etc/init.d/php-fpm start && nginx
  3. [root@49c5b69ce701 /]# netstat -antp | grep php
  4. tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 32/php-fpm: master
  5. [root@49c5b69ce701 /]# netstat -antp | grep nginx
  6. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 39/nginx: master pr

验证一下:

在这里插入图片描述

五、部署MySQL

1、创建MySQL的dockerfile文件

  1. [root@docker-lnmp mysql]# vim Dockerfile
  2. FROM docker.io/centos:7
  3. RUN yum -y install gcc gcc-c++ make autoconf make cmake wget
  4. RUN groupadd mysql; useradd -r -M -u 3306 -s /sbin/nologin -g mysql mysql
  5. RUN mkdir /usr/local/mysql; mkdir /data/mysql -pv
  6. RUN yum install gcc gcc-c++ ncurses-devel bison bison-devel -y
  7. RUN wget -c http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.29.tar.gz
  8. RUN tar xf mysql-5.6.29.tar.gz -C /usr/local/src/
  9. WORKDIR /usr/local/src/mysql-5.6.29
  10. RUN cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DEXTRA_CHARSETS=all -DDEFAULT_COLLATION=utf8_general_ci -DWITH-MYSQLD-LDFLAGS=-all-static -DWITH-CLIENT-LD-FLAGS=-all-static -DWITH_DEBUG=0 && gmake && gmake install
  11. RUN chown -R root:mysql /usr/local/mysql/ && chown -R mysql:mysql /data/mysql
  12. RUN chmod 755 /usr/local/src/mysql-5.6.29/scripts/mysql_install_db.sh
  13. RUN /usr/local/src/mysql-5.6.29/scripts/mysql_install_db.sh --basedir=/usr/local/mysql --datadir=/data/mysql --no-defaults --user=mysql
  14. RUN cp /usr/local/src/mysql-5.6.29/support-files/my-default.cnf /etc/my.cnf
  15. RUN cp /usr/local/src/mysql-5.6.29/support-files/mysql.server /etc/init.d/mysqld
  16. RUN chmod 775 /etc/init.d/mysqld && /etc/init.d/mysqld start
  17. RUN echo -e '#!/bin/bash\nexport PATH=$PATH:/usr/local/mysql/bin' >/etc/profile.d/mysql.sh
  18. RUN source /etc/profile
  19. EXPOSE 3306

2、构建镜像

  1. [root@docker-lnmp mysql]# docker build -t "centos:mysql-5.6" .

查看镜像列表

在这里插入图片描述

3、创建容器并运行

  1. [root@docker-lnmp mysql]# docker run -dit -p 3306:3306 --device-write-bps /dev/sda:10M 704e5b978518 /bin/bash
  2. 960645a296e3e8795c344a8037b0641f8b5baf8e2214453214359071480c379d

查看容器列表

在这里插入图片描述

4、启动服务

  1. [root@docker-lnmp mysql]# docker exec -it 960645a296e3 /bin/bash
  2. [root@960645a296e3 mysql-5.6.29]# /etc/init.d/mysqld start
  3. Starting MySQL............ SUCCESS!

5、数据库授权

  1. #修改密码
  2. [root@960645a296e3 mysql-5.6.29]# mysql -uroot -p123456
  3. Warning: Using a password on the command line interface can be insecure.
  4. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  5. [root@960645a296e3 mysql-5.6.29]# mysqladmin -u root -p password
  6. Enter password:
  7. New password:
  8. Confirm new password:
  9. #授权
  10. [root@960645a296e3 mysql-5.6.29]# mysql -uroot -p123456
  11. mysql> create database wordpress default charset utf8 COLLATE utf8_general_ci; #创建wordpress表
  12. Query OK, 1 row affected (0.00 sec)
  13.  
  14. mysql> grant all privileges on wordpress.* to 'wordpress'@'%' identified by '123456' with grant option; #授权
  15. Query OK, 0 rows affected (0.00 sec)
  16.  
  17. mysql> flush privileges; #刷新权限
  18. Query OK, 0 rows affected (0.01 sec)

访问:http://192.168.238.133/wordpress/index.php

在这里插入图片描述

到此这篇关于docker部署lnmp-wordpress的实现步骤的文章就介绍到这了,更多相关docker部署lnmp-wordpress内容请搜索w3xue以前的文章或继续浏览下面的相关文章希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号