12. 复习题
12. 复习题
一、环境准备
-
A机器配置
- 设置静态IP地址:
192.168.10.100,子网掩码默认,网关为192.168.10.1,DNS为8.8.8.8。 - 禁用网卡DHCP功能,使用NAT模式联网。
- 挂载系统光盘,配置本地YUM源(仓库名称为
local)。 - 关闭防火墙和SELinux(需验证生效)。
- 设置静态IP地址:
-
B机器配置
- 将网卡设置为DHCP动态获取IP,使用NAT模式联网。
- 挂载系统光盘,配置本地YUM源(仓库名称为
local)。 - 关闭防火墙和SELinux(需验证生效)。
- 验证能否通过A机器的DHCP服务获取IP地址(IP范围应为
192.168.10.101-200)。
二、DHCP服务器部署题(A机器)
-
服务安装与配置
- 安装DHCP服务软件包。
- 配置DHCP服务,要求:
- 地址池范围:
192.168.10.101到192.168.10.200。 - 网关:
192.168.10.1,DNS服务器:8.8.8.8。 - 默认租期:
600秒,最大租期:7200秒。
- 地址池范围:
- 启动DHCP服务并设置开机自启。
-
验证操作
- 在B机器上执行
dhclient命令释放并重新获取IP地址。 - 使用
ip addr检查B机器是否获得符合地址池范围的IP。
- 在B机器上执行
三、MYSQL服务部署题(B机器)
-
服务安装与配置
- 安装MariaDB数据库服务。
- 设置root用户密码为
123456,删除匿名用户及测试数据库。 - 创建数据库
web。
-
表结构操作
- 在
web数据库中创建表users,字段要求:id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) UNIQUE NOT NULL, password_hash VARCHAR(255) NOT NULL - 验证表结构是否成功创建(需提供SQL查询命令及结果截图)。
- 在
四、WEB服务部署题(B机器)
-
基础服务安装
- 安装Apache服务(httpd)及PHP支持。
- 创建PHP测试页面
index.php,内容为<?php phpinfo(); ?>。 - 启动Apache服务并设置开机自启。
-
功能验证
- 在真机浏览器中访问
http://B机器IP,确认能正常显示PHP信息页面。
- 在真机浏览器中访问
五、FTP服务部署题(B机器)
-
服务安装与配置
- 安装
vsftpd服务。 - 修改配置文件,禁止匿名用户登录(
anonymous_enable=NO)。
- 安装
-
本地用户管理
- 创建本地用户
ftpuser,设置家目录为/var/www/html,密码为123456。 - 确保用户
ftpuser对家目录拥有完整权限(读写执行)。
- 创建本地用户
六、网页文件传输题(A→B机器)
- 文件创建与传输
- 在A机器上创建以下文件:
index.html:基础HTML页面。config.php:包含MySQL数据库连接配置。login.php:用户登录表单页面。dashboard.php:用户数据展示页面。
- 通过FTP方式将上述文件传输到B机器的
/var/www/html目录。
- 在A机器上创建以下文件:
index.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<style>
/* 基础样式重置 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #f0f2f5;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
/* 登录容器 */
.login-container {
background: white;
padding: 2.5rem;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
/* 标题样式 */
h1 {
color: #1a73e8;
text-align: center;
margin-bottom: 2rem;
font-size: 1.8rem;
}
/* 表单组样式 */
.form-group {
margin-bottom: 1.5rem;
}
label {
display: block;
margin-bottom: 0.5rem;
color: #5f6368;
font-weight: 500;
}
input {
width: 100%;
padding: 12px;
border: 1px solid #dadce0;
border-radius: 5px;
font-size: 1rem;
transition: border-color 0.3s ease;
}
input:focus {
outline: none;
border-color: #1a73e8;
box-shadow: 0 0 0 2px rgba(26,115,232,0.2);
}
/* 登录按钮 */
.login-btn {
width: 100%;
padding: 12px;
background: #1a73e8;
color: white;
border: none;
border-radius: 5px;
font-size: 1rem;
cursor: pointer;
transition: background 0.3s ease;
}
.login-btn:hover {
background: #1557b0;
}
/* 错误提示 */
.error-msg {
color: #dc3545;
font-size: 0.875rem;
margin-top: 0.5rem;
display: none;
}
/* 底部链接 */
.bottom-links {
text-align: center;
margin-top: 1.5rem;
}
.bottom-links a {
color: #1a73e8;
text-decoration: none;
font-size: 0.875rem;
}
.bottom-links a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="login-container">
<h1>用户登录</h1>
<form id="loginForm" action="login.php" method="POST">
<div class="form-group">
<label for="username">用户名</label>
<input
type="text"
id="username"
name="username"
placeholder="请输入用户名"
required
>
<div class="error-msg" id="usernameError">用户名不能为空</div>
</div>
<div class="form-group">
<label for="password">密码</label>
<input
type="password"
id="password"
name="password"
placeholder="请输入密码"
required
minlength="6"
>
<div class="error-msg" id="passwordError">密码不能少于6位</div>
</div>
<button type="submit" class="login-btn">登录</button>
</form>
<div class="bottom-links">
<a href="#">忘记密码?</a>
<span style="color: #dadce0"> | </span>
<a href="#">立即注册</a>
</div>
</div>
<script>
const form = document.getElementById('loginForm');
const usernameInput = document.getElementById('username');
const passwordInput = document.getElementById('password');
const usernameError = document.getElementById('usernameError');
const passwordError = document.getElementById('passwordError');
form.addEventListener('submit', function(e) {
let isValid = true;
if(usernameInput.value.trim() === '') {
usernameError.style.display = 'block';
isValid = false;
}
if(passwordInput.value.length < 6) {
passwordError.style.display = 'block';
isValid = false;
}
if(!isValid) {
e.preventDefault();
}
// 验证通过时允许直接提交到PHP
});
</script>
</body>
</html>
config.php
<?php
$host = "localhost";
$user = "root";
$password = "";
$dbname = "web";
// 创建不安全连接
$conn = mysqli_connect($host, $user, $password, $dbname);
// 检查连接(显示详细错误)
if (!$conn) {
die("连接失败: " . mysqli_connect_error());
}
?>
login.php
<?php
include 'config.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 直接获取用户输入,不做任何过滤
$username = $_POST['username'];
$password = $_POST['password'];
// 构建危险SQL查询语句
$sql = "SELECT * FROM users WHERE username='$username' AND password_hash=md5('$password')";
// 执行查询(显示错误信息)
$result = mysqli_query($conn, $sql);
// 验证登录
if (mysqli_num_rows($result) > 0) {
// 登录成功跳转
header("Location: dashboard.php?username=".$username);
exit();
} else {
echo "用户名或密码错误!";
}
}
?>
dashboard.php
<?php
// 注意:仍然没有会话验证和过滤
$username = $_GET['username']; // 直接从URL获取用户名
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>用户仪表盘</title>
<style>
/* 现代仪表盘样式 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', system-ui;
}
body {
background: #f0f2f5;
min-height: 100vh;
}
.dashboard-container {
max-width: 1200px;
margin: 0 auto;
padding: 2rem;
}
.header {
background: #1a73e8;
color: white;
padding: 1.5rem;
border-radius: 12px;
margin-bottom: 2rem;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.welcome-text {
font-size: 2rem;
margin-bottom: 0.5rem;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
margin-bottom: 2rem;
}
.stat-card {
background: white;
padding: 1.5rem;
border-radius: 12px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
transition: transform 0.2s;
}
.stat-card:hover {
transform: translateY(-2px);
}
.card-title {
color: #5f6368;
margin-bottom: 1rem;
font-size: 0.9rem;
}
.card-value {
font-size: 2rem;
color: #1a73e8;
font-weight: bold;
}
.recent-activity {
background: white;
border-radius: 12px;
padding: 1.5rem;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.activity-list {
list-style: none;
}
.activity-item {
display: flex;
align-items: center;
padding: 1rem 0;
border-bottom: 1px solid #eee;
}
.activity-icon {
width: 40px;
height: 40px;
background: #1a73e820;
border-radius: 8px;
margin-right: 1rem;
display: flex;
align-items: center;
justify-content: center;
color: #1a73e8;
}
</style>
</head>
<body>
<div class="dashboard-container">
<div class="header">
<div class="welcome-text">欢迎回来,<?php echo $username; ?>!</div>
<p>最后登录时间:2023-08-15 14:30</p>
</div>
<div class="stats-grid">
<div class="stat-card">
<div class="card-title">总访问量</div>
<div class="card-value">2,345</div>
</div>
<div class="stat-card">
<div class="card-title">新消息</div>
<div class="card-value">12</div>
</div>
<div class="stat-card">
<div class="card-title">账户余额</div>
<div class="card-value">¥5,678</div>
</div>
</div>
<div class="recent-activity">
<h2>最近活动</h2>
<ul class="activity-list">
<li class="activity-item">
<div class="activity-icon">📌</div>
<div>
<h3>系统登录</h3>
<p>2023-08-15 14:30 从 192.168.1.1 登录</p>
</div>
</li>
<li class="activity-item">
<div class="activity-icon">💰</div>
<div>
<h3>收入到账</h3>
<p>+ ¥1,000 来自客户付款</p>
</div>
</li>
<li class="activity-item">
<div class="activity-icon">⚙️</div>
<div>
<h3>资料修改</h3>
<p>更新了个人联系方式</p>
</div>
</li>
</ul>
</div>
</div>
</body>
</html>
七、TFTP服务部署题(A机器)
-
服务安装与配置
- 安装
tftp-server和xinetd服务。 - 配置TFTP根目录为
/var/lib/tftpboot,允许文件上传。 - 启动服务并设置开机自启。
- 安装
-
验证操作
- 在B机器上使用TFTP客户端上传文件到A机器的
/var/lib/tftpboot。 - 从A机器下载文件到B机器,验证服务可用性。
- 在B机器上使用TFTP客户端上传文件到A机器的
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 现代职校董良
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果