源码安装及定制rpm包

[TOC]

linux中软件的安装方式

安装包

安装方式

rpm包

rpm,yum

源码包

源码安装

二进制包

解压既用

获取源码包

安装什么服务,就去什么服务的官方网站,下载源码包

linux安装源码包

​http://nginx.org/​

源码安装及定制rpm包_html

源码安装及定制rpm包_html_02

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

# 2.下载
[root@zxw <sub>]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
[root@zxw </sub>]# ll
total 1040
-rw-r--r--. 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz

# 3.解压
[root@zxw <sub>]# tar xf nginx-1.20.2.tar.gz
[root@zxw </sub>]# ll
total 1040
drwxr-xr-x. 8 1001 1001 158 Nov 16 22:44 nginx-1.20.2
-rw-r--r--. 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz

# 4.进入解压好的目录里
[root@zxw <sub>]# cd nginx-1.20.2
[root@zxw nginx-1.20.2]# ll
total 796
drwxr-xr-x. 6 1001 1001 4096 Apr 27 19:27 auto
-rw-r--r--. 1 1001 1001 312251 Nov 16 22:44 CHANGES
-rw-r--r--. 1 1001 1001 476577 Nov 16 22:44 CHANGES.ru
drwxr-xr-x. 2 1001 1001 168 Apr 27 19:27 conf
-rwxr-xr-x. 1 1001 1001 2590 Nov 16 22:44 configure
drwxr-xr-x. 4 1001 1001 72 Apr 27 19:27 contrib
drwxr-xr-x. 2 1001 1001 40 Apr 27 19:27 html
-rw-r--r--. 1 1001 1001 1397 Nov 16 22:44 LICENSE
drwxr-xr-x. 2 1001 1001 21 Apr 27 19:27 man
drwxr-xr-x. 2 root root 77 Apr 27 19:51 objs
-rw-r--r--. 1 1001 1001 49 Nov 16 22:44 README
drwxr-xr-x. 9 1001 1001 91 Apr 27 19:27 src


# 5.生成
./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module

[root@zxw nginx-1.20.2]# ./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module
checking for OS
+ Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

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

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

# 6.再执行
[root@zxw nginx-1.20.2]# ./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module

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

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

# 7.再执行
[root@zxw nginx-1.20.2]# ./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module

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


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

# 看到结尾是这玩意就算整好了
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"

# 8.好了以后会生成Makefile文件
[root@zxw nginx-1.20.2]# ll
total 796
drwxr-xr-x. 6 1001 1001 4096 Apr 27 20:42 auto
-rw-r--r--. 1 1001 1001 312251 Nov 16 22:44 CHANGES
-rw-r--r--. 1 1001 1001 476577 Nov 16 22:44 CHANGES.ru
drwxr-xr-x. 2 1001 1001 168 Apr 27 20:42 conf
-rwxr-xr-x. 1 1001 1001 2590 Nov 16 22:44 configure
drwxr-xr-x. 4 1001 1001 72 Apr 27 20:42 contrib
drwxr-xr-x. 2 1001 1001 40 Apr 27 20:42 html
-rw-r--r--. 1 1001 1001 1397 Nov 16 22:44 LICENSE
-rw-r--r--. 1 root root 442 Apr 27 20:49 Makefile
drwxr-xr-x. 2 1001 1001 21 Apr 27 20:42 man
drwxr-xr-x. 3 root root 174 Apr 27 20:50 objs
-rw-r--r--. 1 1001 1001 49 Nov 16 22:44 README
drwxr-xr-x. 9 1001 1001 91 Apr 27 20:42 src


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

# 9.5.安装(这玩意和编译一起做)
[root@zxw nginx-1.20.2]# make install
完事以后看看/opt有没有
[root@zxw nginx-1.20.2]# ll /opt/
total 0
drwxr-xr-x. 6 root root 54 Apr 27 20:53 nginx-1.20.2
[root@zxw nginx-1.20.2]# ll /opt/nginx-1.20.2/
total 4
drwxr-xr-x. 2 root root 4096 Apr 27 20:53 conf
drwxr-xr-x. 2 root root 40 Apr 27 20:53 html
drwxr-xr-x. 2 root root 6 Apr 27 20:53 logs
drwxr-xr-x. 2 root root 19 Apr 27 20:53 sbin

# 10.为了专业点,给他做个软连接
[root@zxw nginx-1.20.2]# ll /opt/
total 0
lrwxrwxrwx. 1 root root 18 Apr 27 20:57 nginx -> /opt/nginx-1.20.2/
drwxr-xr-x. 6 root root 54 Apr 27 20:53 nginx-1.20.2

# 11.系统命令为什么可以直接执行?
[root@zxw nginx-1.20.2]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

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

# 13.加载环境变量
[root@zxw nginx-1.20.2]# source /etc/profile
[root@zxw nginx-1.20.2]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/nginx/sbin

# 14.启动nginx
[root@zxw nginx-1.20.2]# nginx

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

# 16.检查nginx进程
[root@zxw </sub>]# ps -ef | grep nginx
root 19282 1 0 21:32 ? 00:00:00 nginx: master process nginx
nobody 19283 19282 0 21:32 ? 00:00:00 nginx: worker process
root 19313 1844 0 21:38 pts/0 00:00:00 grep --color=auto nginx
[root@zxw <sub>]# ps -ef|grep nginx|grep -v 'grep'
root 19282 1 0 21:32 ? 00:00:00 nginx: master process nginx
nobody 19283 19282 0 21:32 ? 00:00:00 nginx: worker process
[root@zxw </sub>]# ps -ef|grep [n]ginx
root 19282 1 0 21:32 ? 00:00:00 nginx: master process nginx
nobody 19283 19282 0 21:32 ? 00:00:00 nginx: worker process

# 17.关闭防火墙
[root@zxw <sub>]# systemctl stop firewalld
[root@zxw </sub>]# setenforce 0

访问​​http://10.0.0.105/​

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

nginx网页

# 站点目录
[root@zxw html]# pwd
/opt/nginx/html
[root@zxw html]# ll
total 8
-rw-r--r--. 1 root root 494 Apr 27 20:53 50x.html
-rw-r--r--. 1 root root 612 Apr 27 20:53 index.html

# 代码文件
vim index.html

尝试用nginx做yum仓库

[root@zxw ~]# cd /opt/nginx/conf/
[root@zxw conf]# ll
total 68
-rw-r--r--. 1 root root 1077 Apr 27 20:53 fastcgi.conf
-rw-r--r--. 1 root root 1077 Apr 27 20:53 fastcgi.conf.default
-rw-r--r--. 1 root root 1007 Apr 27 20:53 fastcgi_params
-rw-r--r--. 1 root root 1007 Apr 27 20:53 fastcgi_params.default
-rw-r--r--. 1 root root 2837 Apr 27 20:53 koi-utf
-rw-r--r--. 1 root root 2223 Apr 27 20:53 koi-win
-rw-r--r--. 1 root root 5231 Apr 27 20:53 mime.types
-rw-r--r--. 1 root root 5231 Apr 27 20:53 mime.types.default
-rw-r--r--. 1 root root 2656 Apr 27 20:53 nginx.conf
-rw-r--r--. 1 root root 2656 Apr 27 20:53 nginx.conf.default
-rw-r--r--. 1 root root 636 Apr 27 20:53 scgi_params
-rw-r--r--. 1 root root 636 Apr 27 20:53 scgi_params.default
-rw-r--r--. 1 root root 664 Apr 27 20:53 uwsgi_params
-rw-r--r--. 1 root root 664 Apr 27 20:53 uwsgi_params.default
-rw-r--r--. 1 root root 3610 Apr 27 20:53 win-utf
[root@zxw conf]# vi nginx.conf
# 太长了,只截取了要改的配置文件)

server {
listen 80;
server_name localhost;
location / {
root /data/yum_data/;
autoindex on;
access_log dff;
}
}

[root@zxw conf]# mkdir /data/yum_data -p(创建出目录)
然后重启下nginx
[root@zxw conf]# nginx -s reload
[root@zxw conf]# mkdir /data/yum_data/centos/7/os/x86_64/Packages/ -p
[root@zxw conf]# cd /data/yum_data/centos/7/os/x86_64/Packages/
[root@zxw Packages]# ll
total 0

随便复制一个包进去
[root@zxw Packages]# cp /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm .
[root@zxw Packages]# ll
total 48
-rw-r--r--. 1 root root 47508 Apr 27 22:36 tree-1.6.0-10.el7.x86_64.rpm

然后刷新看看看

然后把他做成一个仓库
[root@zxw Packages]# createrepo /data/yum_data/centos/7/os/x86_64/
Spawning worker 0 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

换到别的虚拟机
vim /etc/yum.repos.d/

把里面的baseurl=http://10.0.0.105/centos/$releasever/os/$basearch/Packages/这样写就ok了

源码安装及定制rpm包_html_04

源码安装及定制rpm包_html_05

源码安装及定制rpm包_html_06