一 使用RPM工具管理RPM包
需要考虑:
- OS版本,e.g. Centos6/7 cat /etc/redhat-release
- 系统架构,e.g. i386/x86_64 uname -m
- 依赖关系,e.g. ntfs-3g-devel 需要依赖ntfs-3g
- rpm包的版本, e.g. 2015/2017
==安装
rpm -ivh local_path //local_path本地路径
rpm -ivh url_path //url_path地址链接
[root@localhost ~]# rpm -ivh ntfs-3g-2017.3.23-1.el7.x86_64.rpm //套件名,-i安装
[root@localhost ~]# rpm -ivh zip-3.0-11.el7.x86_64.rpm
[root@localhost ~]# rpm -Uvh ntfs-3g-2017.3.23-1.el7.x86_64.rpm //套件名,-U更新
[root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
参数解释:
额外选项: --nosignature //不检验软件包的签名
--force //强制安装软件包
yum reinstall --nodeps //忽略依赖关系
软件卸载
#rpm -e 软件名称
--force 在安装的时候用(强制覆盖安装)
--nodeps 在卸载的时候用(卸载的时候不检查依赖关系)
RPM包安装信息存储到本地RPM数据库中。。。
==查询
(从本地的rpm数据库)
[root@localhost ~]# yum -y install httpd
[root@localhost yum.repos.d]# rpm -q httpd //查询指定包是否安装
[root@localhost ~]# rpm -qa|grep httpd
httpd-tools-2.4.6-90.el7.centos.x86_64
httpd-2.4.6-90.el7.centos.x86_64
[root@localhost ~]# rpm -ql httpd //查询ntfs-3g安装的文件
[root@localhost ~]# rpm -qf /var/www/html //查询该文件属于哪个rpm包
[root@localhost ~]# rpm -qi httpd //查询包的信息
[root@localhost ~]# rpm -qc httpd //查询某个包安装的配置文件
[root@localhost ~]# rpm -qd httpd //查安装的帮助文档
==卸载
[root@localhost ~]# rpm -e httpd
[root@localhost ~]# rpm -e httpd --nodeps !!!!!!!!!!!!!!不检测依赖关系 直接卸载
案例3:安装如下软件包 vsftpd samba nfs-utils httpd dhcp postfix mysql-server php lftp dos2unix unix2dos tigervnc
[root@localhost Packages]# pwd
/media/cd/Packages
[root@localhost Packages]# rpm -ivh samba-3.0.33-3.37.el5.i386.rpm samba-common-3.0.33-3.37.el5.i386.rpm
rpm工具管理软件包总结:
1. 很难解决包依赖关系
2. 如果某个文件没有,很难知道它由哪个rpm包提供,例如 semanage 或 tree 命令是由哪个包提供?
二 yum方式管理
制作本地yum源:
首先需要挂载镜像
[root@localhost ~]# mkdir /mnt/centos7u3
[root@localhost ~]# mount 镜像.iso /mnt/centos7u3
[root@localhost ~]# rm -rf /etc/yum.repos.d/* //直接删除,不建议操作,建议使用修改名称
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost ~]# mv CentOS.Base.repo CentOS.Base.repo.bak
[root@localhost ~]# vim /etc/yum.repos.d/CentOS.Base.repo
[centos7u3] //yum源区别名称,用来区分其他的yum源
name=centos7u3 //yum源描述 yum源名字
baseurl=file:///mnt/cenos7u3 //指定本地yum源的路径
enabled=1 //是否使用此yum源(1为打开,0为关闭)
gpgcheck=0 //检查软件
yum方式配置及使用
可以自动解决rpm软件依赖关系
分类:本地yum和远程yum
本地yum:
file://
远程yum:
http://
ftp://
yum源:提供软件仓库
挂载镜像到本地目录/mnt/rhel6u4
#mount -o loop /rhel6u4.iso /mnt/rhel6u4 (rhel6)
#mount /centos7u3.iso /mnt/centos7u3 (rhel7)
特殊LOOP解析来自菜鸟: 将 /tmp/image.iso 这个光碟的 image 档使用 loop 模式挂在 /mnt/cdrom之下。用这种方法可以将一般网络上可以找到的 Linux 光 碟 ISO 档在不烧录成光碟的情况下检视其内容。
#mount -o loop /tmp/image.iso /mnt/cdrom
如果是虚拟机,把iso镜像放到虚拟机的光驱里面去,开机连接即可
#mount /dev/cdrom /mnt/centos7u3
清理yum缓存:
# yum clean all
缓存软件包信息:
提高搜索/安装软件的速度
# yum makecache
查询yum源信息:
# yum repolist
查找软件:
# yum search mysql
此命令会搜索到系统已经安装和yum源里没有安装的软件信息,可以用他简单测试yum是否好用
查看软件依赖性关系:
# yum deplist httpd
查看文件属于哪个软件
# yum provides rz
查看系统已经安装好的软件和没有安装的软件(源里存在即可查到):
# yum list
查看系统已经安装好的软件组和没有安装的软件组(源里存在即可查到):
# yum grouplist
查看软件组包含的具体软件:
# yum groupinfo '软件组名称'
安装软件组:
# yum groupinstall ‘软件组名称’
如果软件或者软件组名称内有空格,要给空格转义或者加引号
安装软件:
# yum install 软件名称
# yum install mysql mysql-server -y //-y跳过确认提示直接安装
重装:
# yum reinstall 软件名
卸载软件:
# yum erase mysql-server
# yum remove mysql-server
# yum -y remove mysql-server
打开Yum缓存功能:安装完软件之后,软件不会被删除(默认安装完之后,不会保留安装包)
# vim /etc/yum.conf 修改下面参数的值为1,软件会被保存到cachedir指定的目录下
keepcache=1
# find / -name httpd-2.4.6-90.el7.centos.x86_64.rpm
自己制作yum源
# mkdir /myyum (把rpm安装包放到此目录里面)
# cp -rf /mnt/yum/Packages/* /myyum/
把想用yum安装的软件包拷贝到目录下
# createrepo /myyum //此目录就可以作为yum源了
# vim /etc/yum.repos.d/my.repo
[name]
name=qf
baseurl=file:///myyum
enabled=1
gpgcheck=0
yum排错:
1.yum配置文件必须以.repo结尾
2.yum.conf里面8,9行的值设置成0
3.配置文件关键字错误
4.检查yum源是否存在
5.baseurl路径是否正确
6.镜像大小是否正确
7.当有Yum进程存在的时,无法同时再打开一个Yum进程
三 源码包管理
获得源码包途径 官方网站,可以获得最新的软件包
Apache: www.apache.org
Nginx: www.nginx.org
安装源码包
准备工作(去Nginx官网下载Nginx软件的源码包)
1.编译环境如编译器gcc、make (yum源先准备好)
yum -y install gcc make zlib-devel pcre pcre-devel openssl-devel
//编译环境的准备
gcc是编译工具,编译单个文件
make工具可以看成是一个智能的批处理工具,通过调用makefile文件中用户指定的命令来进行编译和链接的。
pcre支持正则表达式
zlib-devel,有些应用依赖于这个库才能正常运行,因此需要安装zlib-devel
openssl-devel 这个就是包含了头文件,头文件参考,某些库文件等跟开发相关的东西。
2. 准备软件 nginx-1.16.0.tar.gz
3. 部署安装Nginx软件服务
nginx模块介绍: --enable -so 支持动态模块 --enable -modules=all 全部支持动态模块 --enable -ssl 支持https 安全链接useradd www
# tar -xvzf nginx-1.16.0.tar.gz
# cd nginx-1.16.0
写入到脚本里
# ./configure \
> --user=www \
> --group=www \
> --prefix=/usr/local/nginx \
> --with-http_stub_status_module \
> --with-http_sub_module \
> --with-http_ssl_module \
> --with-pcre
# make //编译文件
# make install //安装文件
# /usr/local/nginx/sbin/nginx //启动nginx服务器
# systemctl stop firewalld //关闭防火墙
# setenforce 0
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sCMTbXR6-1598086440029)(assets/1578106435968.png)]
详解源码安装三步曲
# ./configure
a. 指定安装路径,例如 --prefix=/usr/local/nginx
b. 启用或禁用某项功能, 例如 --enable-ssl, --disable-filter --with-http_ssl_module
c. 和其它软件关联,例如--with-pcre
d. 检查安装环境,例如是否有编译器gcc,是否满足软件的依赖需求 最终生成:Makefile
make //按Makefile文件编译
make install //按Makefile定义的文件路径安装
四 源码安装错误(企业案例):
错误1: ./configure: error: the HTTP gzip module requires the **zlib** library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option.
解决方案:
# yum -y install zlib-devel
错误2: ./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.
解决方案: # yum -y install openssl-devel
错误3: checking for C compiler ... not found ./configure: error: C compiler cc is not found
解决方案: # yum -y install gcc gcc-c++ make
错误4: ./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.
解决方案: # yum -y install pcre-devel
Nginx作为web服务器,中文内容显示乱码
在配置文件中添加一行
charset utf-8,gbk;
安装源码的技巧:
README
INSTALL
实例安装:httpd-2.2.11.tar.bz2
1.下载软件
2.解压
# tar xvjf httpd-2.2.11.tar.bz2 -C /usr/src
3.cd 到解压目录
# cd /usr/src/httpd-2.2.11/
4.配置
# ./configure --prefix=/usr/local/apache2
5.编译
# make
6.安装
# make install
启动:
#cd /usr/local/apache2/bin
#./apachectl start
访问:
#firefox http://172.16.70.251
五 局域网yum源制作(企业案例)
操作系统:centos7.4
资源: CentOS-7-x86_64-DVD-1708.iso镜像
实验服务器两台:
10.10.7.169 (作为vsftpd服务端)
10.10.7.170 (客户端)
首先测试两台主机可否ping通
在10.10.7.169上操作
[root@localhost ~]# ping 10.10.7.170
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
在10.10.7.170上操作:
[root@localhost ~]# ping 10.10.7.169
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
如果ping通继续下面操作
如果不同,检测两台虚拟机只用的网络模式是否统一(桥接orNAT),修改为统一网络模式重启虚拟机
在10.10.7.169上操作
将CentOS-7-x86_64-DVD-1708.iso 上传到/opt目录下
[root@localhost ~]# mkdir /opt/yum-iso
[root@localhost ~]# mount /opt/CentOS-7-x86_64-DVD-1708.iso /opt/yum-iso
[root@localhost ~]# yum -y install vsftpd
[root@localhost ~]# cp –a /opt/yum-iso/* /var/ftp/pub/
[root@localhost ~]# cd /var/ftp/
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# createrepo pub
[root@localhost yum.repos.d]# cat myselfYum.repo
[ftpYum]
name=ftpYum
baseurl=file:///opt/yum-iso
enabled=1
gpgcheck=0
[root@youngfit ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
name qf 3,894
repolist: 3,894
在10.10.7.170上操作:
[root@server2 ~]# cd /etc/yum.repos.d/
[root@server2 ~]# vim my.repo
[ftpYum]
name=centos
baseurl=ftp://192.168.62.131/pub
enabled=1
gpgcheck=0
[root@server2 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
scpyum | 2.9 kB 00:00:00
scpyum/primary_db | 3.1 MB 00:00:00
Loading mirror speeds from cached hostfile
repo id repo name status
scpyum scpyum 3,894
repolist: 3,894
d/
[root@server2 ~]# vim my.repo
[ftpYum]
name=centos
baseurl=ftp://192.168.62.131/pub
enabled=1
gpgcheck=0
[root@server2 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
scpyum | 2.9 kB 00:00:00
scpyum/primary_db | 3.1 MB 00:00:00
Loading mirror speeds from cached hostfile
repo id repo name status
scpyum scpyum 3,894
repolist: 3,894