Linux云计算【第一阶段】第十章:软件包管理及yum源配置

第十章:软件包管理及yum源配置【重点】

========================================================

一.使用RP工具管理RPM包

需要考虑关系:

  1. OS版本,e.g. Centos6/7 cat /etc/redhat-release
  2. 系统架构,e.g. i386/x86_64 uname -m
  3. 依赖关系,e.g. ntfs-3g-devel 需要依赖ntfs-3g
  4. rpm包的版本, e.g. 2015/2017

ps:软件安装与Windows系统操作一样,首先需要去网站下载相对应的软件,然后在电脑进行安装。
rpm
先下载需要的安装包,进行安装, 可能需要解决安装过程中的一些依赖问题
a 软件包a依赖 b c d ,先安装 b c d,然后安装a
相当于下载包安装软件

*可以下载rpm软件包的地方
https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/




1.软件包安装
[root@lxw0 ~]# yum -y install wget                                             //安装wget ,
[root@lxw0 ~]# wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/n/ntfs-3g-2017.3.23-11.el7.x86_64.rpm
[root@lxw0 ~]# rpm -ivh ntfs-3g-2017.3.23-1.el7.x86_64.rpm				       //软件套件名字

'额外选项: --nosignature   	//不检验软件包的签名      --force				//强制安装软件包 
yum reinstall --nodeps           //忽略依赖关系  '

[root@lxw0 ~]# rpm -q ntfs-3g					    //查询指定包是否安装
[root@lxw0 ~] rpm -qa |grep ntfs                    //列出所有已安装   rpm -qa |grep ntfs 
[root@lxw0 ~] rpm -ql ntfs -3g                      //列出安装过程都安装了那些文件 [命令 帮助文档 依赖库文件 配置文件]
[root@lxw0 ~] rpm -qf /usr//bin/ntfs-3g             ///查询该文件属于哪个rpm包
[root@lxw0 ~] rpm -qi ntfs-3g                       //查询改文件属于哪个rpm包
[root@lxw0 ~] rpm -qc ntfs-3g                       //查询某个安装包的配置文件
[root@lxw0 ~] rpm -qd vsftpd                        //查询安装的帮助文档
[root@lxw0 ~] rpm -e ntfs-3g                        //卸载安装包 
[root@lxw0 ~] rpm -e ntfs-3g --nodeps               //不检测依赖直接卸载

练习下载安装 vsftpd
找到现在页面 http://www.rpmfind.net/linux/rpm2html/search.php?query=vsftpd

找合适的发行版 合适的版本  然后下载包 http://www.rpmfind.net/linux/centos/7.8.2003/os/x86_64/Packages/vsftpd-3.0.2-27.el7.x86_64.rpm
        Centos     7.x  架构 x86_64
再到安装的机器上,执行 wget http://www.rpmfind.net/linux/centos/7.8.2003/os/x86_64/Packages/vsftpd-3.0.2-27.el7.x86_64.rpm
下载完成后执行  rpm -ivh  vsftpd-3.0.2-27.el7.x86_64.rpm

rpm工具管理软件包总结:
1. 很难解决包依赖关系 
2. 如果某个文件没有,很难知道它由哪个rpm包提供,例如 semanage 或 tree 命令是由哪个包提供?


==================================================================

二.yum方式安装管理

本地yum源:
实战演示:


1.本地yum源
首先需要挂载镜像   【虚拟机设置--cd---添加一个镜像】
[root@lxw0 ~] mkdir /mnt/centos7u3           //创建挂载目录
[root@lxw0 ~] mount /dev/cdrom /mnt/centos7u3      //挂载镜像
[root@lxw0 ~] mv  CentOS.Base.repo /tmp/CentOS.Base.repo.bak     //首先备份改名
[root@lxw0 ~] rm -rf /etc/yum.repos.d/*	          //删除本地仓库源
[root@lxw0 ~] 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 			//检查软件


2.yum方式配置及使用
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)


[root@lxw0 ~] yum clean all                  //清理yum缓存
[root@lxw0 ~] yum makecache                  //提高搜索/安装软件速度
[root@lxw0 ~] yum repolist                   //查询yum源信息
[root@lxw0 ~] yum search mysql               //查找mysql软件
[root@lxw0 ~] yum deplist httpd              //查找软件httpd依赖性关系
[root@lxw0 ~] yum provides rz                //查看rz属于哪个软件
[root@lxw0 ~] yum list	                     //查看系统已安装好的软件和没安装的软件
[root@lxw0 ~] yum grouplist                  //查看系统已经安装好的软件组和没有安装的软件组
[root@lxw0 ~] yum groupinfo                  //查看软件组包含的具体软件
[root@lxw0 ~] yum groupinstall '软件组名称'    //安装软件组,如果软件或者软件组名称内有空格,要给空格转义或者加引号

[root@lxw0 ~] yum install '软件名称'          //安装软件
[root@lxw0 ~] yum -y install mysql            //安装软件 -y 跳过确认直接安装 
[root@lxw0 ~] yum -y reinstall                //重新安装软件
[root@lxw0 ~] yum erase mysql-server          //卸载人软件    -y
[root@lxw0 ~] yum remove mysql-server         //卸载软件       -y

打开Yum缓存功能:安装完软件之后,软件不会被删除(默认安装完之后,不会保留安装包)
    # vim /etc/yum.conf  修改下面参数的值为1,软件会被保存到cachedir指定的目录下
    keepcache=1

自己制作yum源
	#mkdir /myyum
	把想用yum安装的软件包拷贝到目录下
	#createrepo /myyum         //此目录就可以作为yum源了。

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 -y install gcc make zlib-devel pcre pcre-devel openssl-devel
2. 准备软件 nginx-1.16.0.tar.gz
3. 部署Nginx


nginx模块介绍:    
--enable -so 支持动态模块                                                 
--enable -modules=all  全部支持动态模块   
--enable -ssl   支持https 安全链接

[root@lxw0 ~] wget http://nginx.org/download/nginx-1.14.2.tar.gz     //下载nginx源码包,从nginx.org下载
[root@lxw0 ~] yum -y install gcc make zlib-devel pcre pcre-devel openssl-devel                 //下载编译器  gcc  make [cmake]  
[root@lxw0 ~] useradd www                     //添加www用户
[root@lxw0 ~] tar xvf nginx-1.14.2.tar.gz             //解压nginx软件包
[root@lxw0 ~] cd nginx-1.14.2                         //进入nginx目录下
[root@lxw0 ~] ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_sub_module  --with-http_ssl_module --with-pcre       //配置nginx
[root@lxw0 ~] make  && make install                     //编译安装
[root@lxw0 ~] /usr/local/nginx/sbin/nginx	            //启动nginx服务器
[root@lxw0 ~] systemctl stop firewalld                   //关闭防火墙

ps:
详解源码安装三步曲 # ./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++ make183F33}


错误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源【重难点】

进行访问控制 主要使用于ssh
[root@lxw0 ~] cat /etc/hosts.allow //在/etc/hosts.allow配置文件中添加,允许登录,并记录日志
sshd:10.3.133.41
sshd:10.3.137.84

[root@lxw0 ~] cat /etc/hosts.deny //在/etc/hosts.deny配置文件中添加,拒绝登录,并记录日志
sshd:ALL
sshd:ALL

这两个文件相互配置,就设置了该台机器,仅允许 41 和 84两台机器进行ssh连接,其他均拒绝

所有的ssh链接都会记录在 /var/log/secure 日志文件里,所以可以使用下列命令得到下列信息

cat /var/log/secure |grep Accepted | awk ‘{print $11}’ |sort |uniq -c 每天建立ssh链接的ip和次数
cat /var/log/secure |grep refused |awk ‘{print $9}’ |sort |uniq -c 每天被拒绝的连接ip和链接次数


自建yum源:【重难点】
综合案例:建立YUM服务器
1. 提供基础软件包Base [光盘]
2. 提供update软件包
3. 提供其它软件包如nginx, zabbix, docker, hadoop, openstack

'
systemctl stop firewalld      //关闭防火墙[临时]
systemctl disable firewalld   //关闭防火墙[永久,但仅在下次重启后生效,本次不生效]
systemctl status firewalld    //查看防火墙状态  running 运行中  dead 防火墙已关闭


setenforce 0                  //关闭selinux[临时]       setenforce 1开启
vim /etc/selinux/config
修改 SELINUX=enforcing 为 SELINUX=disabled     //关闭selinux[永久,但仅在下次重启后生效,本次不生效]
getenforce                    //查看selinux状态 Enforcing 开启 Permissive 关闭 disabled关闭


iptables -nL                  //查看iptables策略
iptables -F                   //清空iptables策略
iptables -X                   //清空自定义链
iptables -Z                   //清空计数器
iptables-save                 //保存刚刚修改的策略

修改主机名,配置国内yum源,一键三连    固定ip'


一.本地yum源配置
需要有镜像,或者虚拟机挂载了镜像【/dev/cdrom】仅自己本机可使用

[root@lxw0 ~] mkdir /mnt/centos7u3                        //创建挂载目录
[root@lxw0 ~] mount /dev/chrom /mnt/centos7u3             //挂载镜像至centos7u3目录
[root@lxw0 ~] vim /etc/yum.repos.d/own.repo               //创建配置问津,配置本地源
[own-gz2003]                  
name=owngz2003                          
baseurl=file:///mnt/centos7u3           
enable=1


二、通过镜像自建yum源
可以相互通信的都可以用
1.开启防火墙,关闭selinux,一键三连,安装并开启ftp
[root@lxw0 ~] systemctl stop firewalld && systemctl disable firewalld             //关闭防火墙,并查看状态
[root@lxw0 ~] setenforce 0                    //关闭selinux
[root@lxw0 ~] iptables -F                     //清空iptables策略
[root@lxw0 ~] iptables -X                     //清空自定义链
[root@lxw0 ~] iptables -Z                     //清空计数器
[root@lxw0 ~] yum -y install vsftpd                 //安装ftp
[root@lxw0 ~] systemctl start vsftpd                //启动ftp
[root@lxw0 ~] ps -ef |grep vsftpd                   //查看ftp是否启动 systemctl status vsftpd,俩种方式查看启动

2.创建目录,挂载镜像
[root@lxw0 ~] mkdir /var/ftp/{centos6u8,centos7u3}     //创建挂载目录
[root@lxw0 ~] mount /dev/cdrom /var/ftp/centos7u3      //挂载镜像

3.客户端测试
[root@lxw0 ~] vim /etc/yum.repos.d/own-ftp.repo        //创建 yum配置文件
[own-ftp]
name=ftp
baseurl=ftp://10.3.133.181/centos7u3                  //必须要输入自己的ip地址
enable=1
gpgcheck=0


ps:怎么开启yum缓存  
vim /etc/yum.config
keepcache=1      //开启缓存  因为yum在安装包的时候,默认安装完成后删除安装包


三.通过网络源自建yum源
 1.配置所需的yum 源 [拿阿里base源测试]
   删除/etc/yum.repo.d 下所有repo
   仅配置base 和 epel
ps:步骤是在于以上俩步的铺垫而来,首先删除/etc/yum.repo.d 下所有repo
   仅配置base 和 epel,而后去阿里云下载镜像文件,来进行测试。

2.downloadonly
[root@lxw0 ~] yum -y install nginx --downloadonly  
[root@lxw0 ~] mkdir /var/ftp/nginx         //创建nginx目录
[root@lxw0 ~] find /var/cache/yum/x86_64/7/ -iname "*.rpm" -exec cp -rf {} /var/ftp/nginx/ \;

3.进行makerepo
[root@lxw0 ~] createrepo /var/ftp/nginx         //进行makerepo,如无法进行,请先将/etc/yum.repos.d/own.repo和own-ftp.repo俩个配置文件先mv移动至root下,在执行以上命令,执行完成后再移动至/etc/yum.repos.d/目录下

4.客户端配置测试
[root@lxw0 ~] vim /etc/yum.repos.d/nginx-own.repo
[own-nginx]
name=own-nginx
baseurl=ftp://10.3.133.181/nginx
enable=1
gpgcheck=0

配置完成后,可直接在网页输入10.3.133.181即可浏览网络共享配置源,或者ftp
:10.3.133.181,若无法进入,则执行以下命令:
[root@lxw0 ~] systemctl stop firewalld          //关闭防火墙
[root@lxw0 ~] setenforce 0                       //关闭selinux
[root@lxw0 ~] iptables -F                        //清空iptables策略
刷新网页输入自己ip地址即可进入,客户端测试必须输入自己的ip地址。




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值