linux中软件的安装方式

安装包

安装方式

rpm包

rpm,yum

源码包

源码安装

二进制包

解压即可

获取源码包

安装什么服务,就去什么服务的官方网站,下载源码包
windows安装.exe程序

源码安装及定制rpm包_nginx

linux安装源码包

源码安装及定制rpm包_nginx_02

先news然后download

源码安装及定制rpm包_源码包_03

# 1.nginx官网,下载源码包
http://nginx.org/

# 2.下载
[root@Y ~]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
[root@Y ~]# ll
-rw-r--r-- 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz

# 3.安装依赖包
[root@Y nginx-1.20.2]# yum install -y pcre-devel openssl-devel gcc
gcc-c++ glibc zlib-devel
以下包
pcre-devel
openssl-devel
gcc
gcc-c++
glibc
zlib-devel

# 4.解压
[root@Y ~]# tar xf nginx-1.20.2.tar.gz

# 5.生成
[root@Y ~]# cd nginx-1.20.2

./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module
--with-http_stub_status_module

## 报错解决:
# 报错一:
./configure: error: C compiler cc is not found

报错原因:缺少C语言环境 解决方法:yum install -y gcc gcc-c++ glibc

# 报错二
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module optio
n, or install the PCRE library into the system, or build the PCRE library stat
ically from the source with nginx by using --with-pcre=<path> option.

报错原因:缺少pcre库文件 解决方法:yum install -y pcre-devel

# 报错三
./configure: error: SSL modules require the OpenSSL library. You can either do n
ot enable the modules, or install the OpenSSL library into the system, or build th
e OpenSSL library statically from the source with nginx by using --with-openssl
=<path> option.

报错原因:缺少openssl库文件 解决方法:yum install -y openssl-devel

# 6.编译(让系统能识别你的代码,并且把刚才指定的功能和路径编译到源码中)
[root@Y nginx-1.20.2]# make

# 7.安装
[root@Y nginx-1.20.2]# make install

# 8.做软连接
[root@Y nginx-1.20.2]# ln -s /opt/nginx-1.20.2/ /opt/nginx
[root@Y nginx-1.20.2]# ll /opt/
total 0
lrwxrwxrwx 1 root root 18 Apr 27 10:01 nginx -> /opt/nginx-1.20.2/
drwxr-xr-x 6 root root 54 Apr 27 09:55 nginx-1.20.2
[root@Y nginx-1.20.2]# ll /opt/nginx/
total 0
drwxr-xr-x 2 root root 333 Apr 27 09:55 conf
drwxr-xr-x 2 root root 40 Apr 27 09:55 html
drwxr-xr-x 2 root root 6 Apr 27 09:55 logs
drwxr-xr-x 2 root root 19 Apr 27 09:55 sbin

## 系统命令为什么可以直接执行?
因为在环境变量中,有个PATH,只要是PATH所有目录下的可执行程序,都可以直接执行,不需要
写绝对路径
[root@Y nginx-1.20.2]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/.local/bin:/root/bin

# 9.添加nginx的环境变量,让nginx程序可以直接运行
[root@Y opt]# vim /etc/profile.d/nginx.sh
export PATH="$PATH:/opt/nginx/sbin"

# 10.加载环境变量
[root@Y opt]# source /etc/profile

# 11.启动nginx
[root@Y ~]# nginx

# 12.检查nginx是否启动成功(端口)
[root@Y ~]# netstat -lntup|grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
31407/nginx: master

[root@Y ~]# netstat -lntup

#13.检查nginx进程
[root@Y ~]# ps -ef|grep nginx
root 1194 1 0 21:47 ? 00:00:00 nginx: master process nginx
nobody 1195 1194 0 21:47 ? 00:00:00 nginx: worker process
root 1197 1170 0 21:47 pts/0 00:00:00 grep --color=auto nginx

[root@Y ~]# ps -ef|grep nginx|grep -v 'grep'
root 1194 1 0 21:47 ? 00:00:00 nginx: master process nginx
nobody 1195 1194 0 21:47 ? 00:00:00 nginx: worker process

[root@Y ~]# ps -ef|grep [n]ginx
root 1194 1 0 21:47 ? 00:00:00 nginx: master process nginx
nobody 1195 1194 0 21:47 ? 00:00:00 nginx: worker process

# 14.关闭防火墙
[root@Y ~]# systemctl stop firewalld

# 15.关闭selinux
[root@Y ~]# setenforce 0

打开浏览器访问:http://10.0.0.100(自己的IP地址)

源码安装及定制rpm包_源码包_04

nginx网页

# 站点目录
[root@Y html]# pwd
/opt/nginx/html

# 代码文件
[root@Y html]# vim index.html