Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker separation environment sets up LNMP and deploys Discuz

2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

First, install Docker environment

1. Configure the YUM source

Vi / etc/yum.repos.d/CentOS-Base.repo

Last line add

[docker-repo]

Name=Docker Repository

Baseurl= https://yum.dockerproject.org/repo/main/centos/7/

Enabled=1

Gpgcheck=1

Gpgkey= https://yum.dockerproject.org/gpg

2. Install the docker engine

Yum install-y docker-enginemkdir / etc/docker/

Vi / etc/docker/daemon.json / / configure Ali Mirror Accelerator

{

"registry-mirrors": ["https://qtid6917.mirror.aliyuncs.com"]"

}

Systemctl daemon-reload / / reload configuration systemctl enable docker / / Boot self-starting systemctl start docker / / Startup Services II. Docker deployment LNMP-nginx

1. Create a new working directory for nginx

Mkdir nginxcd nginx

Upload the nginx source package to the working directory

2. Edit the dockerfile file

Vi dockerfile / / Edit dockerfile

# basic image

FROM centos

MAINTAINER this is nginx

# prepare the running environment

RUN yum-y install\

Gcc\

Make\

Pcre-devel\

Zlib-devel\

Openssl-devel

# create a new account

RUN useradd-M-s / sbin/nologin nginx

# add Source package

ADD nginx-1.13.9 / nginx-1.13.9

# compile and install

RUN cd / nginx-1.13.9 & &. / configure\

-- prefix=/usr/local/nginx\

-- user=nginx\

-- group=nginx\

-with-http_stub_status_module & & make & & make install

# re-add the locally modified configuration file

ADD nginx.conf / usr/local/nginx/conf/nginx.conf

# specify work port

EXPOSE 80

# close the daemon

RUN echo "daemon off;" > > / usr/local/nginx/conf/nginx.conf

# enable the service

CMD ["/ usr/local/nginx/sbin/nginx"]

3. Modify the nginx configuration file locally

Cp nginx-1.13.9/conf/nginx.conf / root/nginx/ add the configuration file in the source code package to vi nginx.conf / / edit the nginx configuration file under the ngingx directory

. Default configuration.

.

Server {

Listen 80

Server_name localhost

# charset koi8-r

# access_log logs/host.access.log main

Location / {

Root / web; # specifies the working directory of the website

Index index.php index.html index.htm; # add index.php format

}

Error_page 500 502 503 504 / 50x.html

Location = / 50x.html {

Root / web

}

Location ~ .php ${

Root / web; # modified as above

Fastcgi_pass php:9000; # where php functions to interconnect with containers corresponding to the container name php

Fastcgi_index index.php

Fastcgi_param SCRIPT_FILENAME / web$fastcgi_script_name; # correspondingly changed to working directory

Include fastcgi_params

}

4. Finally check the files created by the image.

Ls nginx / / check the nginx working directory file

-nginx-1.13.9

-nginx.conf

-dockerfile

5. Make nginx image file

Docker build-t lnmp/nginx. Generate nginx image

III. Docker deployment of LNMP-mysql

1. Create a new mysql working directory

Mkdir mysqlcd mysql

2. Edit the dockerfile file

Vi dockerfile

# basic image

FROM guyton/centos6

MAINTAINER this is msyql images

# install mysql

RUN yum-y install mysql mysql-server

# enable mysql and authorize

RUN / etc/init.d/mysqld start & &\

Mysql-e "create database bbs;" & &\

Mysql-e "grant all privileges on. To 'root'@'%' identified by' abc123';" & &\

Mysql-e "grant all privileges on. To 'root'@'localhost' identified by' abc123';"

# specify the working port in the container

EXPOSE 3306

# enable multithreading service

CMD ["mysqld_safe"]

3. Make mysql image file

Docker build-t lnmp/mysql. Generate mysql image

IV. Docker deployment of LNMP-php

1. Create a new php working directory

Mkdir phpcd php

Upload the php-7.1.10 source package to the working directory

2. Edit php.ini

Cp php-7.1.10/php.ini-production / root/nginx/php.inivi php.ini

Add the specified database interface file under [PHP]

Mysqli.default_socket = / var/lib/mysql/mysql.sock

Date.timezone = Asia/Shanghai

3. Edit the dockerfile file

Vi dockerfile

# basic image

FROM centos

MAINTAINER this is php

# install the running environment

RUN yum-y install\

Gcc make\

Libjpeg\

Libjpeg-devel\

Libpng libpng-devel\

Freetype freetype-devel\

Libxml2\

Libxml2-devel\

Zlib zlib-devel\

Curl curl-devel\

Openssl openssl-devel

# add Source package

ADD php-7.1.10 / php-7.1.10

# compile and install

RUN cd php-7.1.10 & &. / configure\

-- prefix=/usr/local/php\

-- with-mysql-sock=/var/lib/mysql/mysql.sock\

-- with-mysqli\

-- with-zlib\

-- with-curl\

-- with-gd\

-- with-jpeg-dir\

-- with-png-dir\

-- with-freetype-dir\

-- with-openssl\

-- enable-mbstring\

-- enable-xml\

-- enable-session\

-- enable-ftp\

-- enable-pdo\

-- enable-tokenizer\

-- enable-zip\

-enable-fpm & & make & & make install

# add profile

ADD php.ini / usr/local/php/lib/php.ini

# modify the configuration file corresponding to fpm

RUN cp / usr/local/php/etc/php-fpm.conf.default / usr/local/php/etc/php-fpm.conf & &\

Sed-I's\; pid = run/php-fpm.pid\ pid = run/php-fpm.pid\ g'/ usr/local/php/etc/php-fpm.conf & &\

Sed-I's\; daemonize = yes\ daemonize = no\ g'/ usr/local/php/etc/php-fpm.conf

# modify the listening port, otherwise nginx will not be able to parse the .php file even if the container is interconnected

RUN cp / usr/local/php/etc/php-fpm.d/www.conf.default / usr/local/php/etc/php-fpm.d/www.conf & &\

Sed-I's\ 127.0.0.1\ 0.0.0.0\ g'/ usr/local/php/etc/php-fpm.d/www.conf

# New user

RUN useradd-M-s / sbin/nologin php

# designated port

EXPOSE 9000

Start the service

CMD ["/ usr/local/php/sbin/php-fpm"]

4. Finally check the files created by the image.

Ls php / / View the directory

-php-7.1.10

-php.ini

-dockerfile

5. Make php image file

Docker build-t lnmp/php. Generate php image

5. Start the corresponding images sequentially

Docker images / / View the created image

Docker run-d-- name mysql-v / var/lib/mysql-p 3306 lnmp/mysql / / start mysqldocker run-- name php-- volumes-from mysql-v / web:/web lnmp/php / / start phpdocker run-d-name nginx-- link php:php-p 80:80 / web/:/web lnmp/nginx / / start nginxdocker ps / / check if the container starts

Note: the above data volumes and containers are interconnected, so be sure to start in order, otherwise an error will be reported.

Upload DISCUZ project to / web directory cp-r dir_SC_UTF8/upload/ / web/bbs / / copy the corresponding project to / web cd / web/bbs / / enter the project directory to change permissions chmod-R 777. / config/chmod-R 777. / data/chmod-R 777. / uc_client/chmod-R 777. / uc_server/

Web browser accesses 192.168.80.100/bbs

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 209

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report