容器部署lnmp

本文详细介绍了如何使用Docker容器在CentOS操作系统上分别部署Nginx、MySQL和PHP镜像,构建完整的LNMP(Linux、Nginx、MySQL、PHP)服务环境。
摘要由CSDN通过智能技术生成
部署nginx镜像
#拉取镜像
[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    5d0da3dc9764   2 months ago   231MB

创建容器后设置端口映射进入容器,再编译安装nginx
[root@localhost ~]# docker run --name  mysql -it  centos:8
Unable to find image 'centos:8' locally
8: Pulling from library/centos
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:8
[root@ff7ee0da84bc /]# useradd -r -M -s /sbin/nologin nginx
[root@ff7ee0da84bc /]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@ff7ee0da84bc /]# mkdir -p /var/log/nginx
[root@ff7ee0da84bc /]# chown -R nginx.nginx /var/log/nginx

将安装包传到contos里面去
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  nginx-1.20.1.tar.gz
[root@localhost src]# docker cp /usr/src/nginx-1.20.1.tar.gz  centos1:/usr/src

进去继续编译nginx
[root@ff7ee0da84bc /]# cd /usr/src/
[root@ff7ee0da84bc src]# ls
debug  kernels  nginx-1.20.1.tar.gz
[root@ff7ee0da84bc src]# tar xf nginx-1.20.1.tar.gz 
[root@ff7ee0da84bc src]# cd nginx-1.20.1
[root@ff7ee0da84bc nginx-1.20.1]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@ff7ee0da84bc nginx-1.20.1]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log

[root@ff7ee0da84bc nginx-1.20.1]# yum -y install make
[root@ff7ee0da84bc nginx-1.20.1]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

#配置环境变量
[root@ff7ee0da84bc nginx-1.20.1]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@ff7ee0da84bc nginx-1.20.1]# . /etc/profile.d/nginx.sh

#开启服务
[root@ff7ee0da84bc ~]# nginx -c /usr/local/nginx/conf/nginx.conf
[root@ff7ee0da84bc ~]# ss -anlt
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port      Process      
LISTEN      0           128                    0.0.0.0:80                  0.0.0.0:*                      

部署mysql镜像
创建容器后设置端口映射进入容器,再编译安装mysql
[root@localhost ~]# docker run --name mysql -it centos:8
创建系统用户mysql
[root@643b797dd993 /]# useradd -r -M -s /sbin/nologin mysql
安装依赖环境
[root@643b797dd993 /]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs

将安装包传到contos里面去
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  nginx-1.20.1.tar.gz
[root@localhost src]# docker cp /usr/src/nginx-1.20.1.tar.gz  centos2:/usr/local

进去继续编译mysql
解压后创建软连接
[root@643b797dd993 src]# cd /usr/local/
[root@643b797dd993 local]# ls
bin  games    lib    libexec                                     sbin   src
etc  include  lib64  mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz  share
[root@643b797dd993 local]# tar xf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz 
[root@643b797dd993 local]# ln -sv mysql-5.7.35-linux-glibc2.12-x86_64 mysql     
'mysql' -> 'mysql-5.7.35-linux-glibc2.12-x86_64'
[root@643b797dd993 local]# ls
bin  games    lib    libexec  mysql-5.7.35-linux-glibc2.12-x86_64         sbin   src
etc  include  lib64  mysql    mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz  share


添加环境变量
[root@643b797dd993 src]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@643b797dd993 src]# . /etc/profile.d/mysql.sh
[root@643b797dd993 src]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值