ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

day23 rpm与编译安装

2021-10-28 18:33:54  阅读:193  来源: 互联网

标签:opt 00 nginx rpm day23 repo 编译 yum root


rpm命令安装nginx

安装nginx步骤

rpm -ivh nginx-1.18.0-1.el7.ngx.x86_64.rpm 通过nginx下载包来安装

​ -i 是install安装的简写、

​ -v 显示详细安装过程信息

​ -h 显示安装的进度条

rpm -qc nginx 查询nginx安装位置信息

​ -q 是query 查询的意思

​ -c configfiles 配置文件意思,列出所有配置文件

记住关键文件

​ /etc/nginx/conf.d/default.conf #主配置文件

​ /etc/nginx/nginx.conf #子配置文件

rpm -ql nginx nginx在你系统所有的操作信息都查询出来

​ -q 是query的查询

​ -l 是list列表意思,即列出软件包中的文件

记住关键文件

/etc/nginx/conf.d/default.conf

/etc/nginx/nginx.conf

/etc/sysconfig/nginx

/usr/sbin/nginx #执行命令

/usr/share/nginx/html #代码目录自己写的网页

/var/log/nginx #日志目录

启动服务——了解

systemctl start nginx #启动nginx

iptables -F #关闭防火墙

打开谷歌浏览器 输入ip地址10.0.0.100

发现显示不出内容

可以执行以下内容,刷新浏览器内容即可

[root@centos7-100 ~]# systemctl start nginx 
[root@centos7-100 ~]# iptables -F
[root@centos7-100 ~]# echo zhaocheng >/usr/share/nginx/html/index.html

安装完检查:

浏览器输入:10.0.0.100

卸载:

rpm -e nginx 卸载nginx

rpm -evh nginx 详细显示卸载过程

yum命令安装nginx

yum安装优缺点:

1.yum 安装可以从仓库下载常用软件,不需要知道准确的软件包全称

2.yum安装可以自动解决依赖问题

3.必须要联网(外网)

yum源概念:

1.基础base源和拓展epel源

2.第三方源,nginx,zabbix

3.yum源文件是以*.repo结尾,放在/etc/yum.repos.d/*.repo

常用yum源地址

http://mirrors.aliyun.com/repo/
https://mirrors.tuna.tsinghua.edu.cn/
https://mirrors.tuna.tsinghua.edu.cn/help/centos/
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

yum常用命令:

1.进入yum源目录

cd /etc/yum.repos.d/ #cd 进入这个目录

查看base与epel源

[root@centos7-100 ~]# cd /etc/yum.repos.d/
[root@centos7-100 yum.repos.d]# ls
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo  CentOS-x86_64-kernel.repo
[root@centos7-100 yum.repos.d]# vim CentOS-Base.repo

联网手动更新yum缓存

yum makecache fast

下载阿里源并指定文件名保存

wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

wget -O epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

在这个CentOS-Base.repo文件找到查找这个aliyuncs关键词,d是删除这个关键词的全部行

sed -i '/aliyuncs/d' CentOS-Base.repo 用vim也可以删除但是很麻烦,可以用这个命令一步解决

2.更新yum缓存

yum makecache fast #更新yum缓存相当于更新菜品一样

yum常用命令

yum search nginx #查看当前目录仓库有nginx的包

yum list |grep "nginx" #查询软件列表包含nginx关键字的软件

yum install nginx -y #yum安装nginx -y不用手动确认

查看已经安装的nginx 详细信息

yum info nginx

[root@centos7-100 yum.repos.d]# yum info nginx
已加载插件:fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安装的软件包
名称    :nginx
架构    :x86_64
时期       :1
版本    :1.20.1
发布    :2.el7
大小    :1.7 M
源    :installed
来自源:epel
简介    : A high performance web server and reverse proxy server
网址    :https://nginx.org
协议    : BSD
描述    : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
         : IMAP protocols, with a strong focus on high concurrency, performance and low
         : memory usage.

配置第三方源,nginx官网源地址

https://nginx.org/en/linux_packages.html

选择稳定版本

选择系统版本是RHEL/CentOS

RHEL/CentOS
Install the prerequisites:

sudo yum install yum-utils
To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:

sudo yum-config-manager --enable nginx-mainline
To install nginx, run the following command:

sudo yum install nginx
When prompted to accept the GPG key, verify that the fingerprint matches 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62, and if so, accept it.

使用cat 新建一个第三方源储存在nginx.repo中

 #加单引号''是让系统不要考虑太多里面特殊符号,不要转义特殊符号

cat >/etc/yum.repos.d/nginx.repo << 'EOF'         
[nginx-stable]                                      
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF 

使用ll命令查看/etc/yum.repos.d/目录nginx源

[root@centos7-100 yum.repos.d]# ll
总用量 48
-rw-r--r--. 1 root root 2523 12月 26 2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 4月   8 2020 CentOS-CR.repo
-rw-r--r--. 1 root root  649 4月   8 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 4月   8 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 4月   8 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 4月   8 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 7577 4月   8 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 4月   8 2020 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root  664 12月 26 2020 epel-7.repo
-rw-r--r--. 1 root root  664 12月 26 2020 epel.repo
-rw-r--r--. 1 root root  436 10月  5 11:39 nginx.repo

使用yum makecache fast 更新行加入的第三方源,可以跟新软件目录

[root@centos7-100 yum.repos.d]# yum makecache fast
已加载插件:fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                    | 3.6 kB  00:00:00     
epel                                                                                                                                                                    | 4.7 kB  00:00:00     
extras                                                                                                                                                                  | 2.9 kB  00:00:00     
nginx-stable                                                                                                                                                            | 2.9 kB  00:00:00     
updates                                                                                                                                                                 | 2.9 kB  00:00:00     
nginx-stable/7/x86_64/primary_db                                                                                                                                        |  67 kB  00:00:00     
元数据缓存已建立

再使用yum info nginx命令查看nginx最新版本

第一步我先卸载nginx软件

yum remove nginx

第二步更第三方源软件目录


[root@centos7-100 yum.repos.d]# yum makecache fast 
已加载插件:fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                    | 3.6 kB  00:00:00     
epel                                                                                                                                                                    | 4.7 kB  00:00:00     
extras                                                                                                                                                                  | 2.9 kB  00:00:00     
nginx-stable                                                                                                                                                            | 2.9 kB  00:00:00     
updates                                                                                                                                                                 | 2.9 kB  00:00:00     
元数据缓存已建立

第三步查看可以安装的最新版本

[root@centos7-100 yum.repos.d]# yum info nginx
已加载插件:fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
可安装的软件包
名称    :nginx
架构    :x86_64
时期       :1
版本    :1.20.1
发布    :2.el7
大小    :586 k
源    :epel/x86_64
简介    : A high performance web server and reverse proxy server
网址    :https://nginx.org
协议    : BSD
描述    : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
         : IMAP protocols, with a strong focus on high concurrency, performance and low
         : memory usage.

yum安装命令

yum install nginx -y

查看安装的nginx版本

nginx -v 
[root@centos7-100 yum.repos.d]# nginx -v
nginx version: nginx/1.20.1

仅下载不安装

yum install --downloadonly --downloaddir=/opt/ nginx #只下载不安装,并且指定下载目录到/opt/中

卸载软件

yum remove nginx  卸载完成后,配置文件不会删除,日志也不会删除。 

源码包编译安装

源码包编译介绍

编码包指的是开发者写好的源代码,但是还不能直接使用,需要编译后才能变成可执行的命令。

源码编译安装相比于rpm来说,具有几点优势:

1.可以看到源码,如果有能力可以二次开发

2.可以自己定制安装路径,运行用户等功能

缺点:
安装配置比较复杂,标准化难以实施。

编译安装步骤:

下载源代码
./configure
make
make install
/opt/nginx/sbin/nginx -t                    检查语法
/opt/nginx/sbin/nginx              
/opt/nginx/sbin/nginx -s reload
/opt/nginx/sbin/nginx -s stop 

编译安装步骤:

创建www用户和www组
groupadd www -g 1000
useradd  www -s /sbin/nologin -M -u 1000 -g 1000

安装依赖包

yum install openssl-devel pcre-devel gcc -y

下载解压源码包

mkdir /data/soft -p                    #创建一个存放软件的目录
cd /data/soft/
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar zxvf nginx-1.18.0.tar.gz

配置编译参数

cd nginx-1.18.0                      #加\反斜杠是告诉系统命令还没有执行完,只是另起第二行好看
./configure --help                # --help查看帮助信息
./configure \
--user=www \
--group=www \
--prefix=/opt/nginx-1.19.9/ \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre

编译安装

make && make install
安装完成后,在opt目录下面会新创建一个nginx-1.19.9
[root@centos7-100 opt]# ls
nginx-1.19.9  others  owner

创建软连接

ln -s /opt/nginx-1.19.9/ /opt/nginx
ls -l /opt/nginx                      #查看软连接详细信息
[root@centos7-100 opt]# ls -l /opt/nginx
lrwxrwxrwx. 1 root root 18 10月  5 13:39 /opt/nginx -> /opt/nginx-1.19.9/

检查语法

[root@centos7-100 opt]# /opt/nginx/sbin/nginx -t
nginx: the configuration file /opt/nginx-1.19.9//conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx-1.19.9//conf/nginx.conf test is successful

启动服务

[root@centos7-100 opt]# /opt/nginx/sbin/nginx 
[root@centos7-100 opt]# 

查看nginx版本

[root@centos7-100 opt]# /opt/nginx/sbin/nginx -v
nginx version: nginx/1.18.0

检查服务

curl 127.0.0.1

标签:opt,00,nginx,rpm,day23,repo,编译,yum,root
来源: https://www.cnblogs.com/zhaocheng690/p/15477101.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有