首页 > 编程语言 >源码安装

源码安装

时间:2022-10-08 19:12:49浏览次数:50  
标签:opt root nginx 源码 yum 1.20 安装 localhost

目录

源码安装

Linux中软件的安装方式

安装包 安装方式
rpm包 rpm,yum
源码包 源码安装
二进制包 解压即用

Linux获取源码包

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

1651043357630

1651043423099

# 1.nginx官网,下载源码包
[root@localhost ~]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
[root@localhost ~]# ll
total 1044
-rw-r--r--. 1 root root 1062124 Nov 16 22:51 nginx-1.20.2.tar.gz

# 2.解压
[root@localhost ~]# tar xf nginx-1.20.2.tar.gz

# 3.生成(在当前目录下)
[root@localhost ~/nginx-1.20.2]# ./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module
./ 执行      --prefix 安装路径           --with 要使用的功能

# 报错解决:
# 报错一
./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 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. 
报错原因:缺少pcre库文件 解决方法:yum install -y pcre-devel 

# 报错三
./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

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

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

# 6.安装
[root@localhost nginx-1.20.2]# make install

# 7.做软链接 
[root@localhost nginx-1.20.2]# ln -s /opt/nginx-1.20.2/ /opt/nginx 
[root@localhost ~/nginx-1.20.2]# ll /opt/nginx
lrwxrwxrwx. 1 root root 18 Apr 27 17:05 /opt/nginx -> /opt/nginx-1.20.2/
[root@localhost ~/nginx-1.20.2]# ll /opt/nginx/
total 4
drwxr-xr-x. 2 root root 4096 Apr 27 17:04 conf    # 配置文件目录
drwxr-xr-x. 2 root root   40 Apr 27 17:04 html    # 站点目录(代码存放目录)
drwxr-xr-x. 2 root root    6 Apr 27 17:04 logs    # 日志目录
drwxr-xr-x. 2 root root   19 Apr 27 17:04 sbin    # 可执行程序目录


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


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

# 免交互设置环境变量
[root@localhost ~]# echo 'PATH="/opt/nginx/sbin:$PATH"' > /etc/profile.d/nginx.sh


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

# 10.启动nginx
[root@localhost ~]# nginx

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

[root@localhost ~]# netstat -lntup

# 12.检查nginx进程
[root@localhost ~]# ps -ef|grep nginx 

# 13.关闭防火墙
[root@localhost ~]# systemctl stop firewalld

# 14.关闭selinux
[root@localhost ~]# setenforce 0    # 临时关闭selinux

[root@localhost ~]# vim /etc/sysconfig/selinux
SELINUX=enforcing 改成SELINUX=disabled   # 重启之后,则永久关闭

nginx网页

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

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

1651050790534

nginx做成源

# 1.编辑配置文件
[root@localhost /opt/nginx/html]# cd /opt/nginx/conf/
[root@localhost /opt/nginx/conf]# vi nginx.conf
#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}


http {
   include       mime.types;
   default_type  application/octet-stream;
   sendfile        on;
   keepalive_timeout  65;
   server {
       listen       80;
       server_name  localhost;

       location / {
          root   html;
          autoindex on;
       }
   }
}

# 2.检测nginx配置文件语法
[root@localhost ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

# 3.重启nginx
[root@localhost /opt/nginx/conf]# nginx -s reload 

# 4.创建目录
[root@localhost ~]# mkdir -p /data/yum_data/centos/7/os/x86_64/Packages/

# 5.拷贝rpm包到目录下
[root@localhost /data/yum_data/centos/7/os/x86_64/Packages]# cp /mnt/Packages/*.rpm  ./

# 6.把目录变成仓库
[root@localhost /data/yum_data/centos/7/os/x86_64]# createrepo /data/yum_data/centos/7/os/x86_64/Packages
Spawning worker 0 with 4070 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

# 7.编辑其它机器.repo配置
[root@localhost ~]# gzip -r /etc/yum.repos.d
[root@localhost ~]# vi /etc/yum.repos.d/lzayuan.repo

# 8.使用yum安装
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
[root@localhost ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id     repo name                  status
lza_yuan    Local Repository By lza    enabled: 4,070
repolist: 4,070

[root@localhost ~]# yum install -y tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================
 Package Arch      Version         Repository   Size
=====================================================
Installing:
 tree    x86_64    1.6.0-10.el7    lza_yuan     46 k

Transaction Summary
=====================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm    |  46 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : tree-1.6.0-10.el7.x86_64          1/1 
  Verifying  : tree-1.6.0-10.el7.x86_64          1/1 

Installed:
  tree.x86_64 0:1.6.0-10.el7                         

Complete!

1651057885858

标签:opt,root,nginx,源码,yum,1.20,安装,localhost
From: https://www.cnblogs.com/LZA1218/p/16769920.html

相关文章