linux软件包管理

###修改中英⽂
export LC_ALL=en_US.UTF-8
export LC_ALL=zh_CN.UTF-8


###程序(软件)组成部分:
 ⼆进制程序 可执⾏命令
 库 .so⽂件
 配置⽂件 .conf
 帮助⽂件 readme /usr/share/man
 
 ###开源镜像站
http://mirrors.aliyun.com
http://mirrors.sohu.com
http://mirrors.sohu.com/centos/7.5.1804/os/x86_64/Packages/
http://mirrors.163.com

###epel,提供centos众多额外的第三⽅包,可信任的第三⽅软件包组织
http://mirrors.sohu.com/fedora-epel/7/x86_64/Packages/
https://mirrors.aliyun.com/epel/7/x86_64/Packages/m

###搜索引擎
http://www.rpmfind.net/linux/mageia/distrib/7/x86_64/media/core/


###rpm命令
rpm命令:rpm [OPTIONS] [PACKAGE_FILE]
# i表示安装 v显示详细过程 h以进度条显示,每个#表示2%进度
安装软件的命令格式 rpm -ivh filename.rpm 
升级软件的命令格式 rpm -Uvh filename.rpm
卸载软件的命令格式 rpm -e filename.rpm
查询软件描述信息的命令格式 rpm -qpi filename.rpm
列出软件⽂件信息的命令格式 rpm -qpl filename.rpm
查询⽂件属于哪个 RPM 的命令格式 rpm -qf filename
###常用
rpm -qa 简单信息
rpm -ql 详细信息
rpm -qi 存放目录

### 本地yum客户端
/etc/yum.conf #为所有仓库提供公共配置
[root@chaogelinux yum.repos.d]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0 #本地缓存是否保留,
debuglevel=2 #调试⽇志级别
logfile=/var/log/yum.log #⽇志路径
exactarch=1 #精确系统平台版本匹
obsoletes=1 
gpgcheck=1 #检查软件包的合法性
plugins=1 
installonly_limit=5 #同时安装⼏个⼯具包
bugtracker_url=http://bugs.centos.org/set_project.php?project_id
distroverpkg=centos-release 
# This is the default, if you make this bigger yum won't see if
# is newer on the remote and so you'll "gain" the bandwidth of n
# download the new metadata and "pay" for it by yum not having c
# information.
# It is esp. important, to have correct metadata, for distribut
# Fedora which don't keep old packages around. If you don't like
# interupting your command line usage, it's much better to have 
# manually check the metadata once an hour (yum-updatesd will do
# metadata_expire=90m
#请放置你的仓库在这⾥,并且命名为*.repo类型
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

### yum仓库
/etc/yum.repos.d/*.repo #提供仓库的地址⽂件
CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com #仓库⽂
failovermethod=priority #存在多个url的时候,按顺序来连接,如果是r
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearc
 http://mirrors.aliyuncs.com/centos/$releasever/os/$basea
 http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/
gpgcheck=1 #是否检测秘钥
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 
#released updates 指定rpm包需要升级的地址,此处可以去⽹⻚上寻找对应
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$ba
 http://mirrors.aliyuncs.com/centos/$releasever/updates/$
 http://mirrors.cloud.aliyuncs.com/centos/$releasever/upd
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
epel.conf
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1 #是否启⽤此仓库
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

###⾃定义⼀个简单的repo⽂件
[base]
name=Chaoge repo 
baseurl=http://chaoge.com/centos/7/os/x86_64/
gpgcheck=0
[epel]
name=Chaoge epel repo
baseurl=http://chaoge.com/epel/7/os/x86_64/
gpgcheck=0

###配置yum源
http://mirrors.163.com/
https://opsx.alibaba.com/mirrors
http://mirrors.sohu.com/

1.备份现有repo仓库
2.下载新的repo⽂件
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.
3.清空旧yum缓存,⽣成新的缓存
yum clean all
yum makecache
4.针对阿⾥云镜像,可能出现⽆法解析地址的异常
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.
5.配置epel源
epel(RHEL 7)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/rep
epel(RHEL 6)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/rep
epel(RHEL 5)

###yum命令

yum命令的⽤法:
 yum [options] [command] [package ...]
 command is one of:
 * install package1 [package2] [...]
 * update [package1] [package2] [...]
 * update-to [package1] [package2] [...]
 * check-update
 * upgrade [package1] [package2] [...]
 * upgrade-to [package1] [package2] [...]
 * distribution-synchronization [package1] [package2] [...]
 * remove | erase package1 [package2] [...]
 * list [...]
 * info [...]
 * provides | whatprovides feature1 [feature2] [...]
 * clean [ packages | metadata | expire-cache | rpmdb | plugi
 * makecache
 * groupinstall group1 [group2] [...]
 * groupupdate group1 [group2] [...]
 * grouplist [hidden] [groupwildcard] [...]
 * groupremove group1 [group2] [...]
 * groupinfo group1 [...]
 * search string1 [string2] [...]
 * shell [filename]
 * resolvedep dep1 [dep2] [...]
 * localinstall rpmfile1 [rpmfile2] [...]
 (maintained for legacy reasons only - use install)
 * localupdate rpmfile1 [rpmfile2] [...]
 (maintained for legacy reasons only - use update)
 * reinstall package1 [package2] [...]
 * downgrade package1 [package2] [...]
 * deplist package1 [package2] [...]
 * repolist [all|enabled|disabled]
 * version [ all | installed | available | group-* | nogroups
 * history [info|list|packages-list|packages-info|summary|add
 * check
 * help [command]
显示仓库列表:
 repolist [all|enabled|disabled]
显示程序包:
 list
 # yum list [all | glob_exp1] [glob_exp2] [...]
 # yum list {available|installed|updates} [glob_exp1] [..
安装程序包:
 install package1 [package2] [...]
cpu
562
 reinstall package1 [package2] [...] (重新安装)
升级程序包:
 update [package1] [package2] [...]
 downgrade package1 [package2] [...] (降级)
检查可⽤升级:
 check-update
卸载程序包:
 remove | erase package1 [package2] [...]
查看程序包information:
 info [...]
查看指定的特性(可以是某⽂件)是由哪个程序包所提供:
 provides | whatprovides feature1 [feature2] [...]
清理本地缓存:
clean [headers|packages|metadata|dbcache|plugins|expire-cache|al
构建缓存:
 makecache
搜索:
 search string1 [string2] [...]
 以指定的关键字搜索程序包名及summary信息;
查看指定包所依赖的capabilities:
 deplist package1 [package2] [...]
查看yum事务历史:
 history [info|list|packages-list|packages-info|summary|addon
安装及升级本地程序包:
 * localinstall rpmfile1 [rpmfile2] [...]
 (maintained for legacy reasons only - use install)
 * localupdate rpmfile1 [rpmfile2] [...]
 (maintained for legacy reasons only - use update)
包组管理的相关命令:
 * groupinstall group1 [group2] [...]
 * groupupdate group1 [group2] [...]
 * grouplist [hidden] [groupwildcard] [...]
 * groupremove group1 [group2] [...]
 * groupinfo group1 [...]
如何使⽤光盘当作本地yum仓库:
 (1) 挂载光盘⾄某⽬录,例如/media/cdrom
 # mount -r -t iso9660 /dev/cdrom /media/cdrom
 (2) 创建配置⽂件
 [CentOS7]
 name=
 baseurl=
 gpgcheck=
 enabled=
yum的命令⾏选项:
 --nogpgcheck:禁⽌进⾏gpg check;
 -y: ⾃动回答为“yes”;
 -q:静默模式;
 --disablerepo=repoidglob:临时禁⽤此处指定的repo;
 --enablerepo=repoidglob:临时启⽤此处指定的repo;
 --noplugins:禁⽤所有插件;
yum的repo配置⽂件中可⽤的变量:
 $releasever: 当前OS的发⾏版的主版本号;
 $arch: 平台;
 $basearch:基础平台;
 $YUM0-$YUM9
[base]
name=Chaoge repo 
baseurl=http://chaoge.com/centos/7/os/x86_64/ #使⽤变量替换,就很
baseurl=http://chaoge.com/centos/6/os/x86_64/
baseurl=http://chaoge.com/centos/5/os/x86_64/
gpgcheck=0

### 源码安装
###前提条件:准备好开发⼯具以及开发环境

开发⼯具:gcc make等
开发组件:
yum groupinstall "Development Tools"
yum groupinstall "Server Platform Development
###第⼀曲,执⾏脚本 configure ⽂件
./configure --prefix=软件安装路径
针对C、C++代码,进⾏编译安装,需要指定配置⽂件`Makefile`,需要通过`co
通过选项传递参数,指定启⽤特性、安装路径等<执⾏时会⽣成makefile
检查依赖到的外部环境
###第⼆曲,执⾏make命令
make是Linux开发套件⾥⾯⾃动化编译的⼀个控制程序,他通过借助 Makefile 
make这⼀步就是编译,⼤多数的源代码包都经过这⼀步进⾏编译(当然有些perl
make 的作⽤是开始进⾏源代码编译,以及⼀些功能的提供,这些功能由他的 Ma
###第三曲:开始安装 make install
开始安装软件到./configure指定的安装路径

###检查环境变量,需要⼿动配置nginx的PATH路径,否则必须绝对路径才能找到
编辑⽂件/etc/profile.d/nginx.sh
写⼊export PATH=/opt/ngx112/sbin:$PATH


###环境变量配置⽂件
/etc/profile
⽤于设置系统级的环境变量和启动程序,在这个⽂件下配置会对所有⽤户⽣效。当
~/.profile
每个⽤户都可使⽤该⽂件输⼊专⽤于⾃⼰使⽤的shell信息,当⽤户登录时,该⽂件
~/.bashrc
该⽂件包含专⽤于你的bash shell的bash信息,当登录时以及每次打开新的shel
~/.bash_logout
当每次退出系统(退出bash shell)时,执⾏该⽂件,通常存放清理⼯作的命令。
执⾏顺序
登陆shell
登陆shell时,⾸先执⾏/etc/profile,之后执⾏⽤户⽬录下的~/.profile,~/

posted @ 2023-04-26 09:07  Bre-eZe  阅读(17)  评论(0)    收藏  举报