第二次作业

配置Redhat9系统:NTP时间同步与SSH免密登录,
文章详细介绍了如何在两台Redhat9虚拟机上配置NTP服务,确保客户端与服务主机时间同步,以及如何设置SSH免密登录,允许客户端通过公钥验证方式远程连接服务端。

作业内容

1.配置ntp时间服务器,确保客户端主机能和服务主机同步时间

2.配置ssh免密登陆,能够通过客户端主机通过redhat用户和服务端主机基于公钥验证方式进行远程连接

一,ntp的时间同步
使用2台Redhat 9 虚拟机

服务器端 IP192.168.124.131   主机名 [root@Server~]

客户端 IP 192.168.124.130   主机名  [root@localhost ~]

  前置操作首先保证时区一致
 

date  这里时区都是CST
systemctl stop firewalld    关闭防火墙
setenforce 0                关闭seLiuex

1.安装软件包

 检查是否安装

[root@server root2]# rpm -qa | grep chron
 

未安装时:

先挂载 [root@server root2]# mount /dev/sr0 /mnt
再安装 [root@server root2]# yum install chrony -y

2.服务器和客户端的配置

服务器
[root@server~]# vim /etc/chrony.conf  对其配置文件进行编辑
修改如下内容
#pool 2.rhel.pool.ntp.org iburst  服务器端不需要向上层同步时间
allow 192.168.124.0/24    允许客户端向本服务器同步时间
local stratum 10  定义本地主机时间服务器在第10层级    15以内保证偏差在1-50ms 
[root@server ~]# systemctl  restart chronyd  重启软件以加载配置
客户端
[root@localhost ~]# vim /etc/chrony.conf
 
修改如下内容
pool 192.168.124.131  iburst  从该服务器处同步时间
 
[root@localhost ~]# systemctl restart chronyd  重启chronyd 服务

3.测试

[root@sever ~]# date 111110102022.20
Fri Nov 11 10:10:20 CST 2022     
[root@sever ~]# systemctl restart chronyd
 
[root@localhost ~]# date
sun Apr 16 07:24:00 CST 2023

二、配置ssh免密登陆,能够客户端主机通过普通用户和服务端主机基于公钥验证方式进行远程连接

1.保证opensshrsync两个服务的安装

使用命令

rpm -qa | grep openssh
rpm -qa | grep rsync
 

如果未下载则可使用如下方式 ,分别获取两个服务

rpm -i openssh-2.1.1p4-1.i386.rpm 
yum -y install rsync   

 2.客户端生成密钥

[root@server ~]# ssh-keygen 
[shasha@server ~]# ssh-keygen

 三.发送到指定目录

[shasha@node1 root]$ 
[shasha@node1 root]$ ssh-copy-id root@192.168.124.131
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/redhat/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.38.128's password: 
 
Number of key(s) added: 1
 
Now try logging into the machine, with:   "ssh 'root@192.168.124.130'"
and check to make sure that only the key(s) you wanted were added.

四.客户端测试

 
[t1@node1 root]$ ssh root@192.168.124.131
Activate the web console with: systemctl enable --now cockpit.socket
 
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Sun Apr 18 19:58:18 2023 from 192.168.124.131

Python 第二次作业中涉及了多个知识点,包括基础的循环结构、数学问题的编程实现,以及函数的应用等。以下是对部分作业内容和解答的详细说明: 1. **斐波那契数列的打印** 作业中有一个题目要求使用 `for` 循环来打印斐波那契数列的前 10 项。初始值为 `a, b = 0, 1`,并且循环执行 10 次,每次打印当前的 `a` 值。正确的代码片段如下: ```python a, b = 0, 1 for _ in range(10): print(a, end=&#39; &#39;) a, b = b, a + b ``` 上述代码中的关键部分是 `a, b = b, a + b`,这一行代码负责更新斐波那契数列的两个相邻值。通过这种方式,可以高效地生成斐波那契数列[^1]。 2. **高次方程求根** 另一个作业题目涉及求解一个五次方程的根。题目提供了一个函数 `f(x)`,其定义为 $ f(x) = x^5 - 15x^4 + 85x^3 - 225x^2 + 274x - 121 $。为了求解该方程在区间 [1.5, 2.4] 内的根,采用了二分法。具体实现如下: ```python def f(x): return x**5 - 15*x**4 + 85*x**3 - 225*x**2 + 274*x - 121 l, r = 1.5, 2.4 k = 0 while k < 20: mid = (l + r) / 2 x = f(mid) if x > 0: l = mid else: r = mid k += 1 print(round(mid, 6)) ``` 在这段代码中,`while` 循环执行了 20 次,每次通过计算中间值 `mid` 来判断根的位置,并逐步缩小搜索范围。最终输出的 `mid` 是近似解,保留了 6 位小数[^2]。 3. **两数之和的查找** 作业还包含了一个经典的算法问题——两数之和。题目要求找到数组中两个数的下标,使得它们的和等于给定的目标值 `target`。该问题可以通过哈希表(字典)来高效解决。具体实现如下: ```python def twoSum(nums, target): dict_ = {} for i in range(len(nums)): m = nums[i] if target - m in dict_: return (dict_[target - m], i) dict_[m] = i nums = [3, 4, 9, 7, 10] target = 11 res = twoSum(nums, target) print(res) ``` 上述代码中,`twoSum` 函数通过遍历数组并使用字典记录已遍历的数值及其下标,从而在后续查找中快速判断是否存在满足条件的配对。最终输出的结果是 `(0, 1)`,表示数组中索引为 0 和 1 的两个数之和等于目标值 11[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值