(一) 根据需求配置
在编译时候,你可以加上这些参数,指定一些额外的功能
--prefix=... Directories to put files in /usr/local 软件加目录
--bindir=... $prefix/bin 命令的目录
--etcdir=... $prefix/etc 配置文件的目录
--mandir=... $prefix/share/man man 文档路径
--locale=... $prefix/share/locale
...
(二) 编译
make (使用gcc编译器进行编译)
(三) 安装
make install 类似 rpm -ivh
(四) 源码安装示例
1.安装需求 以下步骤适用于 所有 centos 系统源代码编译
1.源代码安装 nginx 工具,编译安装淘宝 nginx 官网:https://tengine.taobao.org
获取软件包地址:https://tengine.taobao.org/download/tengine-3.0.0.tar.gz
把以前的都删除 rm -rf * 删除该目录下所有目录和文件
## 下载 tengine(淘宝nginx)
[root@lcds opt]# wget https://tengine.taobao.org/download/tengine-3.0.0.tar.gz
## 查看下载情况
[root@lcds opt]# ll
总用量 158484
-rw-r--r--. 1 root root 76381940 8月 4 10:36 firefox-116.0.tar.bz2
-rw-r--r--. 1 root root 82658156 4月 16 2018 firefox-52.7.3-1.el7_5.x86_64.rpm
-rw-r--r--. 1 root root 3243580 7月 21 16:33 tengine-3.0.0.tar.gz
## 解压缩
[root@lcds opt]# tar -zxvf tengine-3.0.0.tar.gz
## 查看解压缩后的情况
[root@lcds opt]# ll
总用量 158488
-rw-r--r--. 1 root root 76381940 8月 4 10:36 firefox-116.0.tar.bz2
-rw-r--r--. 1 root root 82658156 4月 16 2018 firefox-52.7.3-1.el7_5.x86_64.rpm
drwxrwxr-x. 13 root root 4096 7月 20 20:52 tengine-3.0.0
-rw-r--r--. 1 root root 3243580 7月 21 16:33 tengine-3.0.0.tar.gz
## 进入到 tengine-3.0.0 源码包
[root@lcds opt]# cd tengine-3.0.0
[root@lcds tengine-3.0.0]#
oot@lcds tengine-3.0.0]# ls
AUTHORS.te auto CHANGES CHANGES.cn CHANGES.te conf configure contrib docs html LICENSE man modules packages README.markdown src tests THANKS.te
ls make *
## 找到可执行文件 configure
[root@lcds tengine-3.0.0]# ll
总用量 420
-rw-rw-r--. 1 root root 931 7月 20 20:52 AUTHORS.te
drwxrwxr-x. 6 root root 4096 7月 20 20:52 auto
-rw-rw-r--. 1 root root 323310 7月 20 20:52 CHANGES
-rw-rw-r--. 1 root root 28884 7月 20 20:52 CHANGES.cn
-rw-rw-r--. 1 root root 36957 7月 20 20:52 CHANGES.te
drwxrwxr-x. 2 root root 184 7月 20 20:52 conf
-rwxrwxr-x. 1 root root 2502 7月 20 20:52 configure
drwxrwxr-x. 4 root root 109 7月 20 20:52 contrib
drwxrwxr-x. 4 root root 67 7月 20 20:52 docs
drwxrwxr-x. 2 root root 40 7月 20 20:52 html
-rw-rw-r--. 1 root root 1715 7月 20 20:52 LICENSE
drwxrwxr-x. 2 root root 21 7月 20 20:52 man
drwxrwxr-x. 32 root root 4096 7月 20 20:52 modules
drwxrwxr-x. 3 root root 20 7月 20 20:52 packages
-rw-rw-r--. 1 root root 4999 7月 20 20:52 README.markdown
drwxrwxr-x. 10 root root 103 7月 20 20:52 src
drwxrwxr-x. 4 root root 43 7月 20 20:52 tests
-rw-rw-r--. 1 root root 43 7月 20 20:52 THANKS.te
configure的参数配置 查询 nginx重新编译ssl模块教程
## 安装支持openssl模块证书 其实就是一堆依赖 在编译安装时候,可以支持很多扩展
yum -y install openssl openssl-devel pcre pcre-devel zlib zlib-devel
##
./configure --prefix=/usr/local/nginx --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
# 查看 可以到生成了 Makefile 文件
[root@lcds tengine-2.3.3]# ll
总用量 392
-rw-rw-r--. 1 root root 931 3月 29 2021 AUTHORS.te
drwxrwxr-x. 6 root root 4096 3月 29 2021 auto
-rw-rw-r--. 1 root root 302927 3月 29 2021 CHANGES
-rw-rw-r--. 1 root root 27289 3月 29 2021 CHANGES.cn
-rw-rw-r--. 1 root root 34831 3月 29 2021 CHANGES.te
drwxrwxr-x. 2 root root 184 3月 29 2021 conf
-rwxrwxr-x. 1 root root 2502 3月 29 2021 configure
drwxrwxr-x. 4 root root 109 3月 29 2021 contrib
drwxrwxr-x. 4 root root 67 3月 29 2021 docs
drwxrwxr-x. 2 root root 40 3月 29 2021 html
-rw-rw-r--. 1 root root 1715 3月 29 2021 LICENSE
-rw-r--r--. 1 root root 384 8月 4 22:42 Makefile # 生成的文件
drwxrwxr-x. 2 root root 21 3月 29 2021 man
drwxrwxr-x. 26 root root 4096 3月 29 2021 modules
drwxr-xr-x. 4 root root 140 8月 4 22:42 objs
drwxrwxr-x. 3 root root 20 3月 29 2021 packages
-rw-rw-r--. 1 root root 3450 3月 29 2021 README.markdown
drwxrwxr-x. 10 root root 103 3月 29 2021 src
drwxrwxr-x. 4 root root 43 3月 29 2021 tests
-rw-rw-r--. 1 root root 43 3月 29 2021 THANKS.te
# 开始编译安装执行如下命令完 make && make install
# 当你 make 命令执行成功后,自动执行 make install 命令
# 只有 make install 成功后,才会生成你指定的 nginx 路径 /opt/my_nginx 文件夹
[root@lcds tengine-3.0.0]# make && make install
# 检查你安装的nginx是否生成 my_nginx
[root@lcds tengine-3.0.0]# cd /opt/
[root@lcds opt]# ll
总用量 158104
-rw-r--r--. 1 root root 76381940 8月 4 10:36 firefox-116.0.tar.bz2
-rw-r--r--. 1 root root 82658156 4月 16 2018 firefox-52.7.3-1.el7_5.x86_64.rpm
drwxr-xr-x. 6 root root 54 8月 4 23:11 my_nginx
drwxrwxr-x. 14 root root 4096 8月 4 22:36 tengine-3.0.0
-rw-r--r--. 1 root root 2848144 7月 21 16:33 tengine-3.0.0.tar.gz
[root@lcds opt]# cd my_nginx
[root@lcds my_nginx]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 8月 4 23:11 conf # 配置文件
drwxr-xr-x. 2 root root 40 8月 4 23:11 html # 前端的html文件
drwxr-xr-x. 2 root root 6 8月 4 23:11 logs # nginx的日志
drwxr-xr-x. 2 root root 19 8月 4 23:11 sbin # 可执行的二进制命令
[root@lcds my_nginx]#
[root@lcds my_nginx]# ll ./conf/
总用量 68
-rw-r--r--. 1 root root 1077 8月 4 23:11 fastcgi.conf
-rw-r--r--. 1 root root 1077 8月 4 23:11 fastcgi.conf.default
-rw-r--r--. 1 root root 1007 8月 4 23:11 fastcgi_params
-rw-r--r--. 1 root root 1007 8月 4 23:11 fastcgi_params.default
-rw-r--r--. 1 root root 2837 8月 4 23:11 koi-utf
-rw-r--r--. 1 root root 2223 8月 4 23:11 koi-win
-rw-r--r--. 1 root root 5231 8月 4 23:11 mime.types
-rw-r--r--. 1 root root 5231 8月 4 23:11 mime.types.default
-rw-r--r--. 1 root root 3509 8月 4 23:11 nginx.conf
-rw-r--r--. 1 root root 3509 8月 4 23:11 nginx.conf.default
-rw-r--r--. 1 root root 636 8月 4 23:11 scgi_params
-rw-r--r--. 1 root root 636 8月 4 23:11 scgi_params.default
-rw-r--r--. 1 root root 664 8月 4 23:11 uwsgi_params
-rw-r--r--. 1 root root 664 8月 4 23:11 uwsgi_params.default
-rw-r--r--. 1 root root 3610 8月 4 23:11 win-utf
[root@lcds my_nginx]# ll ./sbin/
总用量 6144
-rwxr-xr-x. 1 root root 6291432 8月 4 23:11 nginx # 可执行的二进制文件
[root@lcds my_nginx]# ll ./logs/
总用量 0
[root@lcds my_nginx]# ll ./html/
总用量 8
-rw-r--r--. 1 root root 496 8月 4 23:11 50x.html
-rw-r--r--. 1 root root 555 8月 4 23:11 index.html
[root@lcds my_nginx]#
# 可以用该目录下的二进制 nginx 命令,启动淘宝 nginx 了
# 以下是绝对路径启动 nginx
[root@lcds my_nginx]# /opt/my_nginx/sbin/nginx
[root@lcds my_nginx]# netstat -tunlp | grep 80
-bash: netstat: 未找到命令
[root@lcds my_nginx]#
要安装使用 netstat 命令,需要先安装工具 ,安装步骤如下所示:
一。首先配置好本机的yum源
[root@lcds ~]# yum repolist all
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
源标识 源名称 状态
C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base 禁用
C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus 禁用
C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras 禁用
C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - Fasttrack 禁用
C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates 禁用
C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base 禁用
C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus 禁用
C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras 禁用
C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - Fasttrack 禁用
C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates 禁用
C7.2.1511-base/x86_64 CentOS-7.2.1511 - Base 禁用
C7.2.1511-centosplus/x86_64 CentOS-7.2.1511 - CentOSPlus 禁用
C7.2.1511-extras/x86_64 CentOS-7.2.1511 - Extras 禁用
C7.2.1511-fasttrack/x86_64 CentOS-7.2.1511 - Fasttrack 禁用
C7.2.1511-updates/x86_64 CentOS-7.2.1511 - Updates 禁用
C7.3.1611-base/x86_64 CentOS-7.3.1611 - Base 禁用
C7.3.1611-centosplus/x86_64 CentOS-7.3.1611 - CentOSPlus 禁用
C7.3.1611-extras/x86_64 CentOS-7.3.1611 - Extras 禁用
C7.3.1611-fasttrack/x86_64 CentOS-7.3.1611 - Fasttrack 禁用
C7.3.1611-updates/x86_64 CentOS-7.3.1611 - Updates 禁用
C7.4.1708-base/x86_64 CentOS-7.4.1708 - Base 禁用
C7.4.1708-centosplus/x86_64 CentOS-7.4.1708 - CentOSPlus 禁用
C7.4.1708-extras/x86_64 CentOS-7.4.1708 - Extras 禁用
C7.4.1708-fasttrack/x86_64 CentOS-7.4.1708 - Fasttrack 禁用
C7.4.1708-updates/x86_64 CentOS-7.4.1708 - Updates 禁用
C7.5.1804-base/x86_64 CentOS-7.5.1804 - Base 禁用
C7.5.1804-centosplus/x86_64 CentOS-7.5.1804 - CentOSPlus 禁用
C7.5.1804-extras/x86_64 CentOS-7.5.1804 - Extras 禁用
C7.5.1804-fasttrack/x86_64 CentOS-7.5.1804 - Fasttrack 禁用
C7.5.1804-updates/x86_64 CentOS-7.5.1804 - Updates 禁用
C7.6.1810-base/x86_64 CentOS-7.6.1810 - Base 禁用
C7.6.1810-centosplus/x86_64 CentOS-7.6.1810 - CentOSPlus 禁用
C7.6.1810-extras/x86_64 CentOS-7.6.1810 - Extras 禁用
C7.6.1810-fasttrack/x86_64 CentOS-7.6.1810 - Fasttrack 禁用
C7.6.1810-updates/x86_64 CentOS-7.6.1810 - Updates 禁用
C7.7.1908-base/x86_64 CentOS-7.7.1908 - Base 禁用
C7.7.1908-centosplus/x86_64 CentOS-7.7.1908 - CentOSPlus 禁用
C7.7.1908-extras/x86_64 CentOS-7.7.1908 - Extras 禁用
C7.7.1908-fasttrack/x86_64 CentOS-7.7.1908 - Fasttrack 禁用
C7.7.1908-updates/x86_64 CentOS-7.7.1908 - Updates 禁用
C7.8.2003-base/x86_64 CentOS-7.8.2003 - Base 禁用
C7.8.2003-centosplus/x86_64 CentOS-7.8.2003 - CentOSPlus 禁用
C7.8.2003-extras/x86_64 CentOS-7.8.2003 - Extras 禁用
C7.8.2003-fasttrack/x86_64 CentOS-7.8.2003 - Fasttrack 禁用
C7.8.2003-updates/x86_64 CentOS-7.8.2003 - Updates 禁用
base/7/x86_64 CentOS-7 - Base 启用: 10,072
base-debuginfo/x86_64 CentOS-7 - Debuginfo 禁用
base-source/7 CentOS-7 - Base Sources 禁用
c7-media CentOS-7 - Media 禁用
centos-kernel/7/x86_64 CentOS LTS Kernels for x86_64 禁用
centos-kernel-experimental/7/x86_64 CentOS Experimental Kernels for x86_64 禁用
centosplus/7/x86_64 CentOS-7 - Plus 禁用
centosplus-source/7 CentOS-7 - Plus Sources 禁用
cr/7/x86_64 CentOS-7 - cr 禁用
extras/7/x86_64 CentOS-7 - Extras 启用: 518
extras-source/7 CentOS-7 - Extras Sources 禁用
fasttrack/7/x86_64 CentOS-7 - fasttrack 禁用
updates/7/x86_64 CentOS-7 - Updates 启用: 5,116
updates-source/7 CentOS-7 - Updates Sources 禁用
repolist: 15,706
[root@lcds ~]#
二。查看提供命令的工具包 执行 yum provides */netstat
[root@lcds ~]# yum provides */netstat
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
base/7/x86_64/filelists_db | 7.2 MB 00:00:00
extras/7/x86_64/filelists_db | 303 kB 00:00:00
updates/7/x86_64/filelists_db | 12 MB 00:00:00
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
源 :base
匹配来源:
文件名 :/bin/netstat
三 安装工具包 执行安装命令 yum install net-tools -y
[root@lcds ~]# yum install net-tools -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 net-tools.x86_64.0.2.0-0.25.20131004git.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==============================================================================================================================================================================
Package 架构 版本 源 大小
==============================================================================================================================================================================
正在安装:
net-tools x86_64 2.0-0.25.20131004git.el7 base 306 k
事务概要
==============================================================================================================================================================================
安装 1 软件包
总下载量:306 k
安装大小:917 k
Is this ok [y/d/N]: y
Downloading packages:
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm | 306 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1
验证中 : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1
已安装:
net-tools.x86_64 0:2.0-0.25.20131004git.el7
完毕!
四 验证测试
[root@lcds ~]# netstat -an | grep 9200
[root@lcds ~]# netstat -tunlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19205/nginx: master
[root@lcds ~]#
[root@lcds ~]# ps -ef | grep nginx
root 19205 1 0 8月04 ? 00:00:00 nginx: master process /opt/my_nginx/sbin/nginx
nobody 19206 19205 0 8月04 ? 00:00:00 nginx: worker process
root 25558 12919 0 00:16 pts/2 00:00:00 grep --color=auto nginx
[root@lcds ~]# kill -9 19205
[root@lcds ~]# natstat -tunlp | grep 80
-bash: natstat: 未找到命令
[root@lcds ~]# netstat -tunlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19206/nginx: worker
[root@lcds ~]#
[root@lcds ~]# kill -9 19206
-bash: kill: (19206) - 没有那个进程
[root@lcds ~]# netstat -tunlp | grep 80
[root@lcds ~]#
[root@lcds ~]# /opt/my_nginx/sbin/nginx
[root@lcds ~]# netstat -tunlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4814/nginx: master
访问浏览IP:167就可以了
[root@lcds ~]# curl -I 192.168.31.213:167
curl: (7) Failed connect to 192.168.31.213:167; 拒绝连接
# 查询
[root@lcds ~]# ls /opt/my_nginx/
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
# 编译的软件,删除动作,直接干掉这个目录即可
[root@lcds ~]# rm -ef /opt/my_nginx/
注意环境冲突
本节内容实操流程及需要用到的工具
```
# 下载要安装的软件源码包
wget https://tengine.taobao.org/download/tengine-3.0.0.tar.gz
# 解压缩包
tar -zxvf tengine-3.0.0.tar.gz
# 安装依赖 解决编译器(gcc)及ssl证书问题
yum -y install gcc gcc-c++ autoconf make automake openssl openssl-devel pcre pcre-devel zlib zlib-devel
# 获取版本信息,检查gcc是否安装成功了 出现版本信息代表安装成功
gcc --version
# 解决工具问题
yum -y install wget httpd-tools vim
# 执行编译 安装路径
./configure --prefix=/usr/local/nginx --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
# 执行编译 安装路径 并且指定 --with-http_ssl_module
./configure --prefix=/opt/my_nginx/ --with-http_ssl_module
# 查看 可以到生成了 Makefile 文件
# 开始编译安装执行如下命令完 make && make install
```
以上就是源代码安装tengine的全过程即 淘宝nginx