源码编译-nginx
安装所需工具包
[root@localhost ~]# yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
docker | 2.9 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Loading mirror speeds from cached hostfile
- base: mirrors.nju.edu.cn
- extras: mirrors.aliyun.com
- updates: mirrors.aliyun.com
…
Complete!
[root@localhost ~]# wget http://nginx.org/download/nginx-1.8.0.tar.gz 下载nginx的配置文件
–2020-11-26 20:49:30-- http://nginx.org/download/nginx-1.8.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: 832104 (813K) [application/octet-stream]
Saving to: ‘nginx-1.8.0.tar.gz’
100%[============================================================================================>] 832,104 137KB/s in 9.1s
2020-11-26 20:49:45 (89.5 KB/s) - ‘nginx-1.8.0.tar.gz’ saved [832104/832104]
[root@localhost ~]# tar -zxvf nginx-1.8.0.tar.gz
[root@localhost ~]# ll
total 3270344
-rw-------. 1 root root 1079 Nov 26 16:23 anaconda-ks.cfg
-rw-r–r--. 1 root root 3314069073 Nov 28 2019 Docker.tar.gz
drwxr-xr-x. 8 1001 1001 4096 Apr 21 2015 nginx-1.8.0
-rw-r–r--. 1 root root 832104 Apr 21 2015 nginx-1.8.0.tar.gz
-rw-r–r--. 1 root root 33918976 Dec 14 2019 registry_latest.tar
[root@localhost ~]# cd nginx-1.8.0
[root@localhost nginx-1.8.0]# ll
total 636
drwxr-xr-x. 6 1001 1001 4096 Nov 26 20:51 auto
-rw-r--r--. 1 1001 1001 249124 Apr 21 2015 CHANGES
-rw-r--r--. 1 1001 1001 379021 Apr 21 2015 CHANGES.ru
drwxr-xr-x. 2 1001 1001 4096 Nov 26 20:51 conf
-rwxr-xr-x. 1 1001 1001 2478 Apr 21 2015 configure
drwxr-xr-x. 4 1001 1001 68 Nov 26 20:51 contrib
drwxr-xr-x. 2 1001 1001 38 Nov 26 20:51 html
-rw-r--r--. 1 1001 1001 1397 Apr 21 2015 LICENSE
drwxr-xr-x. 2 1001 1001 20 Nov 26 20:51 man
-rw-r--r--. 1 1001 1001 49 Apr 21 2015 README
drwxr-xr-x. 8 1001 1001 71 Nov 26 20:51 src
[root@localhost nginx-1.8.0]# mkdir -p /usr/local/nginx 创建目录
- List item
[root@localhost nginx-1.8.0]# ./configure --prefix=/usr/local/nginx
[root@localhost nginx-1.8.0]# echo $?
0
[root@localhost nginx-1.8.0]# make 编译
[root@localhost nginx-1.8.0]# echo $?
0
[root@localhost nginx-1.8.0]# make install 安装
[root@localhost nginx-1.8.0]# echo $?
0
[root@localhost nginx-1.8.0]# cd /usr/local/nginx
[root@localhost nginx]# ll
total 4
drwxr-xr-x. 2 root root 4096 Nov 26 21:04 conf
drwxr-xr-x. 2 root root 38 Nov 26 21:04 html
drwxr-xr-x. 2 root root 6 Nov 26 21:04 logs
drwxr-xr-x. 2 root root 18 Nov 26 21:04 sbin
[root@localhost nginx]# ./sbin/nginx
[root@localhost nginx]# netstat -ntpl 查看端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 35096/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1501/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2173/master
tcp6 0 0 :::5000 :::* LISTEN 32460/docker-proxy
tcp6 0 0 :::21 :::* LISTEN 23439/vsftpd
tcp6 0 0 :::22 :::* LISTEN 1501/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2173/master
[root@localhost nginx]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7e5a67e4d458 registry:latest “/entrypoint.sh /etc…” 4 hours ago Up 3 hours 0.0.0.0:5000->5000/tcp flamboyant_rosalind
查看防火墙是否关闭
[root@localhost nginx]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2020-11-26 16:45:12 CST; 4h 26min ago
Main PID: 899 (code=exited, status=0/SUCCESS)
Nov 26 16:28:40 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 26 16:28:42 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 26 16:45:11 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
Nov 26 16:45:12 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
打开浏览器,访问nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx -v 查看版本
nginx version: nginx/1.8.0
[root@localhost ~]# /usr/local/nginx/sbin/nginx -h 查看所有命令
nginx version: nginx/1.8.0
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s load 重启
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop 停止/关闭
Dockerfile示例-nginx
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.200.90:5000/centos latest 300e315adb2f Less than a second ago 209MB
centos latest 300e315adb2f Less than a second ago 209MB
nginx latest f949e7d76d63 14 months ago 126MB
192.168.200.90:5000/nginx latest f949e7d76d63 14 months ago 126MB
registry latest c9bd19d022f6 4 years ago 33.3MB
[root@localhost ~]# curl http://192.168.200.90:5000/v2/_catalog
{“repositories”:[“centos”,“nginx”]}
[root@localhost ~]# wget http://www.apelearn.com/study_v2/.nginx_conf
–2020-11-26 21:29:54-- http://www.apelearn.com/study_v2/.nginx_conf
Resolving www.apelearn.com (www.apelearn.com)… 47.104.7.242
Connecting to www.apelearn.com (www.apelearn.com)|47.104.7.242|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 1678 (1.6K) [application/octet-stream]
Saving to: ‘.nginx_conf’
100%[============================================================================================>] 1,678 --.-K/s in 0s
2020-11-26 21:29:55 (125 MB/s) - ‘.nginx_conf’ saved [1678/1678]
[root@localhost ~]# ll -a 查看隐藏文件
total 3270380
dr-xr-x---. 4 root root 4096 Nov 26 21:29 .
dr-xr-xr-x. 17 root root 4096 Nov 26 16:22 ..
-rw-------. 1 root root 1079 Nov 26 16:23 anaconda-ks.cfg
-rw-------. 1 root root 2196 Nov 26 20:38 .bash_history
-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc
-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
-rw-r--r--. 1 root root 3314069073 Nov 28 2019 Docker.tar.gz
drwxr-xr-x. 9 1001 1001 4096 Nov 26 21:00 nginx-1.8.0
-rw-r--r--. 1 root root 832104 Apr 21 2015 nginx-1.8.0.tar.gz
-rw-r--r--. 1 root root 1678 Jun 26 2015 .nginx_conf
drwxr-----. 3 root root 18 Nov 26 18:08 .pki
-rw-r--r--. 1 root root 33918976 Dec 14 2019 registry_latest.tar
-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
[root@localhost ~]# vi Dockerfile 编写Dockerfile文件
FROM 192.168.200.90:5000/centos
MAINTAINER zouzhe
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
ADD http://nginx.org/download/nginx-1.8.0.tar.gz .
RUN tar -zxf nginx-1.8.0.tar.gz
RUN mkdir -p /usr/local/nginx
RUN cd /nginx-1.8.0 && ./configure --prefix=/usr/local/nginx && make && make install
RUN rm -fv /usr/local/nginx/conf/nginx.conf
COPY .nginx_conf /usr/local/nginx/conf/nginx.conf
EXPOSE 80
ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -f /etc/passwd
[root@localhost ~]# docker build -t centos_nginx . 创建镜像(报错)
方法二
在secureFX上,上传包
[root@localhost ~]# cat centos-7-x86_64-minimal.tar.gz | docker import - centos7
[root@localhost ~]# docker tag 2dcad540baac 192.168.200.130:5000/centos7 打标签
[root@localhost ~]# docker push 192.168.200.130:5000/centos7 拉镜像
[root@localhost ~]# vi Dockerfile 编写Dockerfile文件
FROM 192.168.200.90:5000/centos7
MAINTAINER zouzhe
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
ADD http://nginx.org/download/nginx-1.8.0.tar.gz .
RUN tar -zxf nginx-1.8.0.tar.gz
RUN mkdir -p /usr/local/nginx
RUN cd /nginx-1.8.0 && ./configure --prefix=/usr/local/nginx && make && make install
RUN rm -fv /usr/local/nginx/conf/nginx.conf
COPY .nginx_conf /usr/local/nginx/conf/nginx.conf
EXPOSE 80
ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -f /etc/passwd
[root@localhost ~]# docker build -t centos_nginx . 创建镜像(不要忘了后面的点)
…
Successfully built 48d7609dc2ac
Successfully tagged centos_nginx:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.200.90:5000/centos latest 300e315adb2f Less than a second ago 209MB
centos latest 300e315adb2f Less than a second ago 209MB
centos_nginx latest 48d7609dc2ac 9 minutes ago 799MB
[root@localhost ~]# docker run -itd --name centos_nginx -p 8088:80 centos_nginx bash
e58747997b8cddb333f2f48ef5b092f2a381a4e6fb1f4ada2b3bf4eb433601b4
打开浏览器访问