一、目录/usr/local
作用:编译安装的软件默认存放的位置,存放用户的数据或者软件
第三方软件(绿色软件)安装默认存放的位置
绿色软件:打开既用 不需要安装
二、软件的安装方式:
安装方式三种:
- yum安装
可以自动解决依赖关系,可以配置多个资源仓库
- rpm安装
安装rpm包时,如有关系依赖包,需要自己去解决依赖关
- 编译安装
可以指定安装路径,根据自己需求进行定制
三、yum安装
yum命令使用语法
语法结构:
yum install #软件名(安装软件)
yum remove #软件名(移除该软件以及相应的关系依赖包,谨慎使用,会导致其他命令也用不了)
yum update #(全新更新)
yum reinstall #软件名(重新安装)
yum list #(查看所有的软件)
yum search #软件名(查看该软件是否安装)
yum info #软件名(查看该软件信息)
yum repolist all #(查询哪些源可以使用,哪些是禁用的)
yum provides #命令名(查询某个命令是通过哪个软件安装的)没必要可以直接百度
yum clean all #(清空缓存)
yum makecache #(将安装包进行缓存)
案例:
yum -y remove net-tools weget 删除多个软件
[root@pjp ~]# yum -y remove net-tools bind-tools
[root@pjp ~]# nslookup
-bash: nslookup: 未找到命令
[root@pjp ~]# ifconfig
-bash: /usr/sbin/ifconfig: 没有那个文件或目录
yun -y install 软件名称
yum -y install ntpdate
#案例:时间同步
[root@pjp ~]# yum -y install ntpdate --安装时钟同步命令
[root@pjp ~]# ntpdate ntp1.aliyun.com --采用阿里云的时间同步服务器
1 Mar 22:08:49 ntpdate[1911]: step time server 120.25.115.20 offset 0.911374 sec
yun -y install 名称1 名称2
[root@pjp ~]# yum -y install net-tools bind-utils
使用 provides 查看已经安装命令所在工具包
[root@pjp ~]# yum -y provides ifconfig
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
源 :@base
匹配来源:
文件名 :/usr/sbin/ifconfig
扩展知识:yum只下载不安装
下载插件:
[root@oldboyedu ~]# yum install yum-plugin-downloadonly
下载软件 (下载好的就存放在缓存之下,注意需开启缓存):
yum install --downloadonly 软件名
yum重要文件
yum配置文件:/etc/yum.conf
仓库配置文件目录:/etc/yum.repos.d
repo文件是yum找到安装安装镜像的位置,可以自己配置
yum的缓存目录:/var/cache/yum
yum的日志文件:/var/log/yum.log
yum安装的特点:
yum支持自动解决依赖问题
安装的时候知道软件名称即可
无法安装软件排错:
检查仓库是否有问题
仓库配置问题
仓库缓存问题 (yum celan all 清空缓存)
网络问题(仓库在国外,由于网络延迟无法安装)
软件包的名称错误
yum命令问题 yum -y install
软件包损坏 yum -y reinstall 包名称 (覆盖安装)
YUM仓库优化(设置阿里云为默认yum源和添加增强源)
阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (aliyun.com)
设置阿里云为默认yum源
查看yum源
#yum repolist --查看当前yum仓库信息
[root@oldboyedu ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
源标识 源名称 状态
!base/7/x86_64 CentOS-7 - Base 10,072
!extras/7/x86_64 CentOS-7 - Extras 515
!updates/7/x86_64 CentOS-7 - Updates 4,706
repolist: 15,293
备份中央仓库yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
下载阿里云yum源
curl-o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
wget-O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#到这yum源设置已经成功了,可以使用yum repolist查看yum仓库信息
[root@oldboyedu ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
源标识 源名称 状态
!base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
!extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 515
!updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 4,706
repolist: 15,293
yun仓库增强源(epl)
作用:相当于另一个仓库,对中央仓库的补充
下载安装epl增强源
wget-O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
查看yum源信息,看是否成功
[root@oldboyedu ~]# yum repolist
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): epel/x86_64/group_gz | 99 kB 00:00:00
(2/4): epel/x86_64/updateinfo | 1.0 MB 00:00:07
(3/4): epel/x86_64/primary_db | 7.0 MB 00:00:37
(4/4): updates/7/x86_64/primary_db | 19 MB 00:01:08
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7- x86_64 13,747
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 515
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 4,724
repolist: 29,058
四、rpm安装
由Red Hat公司提出,被众多Linux发行版所采用,建立统一的数据文件,详细记录软件包的安装,卸载等变化信息,能够自动分析软件包的依赖关系
Rpmfind mirror
语法结构:
rpm -ivh 软件包名称.rpm
参数选项:
i install # 安装
v verbose # 显示安装过程
h #显示安装进度
#查询未安装的RPM包文件
格式:rpm -qp[ 子选项 ] RPM包文件
用法:结合不同的子选项完成不同的查询
-qpi:通过查询.rpm包文件查看该软件的详细信息
-qpl:查看.rpm安装包内所包含的目录,文件列表
-qpc:查看.rpm安装包包含的配置文件列表
-qpd:查看.rpm安装包内文档文件列表
#安装或升级RPM包
格式:rpm [ 选项 ] RPM包文件
用法:不同选项适用于不同的情况
-i: 安装一个新的rpm软件包
-U:升级某个rpm软件,若原本未安装,则进行安装
-F:更新某个rpm软件,若原本未安装,则放弃安装
7、卸载指定的RPM软件
格式:rpm -e 软件名
也可以用yum -y remove 软件名
RPM数据库:/var/lib/rpm目录下
故障原因非正常的关机、误删运行中的程序文件RPM数据文件被误写或删除当RPM数据库被删除时,需要进行数据库重建格式:rpm --rebuildddb 或者 rpm --initdb
特点:
不支持自动解决依赖(手动解决依赖问题,缺什么,用yum安装什么)
安装的rpm包必须提前下载
安装时注意路径问题
自动解决依赖: yum -y localinstall *.rpm
五、编译安装
二进制安装:已经编译好的,解压就能用,节省了编译的过程
编译安装三部曲:
./configure
make
make install
一键安装编译部署nginx的脚本
#!/bin/bash
# 解决依赖关系
yum install gcc pcre-devel openssl-devel -y
# 下载nginx安装包
curl-O http://nginx.org/download/nginx-1.19.2.tar.gz
# 解压
tar -xf nginx-1.19.2.tar.gz
# 建立一个用户
useradd mynginx
echo"123456" |passwd mynginx --stdin
cd nginx-1.19.2
# 编译前的配置
./configure --prefix=/usr/local/nginx --user=mynginx --group=mynginx --with-threads--with-http_ssl_module--with-http_realip_module--with-stream --with-http_stub_status_module
# 编译和编译安装
make && make install
# 修改环境变量PATH
echo"PATH=$PATH:/usr/local/nginx/sbin" >> /etc/bashrc
# 关闭防火墙和selinux
service firewalld stop
systemctl disable firewalld
setenforce 0
sed-i'/^SELINUX/ s/enforcing/disabled' /etc/sysconfig/selinux
# 开启nginx服务
nginx