前言
这是最近学习的第一个服务,在此跟大家进行分享,如有错误及不足之处,希望大家能够留言,谢谢!
基础环境:server :centos 8 client :centos 8
yum应用环境
yum服务是Redhat公司发行的一种包管理工具,是rpm的前端程序,可在多个程序间定位软件包,
解决安装rpm包时出现的相关依赖问题,一般用于局域网服务搭建。
原理
基于Client/Server架构,现在服务器搭建yum仓库-yum repository,将事先准备好的rpm包及其元数据上传到repository目录下,yum客户端利用自有yum工具从repository中的元数据进行下载安装,查询包之间的依赖关系,并进行下载安装。
前置操作
- 关闭防火墙:关闭之后进行防火墙状态查看结果
临时关闭:systemctl stop firewalld;
永久关闭:systemctl disable firewalld;
状态查看:systemctl status firewalld;
临时关闭防火墙
[root@Centos8 ~ 13:44:59]systemctl stop firewalld
[root@Centos8 ~ 13:44:59]#systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sun 2021-04-11 13:44:32 CST; 36s ago
Docs: man:firewalld(1)
Process: 1263 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 1263 (code=exited, status=0/SUCCESS)
永久关闭防火墙
[root@Centos8 ~ 13:46:45]#systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
对防火墙熟悉的朋友可以直接在策略里开放已经配置好的端口即可,我就不在这里赘述了。
2. 关闭selinux
[root@Centos8 ~ 13:51:27]#vim /etc/selinux/config
1
2 # This file controls the state of SELinux on the system.
3 # SELINUX= can take one of these three values:
4 # enforcing - SELinux security policy is enforced.
5 # permissive - SELinux prints warnings instead of enforcing.
6 # disabled - No SELinux policy is loaded.
7 SELINUX=disabled
8 # SELINUXTYPE= can take one of these three values:
9 # targeted - Targeted processes are protected,
10 # minimum - Modification of targeted policy. Only selected processes are protected.
11 # mls - Multi Level Security protection.
12 SELINUXTYPE=targeted
不熟练的朋友还是建议直接vim操作,这样清楚直观,也不会改错;熟练的朋友可以用sed等文本编辑工具进行操作。
yum服务搭建
一、首先是yum服务器(server)部署:
- 挂载个光盘到mnt目录
挂载并进行结果查看
[root@Centos8 ~ 13:54:15]#mount /dev/sr0 /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@Centos8 ~ 13:54:53]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 4G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sr0 11:0 1 7G 0 rom /mnt
- 服务器端安装http服务
我的已经安装过了,就给大家演示一下命令。
[root@Centos8 ~ 11:45:19]#yum install httpd
Last metadata expiration check: 1:21:32 ago on Sun 11 Apr 2021 12:37:55 PM CST.
Package httpd-2.4.37-30.module_el8.3.0+561+97fdbbcc.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
需要修改端口的,切换至conf目录修改默认的80端口
[root@Centos8 ~ 13:59:28]#cd /etc/httpd/conf
[root@Centos8 /etc/httpd/conf 14:01:12]#ls
httpd.conf magic
[root@Centos8 /etc/httpd/conf 14:01:13]#vim httpd.conf
38 # ports, instead of the default. See also the <VirtualHost>
39 # directive.:
40 #
41 # Change this to Listen on specific IP addresses as shown below to
42 # prevent Apache from glomming onto all bound IP addresses.
43 #
44 #Listen 12.34.56.78:80
45 Listen 80
修改之后保存即可。
3. 创建目标文件夹,为拷贝文件做准备。
我这里没有做版本区分,可以分版本创建
[root@Centos8 /var/www/html 14:04:40]#mkdir -p /var/www/html/centos/{7,8}/
[root@Centos8 /var/www/html 14:07:42]#ls
Apache centos Haproxy JDK Nginx package rpm包 Tomcat Weblogic 部署-2018-04-11.chm
- 从光盘拷贝文件到目录
由于包文件比较大,所需时间较长,希望大家可以合理安排时间。
[root@Centos8 /var/www/html/centos/8 14:10:56]#cp -a /mnt/* /var/www/html/centos/8
[root@Centos8 /var/www/html/centos/8 14:15:03]#ls
AppStream BaseOS EFI images isolinux media.repo TRANS.TBL
- 开启http服务:
systemctl start httpd 临时开启服务
systemctl enable httpd 设置服务开机启动
[root@Centos8 /var/www/html/centos/8 14:18:58]#systemctl start httpd
[root@Centos8 /var/www/html/centos/8 14:19:15]#systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2021-04-11 11:28:33 CST; 2h 50min ago
Docs: man:httpd.service(8)
Main PID: 1404 (httpd)
Status: "Total requests: 2; Idle/Busy workers 100/0;Requests/sec: 0.000195; Bytes served/sec: 0 B/sec"
Tasks: 213 (limit: 11266)
Memory: 23.0M
CGroup: /system.slice/httpd.service
├─1404 /usr/sbin/httpd -DFOREGROUND
├─1979 /usr/sbin/httpd -DFOREGROUND
├─1981 /usr/sbin/httpd -DFOREGROUND
├─1982 /usr/sbin/httpd -DFOREGROUND
└─1983 /usr/sbin/httpd -DFOREGROUND
Apr 11 11:28:23 Centos8 systemd[1]: Starting The Apache HTTP Server...
Apr 11 11:28:33 Centos8 httpd[1404]: AH00558: httpd: Could not reliably determine the server's fully qualified dom>
Apr 11 11:28:33 Centos8 systemd[1]: Started The Apache HTTP Server.
Apr 11 11:28:33 Centos8 httpd[1404]: Server configured, listening on: port 80
最后显示的就是http服务的默认端口,如果服务启动后有报错,根据报错日志进行排除。
6. 本机浏览器进行访问
为啥就可以直接访问了,因为我们把文件拷贝到了httpd.conf的默认目录里了,所以就可以直接访问了。
二、客户端(client) 文件配置
7. 切换至yum仓库目录
先创建bak文件夹,备份系统默认仓库到bak文件夹
[root@centOS8 ~ 14:25:49]#cd /etc/yum.repos.d
[root@centOS8 /etc/yum.repos.d 14:25:57]#ls
repo.bak test.repo
- 用vim写一个repo格式的文件
[root@centOS8 /etc/yum.repos.d 14:25:58]#vim test.repo
1 [BaseOS]
2 name=BaseOS
3 baseurl=http://10.0.0.151/centos/8/BaseOS
4 gpgcheck=0
5 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosoffical
6
7 [AppStream]
8 name=AppStream
9 baseurl=http://10.0.0.151/centos/8/AppStream
10 gpgcheck=0
11 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosoffical
保存退出即可
配置文件里面IP保证客户端(client)可以访问,这里我没有用yum的函数,熟练的朋友就直接用函数吧,文件夹路径要正确无误,一个字母和标点也不要有,以免浪费时间。我当时就多了一个字母,老半天找不到问题。
接下来就是检查网络是否畅通,看来网络通畅,没有丢包。
[root@centOS8 /etc/yum.repos.d 14:31:28]#ping -c10 10.0.0.151
PING 10.0.0.151 (10.0.0.151) 56(84) bytes of data.
64 bytes from 10.0.0.151: icmp_seq=1 ttl=64 time=0.540 ms
64 bytes from 10.0.0.151: icmp_seq=2 ttl=64 time=0.441 ms
64 bytes from 10.0.0.151: icmp_seq=3 ttl=64 time=0.467 ms
64 bytes from 10.0.0.151: icmp_seq=4 ttl=64 time=0.655 ms
64 bytes from 10.0.0.151: icmp_seq=5 ttl=64 time=0.576 ms
64 bytes from 10.0.0.151: icmp_seq=6 ttl=64 time=2.70 ms
64 bytes from 10.0.0.151: icmp_seq=7 ttl=64 time=2.87 ms
64 bytes from 10.0.0.151: icmp_seq=8 ttl=64 time=3.46 ms
64 bytes from 10.0.0.151: icmp_seq=9 ttl=64 time=2.76 ms
64 bytes from 10.0.0.151: icmp_seq=10 ttl=64 time=0.541 ms
--- 10.0.0.151 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 134ms
rtt min/avg/max/mdev = 0.441/1.500/3.457/1.196 ms
- 清除之前的yum缓存,重新构建缓存
[root@centOS8 /etc/yum.repos.d 14:31:55]#yum clean all
13 files removed
[root@centOS8 /etc/yum.repos.d 14:34:39]#yum makecache
BaseOS 16 MB/s | 2.2 MB 00:00
AppStream 30 MB/s | 5.4 MB 00:00
Metadata cache created.
- yum源检查
[root@centOS8 /etc/yum.repos.d 14:36:17]#yum repolist
repo id repo name
AppStream AppStream
BaseOS BaseOS
- 接下来就可以直接使用配置好的yum服务了
我安装一个memcached服务,以后也会用到,大家先提前认识一下。
[root@centOS8 /etc/yum.repos.d 14:38:40]#yum install memcached.x86_64
Last metadata expiration check: 0:02:23 ago on Sun 11 Apr 2021 02:39:28 PM CST.
Dependencies resolved.
===================================================================================================================
Package Architecture Version Repository Size
===================================================================================================================
Installing:
memcached x86_64 1.5.9-2.el8 AppStream 132 k
Transaction Summary
===================================================================================================================
Install 1 Package
Total download size: 132 k
Installed size: 282 k
Downloading Packages:
memcached-1.5.9-2.el8.x86_64.rpm 3.8 MB/s | 132 kB 00:00
-------------------------------------------------------------------------------------------------------------------
Total 3.6 MB/s | 132 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: memcached-1.5.9-2.el8.x86_64 1/1
Installing : memcached-1.5.9-2.el8.x86_64 1/1
Running scriptlet: memcached-1.5.9-2.el8.x86_64 1/1
Verifying : memcached-1.5.9-2.el8.x86_64 1/1
Installed:
memcached-1.5.9-2.el8.x86_64
Complete!
- 卸载已经安装的memcached服务
[root@centOS8 /etc/yum.repos.d 14:42:45]#yum remove memcached.x86_64
Dependencies resolved.
===================================================================================================================
Package Architecture Version Repository Size
===================================================================================================================
Removing:
memcached x86_64 1.5.9-2.el8 @AppStream 282 k
Transaction Summary
===================================================================================================================
Remove 1 Package
Freed space: 282 k
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: memcached-1.5.9-2.el8.x86_64 1/1
Erasing : memcached-1.5.9-2.el8.x86_64 1/1
Running scriptlet: memcached-1.5.9-2.el8.x86_64 1/1
Verifying : memcached-1.5.9-2.el8.x86_64 1/1
Removed:
memcached-1.5.9-2.el8.x86_64
Complete!
至此,本地yum服务就部署完了,如有不足之处,还请大家能够及时留言,有时间就会回复,谢谢!