使用docker虚拟化技术,lamp架构,搭建wordpress博客服务

使用平台

Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-91-generic x86_64)

搭建思路步骤


需求:使用wprdpress搭建一个私人博客,并且将服务仍到docker容器中

1.构建wordpress的docker容器

2.在容器中搭建lamp架构

3.在lamp架构上,配置wordpress

4.测试运行

5.导出wordpress镜像

构建wordpress的docker容器

1.远程登陆阿里云服务

[root@localhost zip]# ssh root@118.24.176.175
root@118.24.176.175's password: 
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-91-generic x86_64)
​
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
​
Last login: Sun May 27 04:40:30 2018 from 113.133.193.164

2.在mnt目录下,已经准备好了wordpress安装包和一个ubuntu的docker镜像

root@VM-0-16-ubuntu:~# cd /mnt/
root@VM-0-16-ubuntu:/mnt# ls
ubuntu.tar  wordpress-4.9.4-zh_CN.zip

wordpress包可以在官网下载,ubuntu的docker镜像可以使用docker pull ubuntu获取

3.使用apt-get命令下载并安装docker的服务端和客户端,安装完成,启动docker守护进程

root@VM-0-16-ubuntu:/mnt# apt-get install docker*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
...下载docker过程
root@VM-0-16-ubuntu:/mnt# systemctl start docker

4.导入原始的ubuntu镜像

root@VM-0-16-ubuntu:/mnt# docker load --input ubuntu.tar 
454970bd163b: Loading layer [==================================================>] 196.8 MB/196.8 MB
38112156678d: Loading layer [==================================================>] 208.9 kB/208.9 kB
4e1f7c524148: Loading layer [==================================================>] 4.608 kB/4.608 kB
56063ad57855: Loading layer [==================================================>] 1.024 kB/1.024 kB

5.以ubuntu的镜像为基础镜像,构建名为wordpress的docker容器

root@VM-0-16-ubuntu:/mnt# docker run -it -p 80:80 --name wordpress ubuntu /bin/bash

这里将宿主机的80端口映射到容器的80端口
 

搭建lamp平台架构

搭建lamp平台架构思路:

  1. 下载安装apache

  2. 下载安装mysql服务器

  3. 下载安装php5

所有的步骤都是在容器内完成

1.进入wordpress容器

root@VM-0-16-ubuntu:/mnt#docker start -i wordpress
root@441efb1ccb8e:

2.安装apache服务

root@441efb1ccb8e:/# apt-get install apache2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
...下载apache过程

3.下载安装php5

root@441efb1ccb8e:/# apt-get install php5   
Reading package lists... Done
Building dependency tree       
Reading state information... Done
。。。安装过程

4.下载安装mysql服务端和客户端

安装过程中,会提示输入mysql密码

root@441efb1ccb8e:/# apt-get install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
​
root@441efb1ccb8e:/# apt-get install  mysql-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
。。。安装过程

5.安装php5-mysql

该组建连接php5和mysql

root@441efb1ccb8e:/# apt-get install php5-mysql
Reading package lists... Done
Building dependency tree       
Reading state information... Done

6.启动lamp架构

root@441efb1ccb8e:/# /etc/init.d/apache2 start
root@441efb1ccb8e:/# /etc/init.d/mysql start

这时可以进行测试apache服务和php是否安装成功:

在/var/www/html/目录下编辑一个名为index.php的文件
使用curl localhost/index.php访问,如果返回编辑内容,则证明成功

7.在mysql中,建立一个名为wordpress的库

root@441efb1ccb8e:/# mysql -uroot -p
键入密码
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

安装搭建wordpress

给wordpress安装lftp客户端,方便从宿主机上获取wordpress安装包

root@441efb1ccb8e:/mnt# apt-get install lftp
Reading package lists... Done
Building dependency tree       
Reading state information... Done
。。。下载过程

将宿主机的wordpress安装包放在vsftpd服务的发布目录

这里直接解压好,并且修改了其中一个配置文件

root@VM-0-16-ubuntu:/var/ftp/pub# ls
wordpress
root@VM-0-16-ubuntu:/var/ftp/pub# pwd
/var/ftp/pub

将wordpress目录中wp-config-sample.php重命名为wp-config.php

root@VM-0-16-ubuntu:/var/ftp/pub# cp wordpress/wp-config-sample.php wordpress/wp-config.php

修改wp-config.php文件,里面是连接mysql的相关信息,要更改为自己的mysql相关信息

该文件主要提供数据库的名字(如这里的wordpress),用户名(如root),密码(如安装mysql时键入的密码)

使用wordpress容器获取宿主机的wordpress目录

root@441efb1ccb8e:/var/www/html# lftp 172.17.0.1
lftp 172.17.0.1:~> ls
drwxr-xr-x    5 0        0            4096 May 28 11:44 wordpress
lftp 172.17.0.1:/> mirror wordpress/
Total: 143 directories, 1528 files, 0 symlinks                          
New: 1528 files, 0 symlinks
28179250 bytes transferred in 3 seconds (9.09M/s)
lftp 172.17.0.1:/> exit
root@441efb1ccb8e:/var/www/html# ls
index.html  wordpress

这里修给了index.html,方便使用浏览器访问宿主机IP跳转到wordpress

root@441efb1ccb8e:/var/www/html#echo "<a href="wordpress">my wordpress</a>" > index.html

到这里,一个新的wordpress已经搭建成功

导出镜像

构建好的wordpress容器,可以将其导出为镜像,在其他平台上直接使用

root@VM-0-16-ubuntu:~# docker commit -a 'qpy' -m 'wordpress' wordpress qpy/wordpress
sha256:62607c25506d873c3b07e0096b3bdcf16b8cb97895f366969158c0cc5c85aae4
root@VM-0-16-ubuntu:~# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
qpy/wordpress       latest              62607c25506d        6 seconds ago       379 MB
ubuntu              latest              07c86167cdc4        2 years ago         188 MB

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值