青岛实训 7月16号 day07

一、yum源配置

1.将yum.repos.d中的 .repo文件删除

rm  -rf /etc/yum.repos.d/*.repo

2.配置编辑本地镜像文件

3.实现自动挂载

二、配置华为云镜像

1.打开华为云开源镜像站(https://mirrors.huaweicloud.com/home),找到对应的操作系统版本的.repo 文件链接(如:https://repo.huaweicloud.com/repository/conf/centos7.repo )。

进入服务器的 /etc/yum.repos.d/ 目录,可以执行以下命令下载并编辑.repo 文件:

cd /etc/yum.repos.d/
 
vi local.repo
按 i 键进入编辑模式,输入以下内容(注意将 $releasever 替换成实际的操作系统版本号):

#centos-base.repo
 
#
 
# The mirror system uses the connecting IP address of the client and the
 
# update status of each mirror to pick mirrors that are updated to and
 
# geographically close to the client. You should use this for CentOS updates
 
# unless you are manually picking other mirrors.
 
#
 
# If the mirrorlist= does not work for you, as a fallback you can try the
 
# remarked out baseurl= line instead.
 
#
 
#
 
​
 
(base)
 
name=centos7
 
baseurl=https://repo.huaweicloud.com/centos/$releasever/os/$basearch/
 
gpgcheck=0
 
# released updates
 
(updates)
 
name=centos-$releasever-updates-repo.huaweicloud.com
 
baseurl=https://repo.huaweicloud.com/centos/$releasever/updates/$basearch/
 
# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
 
gpgcheck=1
 
gpgkey=https://repo.huaweicloud.com/centos/rpm-gpg-key-centos-7
 
# additional packages that may be useful
 
(extras)
 
name=centos-$releasever-extras-repo.huaweicloud.com
 
baseurl=https://repo.huaweicloud.com/centos/$releasever/extras/$basearch/
 
# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
 
gpgcheck=1
 
gpgkey=https://repo.huaweicloud.com/centos/rpm-gpg-key-centos-7
 
# additional packages that extend functionality of existing packages
 
(centosplus)
 
name=centos-$releasever-plus-repo.huaweicloud.com
 
baseurl=https://repo.huaweicloud.com/centos/$releasever/centosplus/$basearch/
 
# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus

编辑完成后,按 Esc 键,输入 :wq 保存并退出。

执行以下命令更新 Yum 源:

yum clean all:清除原有缓存。

yum makecache:构建新的缓存。

2.配置本地 Yum 源

挂载 ISO 镜像文件(假设镜像文件已上传至服务器):

创建挂载点:mkdir /opt/centos。

挂载镜像:mount /your_iso_file_path /opt/centos (将 /your_iso_file_path 替换为实际的镜像文件路径)。

进入 /etc/yum.repos.d/ 目录,备份原有的.repo 文件(以防需要恢复):mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/old/ 。

创建并编辑本地 Yum 源配置文件:

vi /etc/yum.repos.d/local.repo
输入以下内容:

(centos)
 
name=centos # Yum 源的名称,可自定义
 
baseurl=file:///opt/centos # 本地 Yum 源的位置,指向挂载点目录
 
gpgcheck=0 # 不进行 GPG 签名检查
 
enabled=1 # 启用该 Yum 源
编辑完成后保存并退出。

执行 yum clean all 命令清空缓存。

执行 yum makecache 命令重建缓存。

配置完成后,就可以使用 Yum 命令来安装、更新软件包了。

3.配置局域网 Yum 源(需要至少两台服务器,一台作为源服务器,其他机器作为客户端):

配置局域网 Yum 源(服务器端)

按照上述本地 Yum 源的配置方法,在源服务器上完成本地 Yum 源的配置。

安装并启动 HTTP 服务(如 Apache HTTP Server 或 Nginx 等),将挂载的 ISO 镜像目录通过 HTTP 服务共享出去。

配置客户端机器的 Yum 源:

编辑 /etc/yum.repos.d/ 目录下的.repo 文件,添加类似以下内容:

(centos)
 
name=centos
 
baseurl=http://源服务器 IP/共享目录 # 替换为实际的源服务器 IP 和共享目录
 
gpgcheck=0
 
enabled=1


然后在客户端机器上执行 yum clean all 和 yum makecache 命令更新缓存。

常见的一些网络 Yum 源有阿里云、华为云、网易等提供的开源镜像站点。例如,阿里云的 CentOS 7 yum 源地址为:http://mirrors.aliyun.com/repo/centos-7.repo 。

配置本地yum源

rpm -ivh xxx //rpm需要手动添加依赖

能够使用yum工具安装软件包

yum不止执行安装,还可以自动处理依赖关系

yum是基于rpm的,相当于rpm升级版,自动解决依赖关系

ls -l /etc/yum.repos.d/ //查看现有的yum仓库镜像

(1)打包,做成一个tar压缩包

 yum repolist all
 tar -czvf /etc/yum.repos.d/bak.tar.gz /etc/yum.repos.d/*
 rm -rf /etc/yum.repos.d/*.repo
 ls -l /etc/yum.repos.d/
 yum repolist all
 yum clean all //清空缓存
 yum makecache //生成缓存
(2)删除mnt目录下的所有文件

rm -rf /mnt/*
 
ls /mnt/
(3)将光盘数据挂载到/mnt目录中,就可以在该目录中读取光盘内容

lsblk //找到sr0
 
mount -o ro /dev/sr0 /mnt //以只读方式挂载光盘
(4)设置开机自挂载

echo "mount -o ro /dev/sr0 /mnt" >> /etc/rc.local //开机自动挂载
(5)规定软件包查找位置

[root@1 ~]# vim /etc/yum.repos.d/hh.repo
 
[a]
 
name=a
 
baseurl=file:///mnt
 
gpgcheck=0
 
[root@1 ~]# yum clean all
 
已加载插件:fastestmirror
 
正在清理软件源: a
 
Cleaning up everything
 
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
 
Cleaning up list of fastest mirrors
 
[root@1 ~]# yum makecache
 
已加载插件:fastestmirror
 
Determining fastest mirrors
 
a | 3.6 kB 00:00:00
 
(1/4): a/group_gz | 166 kB 00:00:00
 
(2/4): a/primary_db | 5.9 MB 00:00:00
 
(3/4): a/filelists_db | 6.9 MB 00:00:00
 
(4/4): a/other_db | 2.5 MB 00:00:00

(3)epel源配置

对官⽅和官⽹源的扩展,有些软件找不到

 [root@1 ~]# yum -y install epel-release.noarch
 [root@1 ~]# ls /etc/yum.repos.d/
 CentOS-Base.repo epel.repo hh.repo.b
 CentOS-Base.repo.backup epel-testing.repo
 [root@1 ~]# yum -y install sl //安装小火车
 [root@1 ~]# sl

(4)nginx源配置

(1)移除epel源

 [root@1 ~]# rm -rf /etc/yum.repos.d/epel*
 [root@1 ~]# ls /etc/yum.repos.d/
 CentOS-Base.repo CentOS-Base.repo.backup hh.repo.b
 [root@1 ~]# yum clean all
 [root@1 ~]# yum makecache

(2)搜索nginx镜像

nginx news

[root@1 ~]# vim /etc/yum.repos.d/nginx.repo
 
[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 //启用模块热修复功能
 
[root@1 ~]# yum clean all
 
[root@1 ~]# yum makecache
 
[root@1 ~]# yum list | grep nginx
 
nginx.x86_64 1:1.26.1-2.el7.ngx nginx-stable
 
nginx-debug.x86_64 1:1.8.0-1.el7.ngx nginx-stable
 
nginx-debuginfo.x86_64 1:1.26.1-2.el7.ngx nginx-stable
 
nginx-module-geoip.x86_64 1:1.26.1-2.el7.ngx nginx-stable
 
nginx-module-geoip-debuginfo.x86_64 1:1.26.1-2.el7.ngx nginx-stable
 
nginx-module-image-filter.x86_64 1:1.26.1-2.el7.ngx nginx-stable
 
nginx-module-image-filter-debuginfo.x86_64 1:1.26.1-2.el7.ngx nginx-stable
 
nginx-module-njs.x86_64 1:1.26.1+0.8.5-2.el7.ngx nginx-stable
 
nginx-module-njs-debuginfo.x86_64 1:1.26.1+0.8.5-2.el7.ngx nginx-stable
 
nginx-module-perl.x86_64 1:1.26.1-2.el7.ngx nginx-stable
 
nginx-module-perl-debuginfo.x86_64 1:1.26.1-2.el7.ngx nginx-stable
 
nginx-module-xslt.x86_64 1:1.26.1-2.el7.ngx nginx-stable
 
nginx-module-xslt-debuginfo.x86_64 1:1.26.1-2.el7.ngx nginx-stable
 
nginx-nr-agent.noarch 2.0.0-12.el7.ngx nginx-stable
 
pcp-pmda-nginx.x86_64


 
[root@1 ~]# yum -y install nginx
 
[root@1 ~]# nginx //启动服务
 
[root@1 ~]# whereis nginx //查看指令
 
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
 
[root@1 ~]# curl http://localhost //访问服务器
 

<!DOCTYPE html>
 
<html>
 
<head>
 
<title>Welcome to nginx!</title>
 
<style>
 
html { color-scheme: light dark; }
 
body { width: 35em; margin: 0 auto;
 
font-family: Tahoma, Verdana, Arial, sans-serif; }
 
</style>
 
</head>
 
<body>
 
<h1>Welcome to nginx!</h1>
 
<p>If you see this page, the nginx web server is successfully installed and
 
working. Further configuration is required.</p>
 
​
 
<p>For online documentation and support please refer to
 
<a href="http://nginx.org/">nginx.org</a>.<br/>
 
Commercial support is available at
 
<a href="http://nginx.com/">nginx.com</a>.</p>
 
​
 
<p><em>Thank you for using nginx.</em></p>
 
</body>
 
</html>

(5)自建yum源仓库

[root@1 ~]# vim /etc/yum.conf
 
keepcache=1 //将0改为1 YUM 在下载软件包后保留其缓存
 
[root@1 ~]# yum remove -y nginx //卸载nginx
 
[root@1 ~]# yum -y install nginx //安装nginx
 
[root@1 ~]# find /var/cache/ -name "*nginx*" -type f //查看缓存文件
 
/var/cache/yum/x86_64/7/nginx-stable/packages/nginx-1.26.1-2.el7.ngx.x86_64.rpm
 
[root@1 ~]# yum install --downloadonly --downloaddir=./soft samba //只下载不安装
 
--downloadonly 选项表示只进行下载操作,不进行安装。
 
--downloaddir=./soft 则指定了下载的软件包保存的目录为当前目录下的 soft 文件夹。
 
......
 
总计 1.2 MB/s | 9.0 MB 00:00:07
 
exiting because "Download Only" specified
 
[root@1 ~]# ls soft/
 
avahi-libs-0.6.31-20.el7.x86_64.rpm pytalloc-2.1.16-1.el7.x86_64.rpm
 
cups-libs-1.6.3-52.el7_9.x86_64.rpm python-tdb-1.3.18-1.el7.x86_64.rpm
 
gnutls-3.3.29-9.el7_6.x86_64.rpm samba-4.10.16-25.el7_9.x86_64.rpm
 
libldb-1.5.4-2.el7.x86_64.rpm samba-client-libs-4.10.16-25.el7_9.x86_64.rpm
 
libtalloc-2.1.16-1.el7.x86_64.rpm samba-common-4.10.16-25.el7_9.noarch.rpm
 
libtdb-1.3.18-1.el7.x86_64.rpm samba-common-libs-4.10.16-25.el7_9.x86_64.rpm
 
libtevent-0.9.39-1.el7.x86_64.rpm samba-common-tools-4.10.16-25.el7_9.x86_64.rpm
 
libwbclient-4.10.16-25.el7_9.x86_64.rpm samba-libs-4.10.16-25.el7_9.x86_64.rpm
 
nettle-2.7.1-9.el7_9.x86_64.rpm trousers-0.3.14-2.el7.x86_64.rpm
 
pyldb-1.5.4-2.el7.x86_64.rpm

三、安装createrepo

yum -y install createrepo

createrepo soft/

vi /etc/yum.repos.d/soft.repo

[root@1 soft]# yum clean all
 
已加载插件:fastestmirror
 
正在清理软件源: extras nginx-stable os soft updates
 
Cleaning up everything
 
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
 
Cleaning up list of fastest mirrors
 
[root@1 soft]# yum makecache
 
[root@1 soft]# yum -y install samba //全程直接下载,使用我们自己创建的yum仓库

  • 10
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的C语言万年历的实训报告,供您参考: 一、实训目的 本次实训的主要目的是通过编写一个简单的C语言万年历程序,巩固C语言基本语法和编程思想,提高编程能力和解决问题的能力。 二、实训要求 1、能够使用C语言基本语法和控制语句编写程序。 2、能够使用数组来存储和操作数据。 3、能够使用函数来实现模块化编程。 4、能够使用指针来操作内存中的数据。 5、能够使用文件来读取和写入数据。 三、实训内容 1、程序功能 本程序实现了一个简单的万年历功能,可以通过输入年份和月份来显示该月的日历。 2、程序实现 以下是本程序的主要代码实现: ```c #include <stdio.h> // 判断是否为闰年 int is_leap_year(int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { return 1; } else { return 0; } } // 获取某个月份的总天数 int get_days(int year, int month) { int days[] = {31, 28 + is_leap_year(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; return days[month - 1]; } // 获取某个日期是星期几 int get_weekday(int year, int month, int day) { if (month == 1 || month == 2) { year--; month += 12; } int c = year / 100; int y = year % 100; int w = y + y / 4 + c / 4 - 2 * c + 26 * (month + 1) / 10 + day - 1; w = (w % 7 + 7) % 7; return w; } // 显示日历 void show_calendar(int year, int month) { int days = get_days(year, month); int weekday = get_weekday(year, month, 1); printf(" 日 一 二 三 四 五 六\n"); int i; for (i = 0; i < weekday; i++) { printf(" "); } for (i = 1; i <= days; i++) { printf("%2d ", i); if ((weekday + i) % 7 == 0) { printf("\n"); } } if ((weekday + days) % 7 != 0) { printf("\n"); } } int main() { int year, month; printf("请输入年份:"); scanf("%d", &year); printf("请输入月份:"); scanf("%d", &month); if (month < 1 || month > 12) { printf("月份输入错误!\n"); return 1; } printf(" %d年%d月\n", year, month); show_calendar(year, month); return 0; } ``` 四、实训总结 通过本次实训,我学会了如何使用C语言来编写一个简单的万年历程序,巩固了C语言基本语法和编程思想,加强了对函数、数组、指针、文件等概念和用法的理解,提高了编程能力和解决问题的能力。同时,我也意识到在编程过程中需要注重代码的规范、可读性和可维护性,这对于日后的开发工作非常重要。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值