docker部署lnmp-wordpress的实现步骤

目录
  • 一、实验环境
  • 二、安装docker源
  • 三、安装docker
  • 四、部署nginx和php
    • 1、上传/解压软件包和配置文件
    • 2、创建dockerfile文件
    • 3、构建镜像
    • 4、创建容器并运行
    • 5、开启服务
  • 五、部署mysql
    • 1、创建mysql的dockerfile文件
    • 2、构建镜像
    • 3、创建容器并运行
    • 4、启动服务
    • 5、数据库授权

一、实验环境

系统:centos7 ip:192.168.238.133

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

二、安装docker源

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

三、安装docker

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

四、部署nginx和php

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

#解压软件包[root@docker-lnmp nginx]# tar zxvf wordpress-4.9.4-zh_cn.tar.gz[root@docker-lnmp nginx]# tar zxvf nginx-1.12.2.tar.gz[root@docker-lnmp nginx]# tar zxvf libmcrypt-2.5.7.tar.gz[root@docker-lnmp nginx]# tar zxvf php-5.5.38.tar.gz

2、创建dockerfile文件

[root@docker-lnmp nginx]# vim dockerfile
from docker.io/centos:7
run yum -y update
run yum -y install gcc gcc-c++ openssl-devel openssl autoconf cmake autoconf zlib zlib-devel libtool pcre pcre-devel wget net-tools make
run groupadd  -g 900 nginx && useradd nginx -g nginx -s /sbin/nologin
from docker.io/centos:7
run yum -y update
run yum -y install gcc gcc-c++ openssl-devel openssl autoconf cmake autoconf zlib zlib-devel libtool pcre pcre-devel wget net-tools make
run groupadd  -g 900 nginx && useradd nginx -g nginx -s /sbin/nologin
add nginx-1.12.2 nginx-1.12.2
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
run cd /nginx-1.12.2/ && make && make install
run ln -s /usr/local/nginx/sbin/nginx  /usr/local/sbin/
run sed -i '1afastcgi_param  script_filename    $document_root$fastcgi_script_name;' /usr/local/nginx/conf/fastcgi_params
add nginx.conf /usr/local/nginx/conf/
add wordpress /usr/local/nginx/html/wordpress
add wp-config.php /usr/local/nginx/html/wordpress
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
add libmcrypt-2.5.7 libmcrypt-2.5.7
run cd libmcrypt-2.5.7/&& ./configure --prefix=/usr/local/libmcrypt && make && make install
add php-5.5.38 php-5.5.38
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
run cd php-5.5.38 && cp php.ini-production /etc/php.ini
run cd /php-5.5.38 && cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
run chmod +x /etc/init.d/php-fpm && chkconfig --add php-fpm && chkconfig php-fpm on
run cp /usr/local/php5.5/etc/php-fpm.conf.default  /usr/local/php5.5/etc/php-fpm.conf
run sed -i 's*;pid = run/php-fpm.pid*pid = run/php-fpm.pid*g' /usr/local/php5.5/etc/php-fpm.conf
run sed -i 's/user = nobody/user = nginx/g' /usr/local/php5.5/etc/php-fpm.conf
run sed -i 's/group = nobody/group = nginx/g' /usr/local/php5.5/etc/php-fpm.conf
run sed -i 's/pm.max_children = 5/pm.max_children = 50/g' /usr/local/php5.5/etc/php-fpm.conf
run sed -i 's/pm.start_servers = 2/pm.start_servers = 5/g' /usr/local/php5.5/etc/php-fpm.conf
run sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 5/g' /usr/local/php5.5/etc/php-fpm.conf
run sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 30/g' /usr/local/php5.5/etc/php-fpm.conf
expose 9000
expose 80

3、构建镜像

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

查看镜像列表

4、创建容器并运行

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

查看容器列表

5、开启服务

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

验证一下:

五、部署mysql

1、创建mysql的dockerfile文件

[root@docker-lnmp mysql]# vim dockerfile
from docker.io/centos:7
run yum -y install gcc gcc-c++ make autoconf make cmake wget
run groupadd mysql; useradd -r -m -u 3306 -s /sbin/nologin -g mysql mysql
run mkdir /usr/local/mysql; mkdir /data/mysql -pv
run yum install gcc gcc-c++ ncurses-devel bison bison-devel -y
run wget -c http://dev.mysql.com/get/downloads/mysql-5.6/mysql-5.6.29.tar.gz
run tar xf mysql-5.6.29.tar.gz -c /usr/local/src/
workdir /usr/local/src/mysql-5.6.29
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
run chown -r root:mysql /usr/local/mysql/ && chown -r mysql:mysql /data/mysql
run chmod 755 /usr/local/src/mysql-5.6.29/scripts/mysql_install_db.sh
run /usr/local/src/mysql-5.6.29/scripts/mysql_install_db.sh --basedir=/usr/local/mysql --datadir=/data/mysql --no-defaults --user=mysql
run cp /usr/local/src/mysql-5.6.29/support-files/my-default.cnf  /etc/my.cnf
run cp /usr/local/src/mysql-5.6.29/support-files/mysql.server  /etc/init.d/mysqld
run chmod 775 /etc/init.d/mysqld && /etc/init.d/mysqld start
run echo -e '#!/bin/bash\nexport path=$path:/usr/local/mysql/bin' >/etc/profile.d/mysql.sh
run source /etc/profile
expose 3306

2、构建镜像

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

查看镜像列表

3、创建容器并运行

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

查看容器列表

4、启动服务

[root@docker-lnmp mysql]# docker exec -it 960645a296e3 /bin/bash
[root@960645a296e3 mysql-5.6.29]# /etc/init.d/mysqld start
starting mysql............ success!

5、数据库授权

#修改密码
[root@960645a296e3 mysql-5.6.29]# mysql -uroot -p123456
warning: using a password on the command line interface can be insecure.
error 1045 (28000): access denied for user 'root'@'localhost' (using password: yes)
[root@960645a296e3 mysql-5.6.29]# mysqladmin -u root -p password
enter password: 
new password: 
confirm new password: 
#授权
[root@960645a296e3 mysql-5.6.29]# mysql -uroot -p123456
mysql> create database wordpress default charset utf8 collate utf8_general_ci; #创建wordpress表
query ok, 1 row affected (0.00 sec)

mysql> grant all privileges on wordpress.*  to 'wordpress'@'%' identified by '123456' with grant option; #授权
query ok, 0 rows affected (0.00 sec)

mysql> flush privileges; #刷新权限
query ok, 0 rows affected (0.01 sec)

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

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

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐