1、用处:定制
1.部分软件,官方只提供源码包,需要自行编译安装
2.运维需要规范时,我们想把所有的软件全都安装到同一个目录下
PS:咱们使用windows时,强迫症,我装的QQ,微信,游戏等...全都要放到D盘的某一个目录下
3.有些软件,官方刚发布,还没来得及制作成RPM包,那么我们可以自行编译安装
2、优缺点
优点:
1.有了源码包,那我就可以自行修改代码,提供我们使用,传说中的二次开发
2.定制
3.新版本优先更新源码
4.自动化规范,方便落地
缺点:
1.相对于yum安装,复杂
2.耗时比较长
3、获取:
常见的软件,源码包均可以去官方网站获取源码包。
4、源码安装步骤
安装源码包,必须要经历4个步骤
1.解压 tar
2.生成 ./configure cmake
3.编译 make
4.安装 make install
实战:源码安装nginx
[root@localhost ~]# wget https://nginx.org/download/nginx-1.20.2.tar.gz 下载
[root@localhost ~]# ll 下载后看一下
total 2440
。。。。。。
-rw-r--r--. 1 root root 1062124 Nov 16 2021 nginx-1.20.2.tar.gz
[root@localhost ~]# tar -xf nginx-1.20.2.tar.gz 解压缩
[root@localhost ~/nginx-1.20.2]# ll 打开
total 792
drwxr-xr-x. 6 1001 dba 4096 Aug 31 11:51 auto
-rw-r--r--. 1 1001 dba 312251 Nov 16 2021 CHANGES
-rw-r--r--. 1 1001 dba 476577 Nov 16 2021 CHANGES.ru
drwxr-xr-x. 2 1001 dba 168 Aug 31 11:51 conf
-rwxr-xr-x. 1 1001 dba 2590 Nov 16 2021 configure
drwxr-xr-x. 4 1001 dba 72 Aug 31 11:51 contrib
drwxr-xr-x. 2 1001 dba 40 Aug 31 11:51 html
-rw-r--r--. 1 1001 dba 1397 Nov 16 2021 LICENSE
drwxr-xr-x. 2 1001 dba 21 Aug 31 11:51 man
-rw-r--r--. 1 1001 dba 49 Nov 16 2021 README
drwxr-xr-x. 9 1001 dba 91 Aug 31 11:51 src
# 直接这条生成命令会报错
./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module
选安装路径 到/opt下 相当于windows安软件下面要勾选的项目
# 需安装三个依赖
yum install -y gcc gcc-c++ glibc 第一个报错 缺少C
yum install -y pcre-devel 第二个报错 依赖PCRE
yum install -y openssl-devel 第三个报错
# 依赖安装完之后再装就OK了:
[root@localhost ~/nginx-1.20.2]# ./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_statu
......(省略输出)
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/opt/nginx-1.20.2"
nginx binary file: "/opt/nginx-1.20.2/sbin/nginx"
nginx modules path: "/opt/nginx-1.20.2/modules"
nginx configuration prefix: "/opt/nginx-1.20.2/conf"
nginx configuration file: "/opt/nginx-1.20.2/conf/nginx.conf"
nginx pid file: "/opt/nginx-1.20.2/logs/nginx.pid"
nginx error log file: "/opt/nginx-1.20.2/logs/error.log"
nginx http access log file: "/opt/nginx-1.20.2/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
# 编译(让系统识别你的代码
[root@localhost ~/nginx-1.20.2]# make
# 安装
[root@localhost ~/nginx-1.20.2]# make install
# 看一眼
[root@localhost ~/nginx-1.20.2]# cd /opt 安装完去看一下
[root@localhost /opt]# ll
total 4
-rw-r--r--. 1 root root 0 Aug 25 11:11 {1...1000}.txt
-rw-r--r--. 1 root root 0 Aug 25 11:24 {1.1000}.txt
-rw-r--r--. 1 root root 0 Aug 25 11:16 {1.10}.txt
drwxr-xr-x. 6 root root 54 Aug 31 12:14 nginx-1.20.2 # 有了
-rw-r--r--. 1 root root 45 Aug 29 20:38 test_opt.tar.gz
-rw-r--r--. 1 root root 0 Aug 29 20:34 yjh.txt
# 做个软链接 opt下
[root@localhost /opt]# ln -s /opt/nginx-1.20.2/ /opt/nginx
[root@localhost /opt]# ll
total 4
-rw-r--r--. 1 root root 0 Aug 25 11:11 {1...1000}.txt
-rw-r--r--. 1 root root 0 Aug 25 11:24 {1.1000}.txt
-rw-r--r--. 1 root root 0 Aug 25 11:16 {1.10}.txt
lrwxrwxrwx. 1 root root 18 Aug 31 12:16 nginx -> /opt/nginx-1.20.2/
drwxr-xr-x. 6 root root 54 Aug 31 12:14 nginx-1.20.2
-rw-r--r--. 1 root root 45 Aug 29 20:38 test_opt.tar.gz
-rw-r--r--. 1 root root 0 Aug 29 20:34 yjh.txt
[root@localhost /opt]# cd nginx
[root@localhost /opt/nginx]# ll
total 4
drwxr-xr-x. 2 root root 4096 Aug 31 12:14 conf
drwxr-xr-x. 2 root root 40 Aug 31 12:14 html
drwxr-xr-x. 2 root root 6 Aug 31 12:14 logs
drwxr-xr-x. 2 root root 19 Aug 31 12:14 sbin
看到这四个安装成功。
#加入变量PATH中,使其可以直接执行
[root@localhost ~]# vim /etc/profile.d/nginx.sh
在其中输入
export PATH="$PATH:/opt/nginx/sbin"
#看一下 有了
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/nginx/sbin:/root/bin
#source一下
[root@localhost ~]# source /etc/profile
(source命令通常用于保留、更改当前shell中的环境变量。简而言之,source一个脚本,将会在当前shell中运行 execute命令 )
[root@localhost ~]# nginx
[root@localhost ~]# netstat -lntup 看一眼
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 12019/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6965/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7120/master
tcp6 0 0 :::22 :::* LISTEN 6965/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7120/master
[root@localhost ~]# netstat -lntup|grep nginx 看到nginx 80端口 说明没问题
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12019/nginx: master
[root@localhost ~]# systemctl stop firewalld 防火墙停一下
[root@localhost /opt/nginx]# setenforce 0
(setenforce是Linux的selinux防火墙配置命令, 执行setenforce 0 表示临时关闭selinux防火墙。)
[root@localhost ~]# systemctl restart firewalld 开防火墙 开了就连不上了
输入服务器IP,访问到Nginx页面说明已成功安装:
页面更新:2024-04-23
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号