CentOS容器中安裝Nginx
1.載入本地 centos8.tar 映象
docker load --input centos8.tar
[root@VM_0_6_centos images-bak]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@VM_0_6_centos images-bak]# ls
centos8.tar
[root@VM_0_6_centos images-bak]# docker load --input centos8.tar
Loaded image: centos:latest
[root@VM_0_6_centos images-bak]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 0d120b6ccaa8 10 days ago 215MB
[root@VM_0_6_centos images-bak]#
2.啟動centos容器
docker run -itd --name centos-test centos:latest
[root@VM_0_6_centos images-bak]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 0d120b6ccaa8 10 days ago 215MB
[root@VM_0_6_centos images-bak]# docker run -itd --name centos-test centos:latest
57e5009437df2fbef3f234e1ce7c09c4311656bd9e4acf8a164f43a509cfbfc1
[root@VM_0_6_centos images-bak]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
57e5009437df centos:latest "/bin/bash" 3 seconds ago Up 2 seconds centos-test
[root@VM_0_6_centos images-bak]#
docker rm -f centos:latest 刪除以前已停止,殘留的容器
3.進入centos容器bash
docker exec -i -t centos-test /bin/bash
[root@VM_0_6_centos images-bak]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
57e5009437df centos:latest "/bin/bash" 3 seconds ago Up 2 seconds centos-test
[root@VM_0_6_centos images-bak]# docker exec -i -t centos-test /bin/bash
[root@57e5009437df /]#
4.在centos容器裡安裝Nginx
1.安裝編譯軟體
yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
[root@57e5009437df /]# gcc -v
bash: gcc: command not found
[root@57e5009437df /]# yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream 907 kB/s | 5.8 MB 00:06
CentOS-8 - Base 1.8 MB/s | 2.2 MB 00:01
CentOS-8 - Extras 1.4 kB/s | 7.3 kB 00:05
Package zlib-1.2.11-13.el8.x86_64 is already installed.
Package pcre-8.42-4.el8.x86_64 is already installed.
2.下載Nginx軟體
yum -y install wget
wget http://nginx.org/download/nginx-1.18.0.tar.gz
[root@57e5009437df src]# pwd
/usr/local/src
[root@57e5009437df src]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
--2020-08-21 09:39:15-- http://nginx.org/download/nginx-1.18.0.tar.gz
Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1039530 (1015K) [application/octet-stream]
Saving to: 'nginx-1.18.0.tar.gz'
3.解壓nginx-1.18.0.tar.gz和安裝
在 nginx-1.18.0.tar.gz 當前目錄下 執行解壓
tar -zxvf nginx-1.18.0.tar.gz
解壓縮後,可以看到 nginx-1.18.0
目錄,然後進入這個目錄
cd nginx-1.18.0
在 nginx-1.18.0
目錄下執行 配置 和 make 命令
# 1.配置
[root@xxx nginx-1.18.0]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-pcre --with-http_gzip_static_module --with-http_ssl_module
# 1.make 和 安裝
[root@xxx nginx-1.18.0]# make && make install
注意:
--prefix=PATH
: 指定 nginx
的安裝目錄。預設 /usr/local/nginx
,我的是 /usr/local/webserver/nginx
--with-http_stub_status_module
: 用來監控 Nginx
的當前狀態
--with-pcre
: 讓nginx支援正規表示式, 需要安裝 pcre 與 pcre-devel
--with-http_gzip_static_module
: 允許nginx傳送以“.gz”作為副檔名的預壓縮檔案,以替代傳送普通檔案
--with-http_ssl_module
: 使用https
協議模組。預設情況下,該模組沒有被構建。前提是openssl
與openssl-devel
已安裝
4.啟動Nginx和檢查是否啟動
/usr/local/webserver/nginx/sbin/mginx
curl localhost
5.修改nginx.conf配置
將 nginx 切換為 守護程式(daemon)
##Nginx worker程式個數:其數量直接影響效能。
#每個worker程式都是單執行緒的程式,他們會呼叫各個模組以實現多種多樣的功能。如果這些模組不會出現阻塞式的呼叫,那麼,有多少CPU核心就應該配置多少個程式,反之,有可能出現阻塞式呼叫,那麼,需要配置稍多一些的worker程式。
worker_processes 1;
##守護程式(daemon)。是脫離終端在後臺允許的程式。它脫離終端是為了避免程式執行過程中的資訊在任何終端上顯示。這樣一來,程式也不會被任何終端所產生的資訊所打斷。##
##關閉守護程式的模式,之所以提供這種模式,是為了放便跟蹤除錯nginx,畢竟用gdb除錯程式時最繁瑣的就是如何繼續跟進fork出的子程式了。##
##如果用off關閉了master_proccess方式,就不會fork出worker子程式來處理請求,而是用master程式自身來處理請求
daemon off;
修改完之後推出即可
6.centos中的nginx自啟動
可以編寫:Dockerfile
7.centos-test容器生成映象
docker commit -a “liujun” -m “centos-test容器生成映象nginx18:v1” a404c6c174a2 nginx18:v1
[root@VM_0_6_centos images-bak]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a4e66f4ffd4 centos:latest "/bin/bash" 23 minutes ago Up 4 minutes 0.0.0.0:80->80/tcp centos-test
[root@VM_0_6_centos images-bak]# docker commit -a "liujun" -m "centos-test容器生成映象nginx18:v1" 2a4e nginx18:v1
sha256:828b659f7a7760a4807407e33d0d9b7b524de5ceee55580e0827ddb794c53c68
[root@VM_0_6_centos images-bak]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a4e66f4ffd4 centos:latest "/bin/bash" 24 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp centos-test
[root@VM_0_6_centos images-bak]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx18 v1 828b659f7a77 12 seconds ago 487MB
centos latest 0d120b6ccaa8 10 days ago 215MB
[root@VM_0_6_centos images-bak]#
8.執行nginx18映象
[root@VM_0_6_centos images-bak]# docker run -itd -p 8080:80 --name nginx-test nginx18:v1
32ea0a0d794045faada609ba777ce5449499c80d6a6266de3da0ea9ae58db85d
[root@VM_0_6_centos images-bak]#
執行nginx18映象時 nginx18 伺服器並沒有自動啟動, 需要手動啟動
第一步:docker exec -i -t nginx-test /bin/bash // 進入容器
第二步:/usr/local/webserver/nginx/sbin/nginx // 啟動nginx伺服器
如何實現在 啟動容器的時候自動啟動容器中的 Nginx 伺服器?
相關文章
- centos7中使用yum安裝NGINX安裝CentOSNginx
- CentOS 上安裝 NginxCentOSNginx
- CentOS 7 - 安裝NginxCentOSNginx
- Centos 7 安裝NginxCentOSNginx
- centos下安裝nginxCentOSNginx
- centos 7.6 安裝 nginxCentOSNginx
- 在CentOS7中,使用yum安裝NginxCentOSNginx
- CentOS 7 yum 安裝 NGINXCentOSNginx
- centos安裝nginx1.17.9CentOSNginx
- CentOS離線安裝NginxCentOSNginx
- CentOS系統安裝NginxCentOSNginx
- CentOS7-安裝NginxCentOSNginx
- CentOS7 安裝NginxCentOSNginx
- centos上nginx的安裝CentOSNginx
- Centos原始碼安裝NginxCentOS原始碼Nginx
- Centos7.2安裝NginxCentOSNginx
- CentOS 6.5安裝Nginx (一)CentOSNginx
- Centos-6.3安裝NginxCentOSNginx
- Centos 7 yum 安裝nginxCentOSNginx
- Centos7 安裝 NginxCentOSNginx
- centos7安裝nginxCentOSNginx
- CentOS 下編譯安裝 NginxCentOS編譯Nginx
- centos 下 安裝 node,nginx, mysqlCentOSNginxMySql
- CentOS7.X安裝NginxCentOSNginx
- gerrit+nginx+centos安裝配置NginxCentOS
- CentOS 7 安裝 nginx-rtmpCentOSNginx
- CentOS7原始碼安裝NginxCentOS原始碼Nginx
- 如何在 CentOS 7 上安裝 NginxCentOSNginx
- Centos下安裝FastDFS及Nginx模組CentOSASTNginx
- Centos7安裝Nginx實戰CentOSNginx
- CentOS6.6 安裝 nginx-1.8.0CentOSNginx
- centos/linux下的安裝NginxCentOSLinuxNginx
- centos+nginx+redmine+gitosis安裝指南CentOSNginxGit
- CentOS下安裝Nginx並新增nginx_upload_moduleCentOSNginx
- centos7通過yum安裝nginxCentOSNginx
- centos7+安裝nginx+php7CentOSNginxPHP
- Centos7Nginx+PHP安裝步驟CentOSNginxPHP
- CentOS6.5安裝nginx1.20CentOSNginx