IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> LNMP+Wordpress架构部署! -> 正文阅读

[系统运维]LNMP+Wordpress架构部署!

LNMP+Wordpress

环境部署

设备:CentOS7,192.168.118.33(博主这里在一台设备上部署)

  • 关闭防火墙,核心防护
[root@localhost ~]# hostnamectl set-hostname docker_lnmp
[root@localhost ~]# su
[root@docker_lnmp ~]# systemctl stop firewalld
[root@docker_lnmp ~]# systemctl disable firewalld
[root@docker_lnmp ~]# setenforce 0
  • 安装docker源,安装docker
[root@docker_lnmp ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@docker_lnmp ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@docker_lnmp ~]# yum install -y docker-ce
[root@docker_lnmp ~]# systemctl start docker
[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.
  • 创建dockerfile目录
[root@docker_lnmp ~]# mkdir docker && cd docker
[root@docker_lnmp docker]# yum install -y tree

部署LNMP

  • 在docker目录创建nginx和mysql目录,上传nginx-1.12.2.tar.gz、wordpress-4.9.4-zh_CN.tar、libmcrypt-2.5.7.tar.gz、nginx.conf、wp-config.php等包到两个目录下
[root@docker_lnmp docker]# mkdir nginx mysql
[root@docker_lnmp docker]# cd nginx/
[root@docker_lnmp nginx]# touch Dokcerfile
##分别解压,结果如下
[root@docker_lnmp docker]# tree -L 2
.
├── mysql
│   ├── Dockerfile
│   ├── mysql-5.7.20
│   └── mysql-boost-5.7.20.tar.gz
└── nginx
    ├── Dockerfile
    ├── libmcrypt-2.5.7
    ├── libmcrypt-2.5.7.tar.gz
    ├── nginx-1.12.2
    ├── nginx-1.12.2.tar.gz
    ├── nginx.conf
    ├── php-5.5.38
    ├── php-5.5.38.tar.gz
    ├── wordpress
    ├── wordpress-4.9.4-zh_CN.tar.gz
    └── wp-config.php

7 directories, 9 files
  • 执行以下命令
[root@docker_lnmp docker]# cd nginx/
[root@docker_lnmp nginx]# cat >>Dockerfile <<EOF
FROM docker.io/centos:7
#部署nginx
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
#部署php
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
EOF
  • docker部署nginx-php
[root@docker_lnmp docker]# docker build -t "centos:nginx-php" .
[root@docker-lnmp nginx]# docker images
REPOSITORY   TAG         IMAGE ID       CREATED          SIZE
centos       nginx-php   aae821494984   20 seconds ago   1.5GB
centos       7           8652b9f0cb4c   9 months ago     204MB
[root@docker-lnmp nginx]# docker run -dit -p 80:80 -m 500m --memory-swap 1G aae821494984 /bin/bash
c44f152f883d1fb723c5e4f5cd242f2dbe94921a918f57b6f54c20b2aff56cb7
[root@docker-lnmp nginx]# docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS          PORTS                                         NAMES
c44f152f883d   aae821494984   "/bin/bash"   25 seconds ago   Up 24 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp, 9000/tcp   loving_hugle
[root@docker_lnmp docker]#  docker exec -it c44f152f883d /bin/bash
[root@c44f152f883d ~]# /etc/init.d/php-fpm start
[root@c44f152f883d ~]# nginx
[root@c44f152f883d ~]# netstat -antp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      85/nginx: master pr 
[root@c44f152f883d ~]# netstat -antp | grep php  
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      31/php-fpm: master 
[root@c44f152f883d ~]# exit
exit
  • 部署MySQL
[root@docker-lnmp ~]# cd /root/docker/mysql/
####执行以下命令
cat >>Dockerfile<<EOF
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
EOF

##把MySQL安装进容器
[root@docker-lnmp mysql]# docker build -t "centos:mysql-5.6" .
[root@docker-lnmp mysql]# docker images
REPOSITORY   TAG         IMAGE ID       CREATED          SIZE
centos       mysql-5.6   5fa429158de6   22 minutes ago   5.23GB
centos       nginx-php   aae821494984   19 hours ago     1.5GB
centos       7           8652b9f0cb4c   9 months ago     204MB
[root@docker-lnmp mysql]# docker run -dit -p 3306:3306 --device-write-bps /dev/sda:10M 5fa429158de6 /bin/bash
21bbe49c32fa10b1ce799247f928609312c81ac6a718a4d790f09525b9e2c662
[root@docker-lnmp mysql]# docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS          PORTS                                         NAMES
21bbe49c32fa   5fa429158de6   "/bin/bash"   31 seconds ago   Up 29 seconds   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp     magical_agnesi
c44f152f883d   aae821494984   "/bin/bash"   19 hours ago     Up 19 hours     0.0.0.0:80->80/tcp, :::80->80/tcp, 9000/tcp   loving_hugle
[root@docker-lnmp mysql]# docker exec -it 21bbe49c32fa /bin/bash
[root@21bbe49c32fa mysql-5.6.29]# /etc/init.d/mysqld start
Starting MySQL............ SUCCESS! 
  • 设置数据库密码,进入数据库,授权
[root@21bbe49c32fa mysql-5.6.29]# mysqladmin -uroot -p password
Enter password: 
New password: 
Confirm new password: 

##创建wordpress表
mysql> create database wordpress default charset utf8 COLLATE utf8_general_ci;
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.00 sec)

mysql> exit
Bye

[root@21bbe49c32fa mysql-5.6.29]# exit
exit
[root@docker-lnmp mysql]# docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED        STATUS        PORTS                                         NAMES
21bbe49c32fa   5fa429158de6   "/bin/bash"   5 hours ago    Up 5 hours    0.0.0.0:3306->3306/tcp, :::3306->3306/tcp     magical_agnesi
c44f152f883d   aae821494984   "/bin/bash"   23 hours ago   Up 23 hours   0.0.0.0:80->80/tcp, :::80->80/tcp, 9000/tcp   loving_hugle
[root@docker-lnmp mysql]# docker inspect --format='{{.NetworkSettings.IPAddress}}' 21bbe49c32fa
172.17.0.3
###可查看容器内应用的ip,如果出现数据库连接错误,记得修改/usr/local/nginx/html/wordpress/wp-config.php中的IP地址

在这里插入图片描述

  • 访问浏览器

在这里插入图片描述

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-08-30 12:34:54  更:2021-08-30 12:34:58 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 11:45:35-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码