惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Cisco Blogs
Schneier on Security
Schneier on Security
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Scott Helme
Scott Helme
Webroot Blog
Webroot Blog
Project Zero
Project Zero
Google Online Security Blog
Google Online Security Blog
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
Hacker News: Ask HN
Hacker News: Ask HN
PCI Perspectives
PCI Perspectives
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News | PayPal Newsroom
Help Net Security
Help Net Security
The Hacker News
The Hacker News
H
Heimdal Security Blog
O
OpenAI News
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 叶小钗
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
I
Intezer
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security Affairs
P
Proofpoint News Feed
S
Secure Thoughts
腾讯CDC
Google DeepMind News
Google DeepMind News
量子位
罗磊的独立博客

叶泯希

每天都是绝版呢———记博客二周年 | 叶泯希 海的那边,真的是自由吗? | 叶泯希 放学打球 | 叶泯希 因 LeanCloud 停止对外服务,对数据迁移至 Vercel 。 2025:得与失 | 叶泯希 世事无常,珍惜眼前 | 叶泯希 “花怎么会落呢” | 叶泯希 “世界充满分歧,所以要学会尊重别人” | 叶泯希 “死亡不是永别,遗忘才是” | 叶泯希 “爱就像蓝天白云晴空万里突然暴风雨” | 叶泯希 “小雨天气” | 叶泯希 快下雨,别打雷了,赶紧的,热! | 叶泯希 寄博客一周年 | 叶泯希 出门不要摔跤容易烫伤 | 叶泯希 Windows 安装 Docker 部署 Immich 主题魔改——Solitude主题 | 叶泯希 自定义表盘导航软件——对小米手环9的折腾 | 叶泯希 武汉之旅 | 叶泯希 关于我在2024年做了这件事... | 叶泯希 2024.11.24 | 叶泯希 他乡纵有当头月,不及家乡一盏灯 | 叶泯希 Vercel+Aiven 自建Umami统计 | 叶泯希 侧边栏——Solitude主题 | 叶泯希 弹幕留言板——Solitude主题 | 叶泯希 2024.11.13 | 叶泯希 2024.11.12 | 叶泯希 好像还没写过日常 | 叶泯希 给自己的网站加上Do you like me 小组件 网站数据库中表的设计 | 叶泯希 听山河把春风酿成千言万语吹过旧人故里 | 叶泯希 网站页面规划设计 | 叶泯希 你出现又幻灭是错觉 | 叶泯希 网站功能设计 | 叶泯希 •ᴗ• | 叶泯希 相机喜欢镜头前的每一个故事 | 叶泯希 白茶记异品,天曹玉玲珑 | 叶泯希 岁月的年轮,再诚恳。也渡不过红尘《宿命》 | 叶泯希 云朵偷喝了酒,于是映红了半边天。 | 叶泯希 用太多的精力因为上天自有安排 | 叶泯希 我一脚踏空,我就要飞起来了。 | 叶泯希 日落是永远拍不完的浪漫 | 叶泯希 风吹过我的头发 | 叶泯希 童话里的王国住着巫婆 | 叶泯希 “晚风吹起你鬓间的白发” | 叶泯希 人性的背后都是白云苍狗 | 叶泯希 蒲公英的约定 | 叶泯希 我捡到过一束光,日落时还给了太阳。 | 叶泯希 去拥抱陌生,期待惊喜,所有的不期而遇都在 | 叶泯希 人生天地间,忽如远行客 | 叶泯希 少年的征途应是星辰大海,而非烟尘人间 | 叶泯希 数据库表结构 | 叶泯希 第七章 Centos 7 Linux配置ftp 实训任务1:FTP服务器加密传输 第六章 Centos 7 Linux配置web 实训任务:Apache服务器部署 第五章 Centos 7 Linux配置dns 实训任务:部署DNS服务器 第四章 Centos 7 Linux配置dhcp 实训任务1:使用DHCP中继部署多子网环境 第三章 Centos 7 Linux配置samba 实训任务1:配置Samba服务 第二章_Centos 7 Linux配置ssh 实训任务:SSH的安全配置 | 叶泯希 第一章 VMware Workstation Pro 17安装Centos 7 安装虚拟机及简单配置 Hello World | 叶泯希
第八章 Centos 7 Linux配置mariadb 实训任务:部署数据库
标签 · 2024-05-28 · via 叶泯希

前言

任务情境描述任务一某公司准备开发一套员工管理系统,其中数据库使用到了MariaDB数据库,现需要系统管理员完成以下部署工作:在公司一台Linux服务器(192.168.1.10)上安装数据库服务器和客户端,方便开发人员开发测试使用,在另一台Linux主机(192.168.1.100)上安装客户端;对数据库进行初始化设置。任务二,该公司准备开发一套新员工管理系统,现需要系统管理员完成以下安全管理工作:数据库服务器进行必要的网络安全设置,只允许从公司内部公司内部网络(192.168.1.0/24)访问数据库服务。

虚拟机需求:1台服务器(Server)192.168.1.10、1台客户端(Client1)192.168.1.100

部署数据库

任务情境描述

任务一

某公司准备开发一套员工管理系统,其中数据库使用到了MariaDB数据库,现需要系统管理员完成以下部署工作:在公司一台Linux服务器(192.168.1.10)上安装数据库服务器和客户端,方便开发人员开发测试使用,在另一台Linux主机(192.168.1.100)上安装客户端;
对数据库进行初始化设置。

任务二

该公司准备开发一套新员工管理系统,现需要系统管理员完成以下安全管理工作:

  1. 对数据库服务器进行必要的网络安全设置,只允许从公司内部网络(192.168.1.0/24)访问数据库服务器;

  2. 从安全的角度对数据库的配置文件进行必要的安全设置,修改数据库端口号为“8800”,并设置日志文件为/var/log/mariaDB/access.log

  3. 登录数据库,并新建一个名为newstaff的数据库;在数据库中创建一个数据表为stafftable;字段类型为staff int,username varchar(20),sex char(6),age
    int;并将下表中的总公司部门员工信息插入到stafftable表中:

  4. 对数据库账户和权限进行必要的管理,为开发人员创建一个名为“adminDB”的账户,但只允许他对newstaff数据库进行必要的操作;

  5. 为有效保护员工数据,编写一个定时任务,让系统每天凌晨0:00点对newstaff数据库自动进行数据备份。

一、 服务器(Server)和客户端(Client1)安装数据库服务

1. 服务器(Server)

1
2
3
4
5
[root@server www]# yum -y install mariadb-server mysql  //安装
[root@server www]# systemctl start mariadb.service //开启
[root@server www]# systemctl enable mariadb.service //自启
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

2. 客户端(Client1)

1
[root@webserver webserver]# yum -y install mysql    //安装

二、在服务器(Server)创建数据库和表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[root@server www]# mysql -uroot -p    //登录数据库 默认密码应该是root或空
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database newstaff; //创建数据库newstaff
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> use newstaff; //进入数据库newstaff
Database changed
MariaDB [newstaff]> create table stafftable ( //按任务需求创建表
-> staffID int auto_increment, //自增
-> username varchar(20),
-> sex char(6),
-> age int,
-> primary key(staffID) //主键
-> )engine=innodb default charset=utf8; //表的引擎字符类型
Query OK, 0 rows affected (0.02 sec)

MariaDB [newstaff]> insert into stafftable(username,sex,age) values('Tom','male',25),('Mary','female',30);
Query OK, 2 rows affected (0.05 sec) //按要求插入数据
Records: 2 Duplicates: 0 Warnings: 0

MariaDB [newstaff]> desc stafftable; //查看表结构
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| staffID | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(20) | YES | | NULL | |
| sex | char(6) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

MariaDB [newstaff]> select * from stafftable; //查询表内所有数据
+---------+----------+--------+------+
| staffID | username | sex | age |
+---------+----------+--------+------+
| 1 | Tom | male | 25 |
| 2 | Mary | female | 30 |
+---------+----------+--------+------+
2 rows in set (0.01 sec)

MariaDB [newstaff]> quit //退出
Bye
[root@server www]#

三、 服务器(Server)只允许192.168.1.0/24访问数据库

1
[root@server www]# iptables -A INPUT -p tcp -s 192.168.1.0/24 --dport 8800 -j ACCEPT

四、 修改服务器(Server)默认端口

1
2
3
4
5
vim /etc/my.cnf   //插入以下
port=8800 //修改默认端口
max_user_connections=2 //最大用户数
log=/var/log/mariadb/access.log //修改日志默认路径
[mysqld_safe]

防火墙设置

1
2
3
4
5
6
7
8
9
10
11
12
13
允许mysql[root@server www]# firewall-cmd --permanent --zone=public --add-service=mysql
success
允许端口[root@server www]# firewall-cmd --permanent --zone=public --add-port=8800/tcp
success
允许端口[root@server www]# firewall-cmd --permanent --zone=public --add-port=8800/udp
success
重启防火墙[root@server www]# semanage port -l | grep mysql
mysqld_port_t tcp 8800, 1186, 3306, 63132-63164
mysqlmanagerd_port_t tcp 2273
[root@server www]# semanage port -a -t mysqld_port_t -p tcp 8800
[root@server www]# firewall-cmd --reload
success
[root@server www]# systemctl restart mariadb.service

五、在服务器(Server)上创建账户只允许他对newstaff数据库进行操作

创建用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@server www]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> create user 'adminDB'@'%' identified by 'root'; //设置用户名和密码root
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> quit
Bye
[root@server www]#


只允许对newstaff数据库进行操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@server www]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show grants for 'adminDB'@'%';
+----------------------------------------------------------------------------------------------------------------+
| Grants for adminDB@% |
+----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'adminDB'@'%' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' |
+----------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> grant select,insert,update,delete,create,drop on newstaff.* to 'adminDB'@'%'; //只允许adminDB操作数据库newstaff
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> quit
Bye
[root@server www]#

六、编写备份程序(可略,老师好像不看)

1
2
3
4
5
6
7
8
9
10
11
12
[root@server www]# mysqldump -uroot -p newstaff > newstaff_backup.sql   //备份newstaff数据库
Enter password:
[root@server www]# cd ..
[root@server var]# cd ..
[root@server /]# vim backup.sh //编写程序

time=`date+"("%F")"%R`
$/usr/local/mysql/bin/mysqldump -uroot -proot newstaff|gzip > /root/staffbackup-$time.gz
[root@server /]# crontab -e //添加定时任务
00 00 * * * /backup.sh //0点0分 每天 每月 每时 脚本路径
crontab: installing new crontab
[root@server /]# systemcrl restart mariadb

七、 测试

老师一般说这几条命令,她叫你打什么就打什么吧

1. 客户端(Client1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@webserver webserver]# mysql -uadminDB -p -P8800 -h 192.168.1.10 //带端口登录
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use newstaff;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [newstaff]> desc stafftable; //查看表结构
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| staffID | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(20) | YES | | NULL | |
| sex | char(6) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

MariaDB [newstaff]> select * from stafftable; //查看表内容
+---------+----------+--------+------+
| staffID | username | sex | age |
+---------+----------+--------+------+
| 1 | Tom | male | 25 |
| 2 | Mary | female | 30 |
+---------+----------+--------+------+
2 rows in set (0.00 sec)

MariaDB [newstaff]> quit
Bye
[root@webserver webserver]#

2. 服务器(Server)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@server /]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show grants for 'adminDB'@'%';
+--------------------------------------------------------------------------------------------------------------------+
| Grants for adminDB@% |
+--------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'adminDB'@'%' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON `newstaff`.* TO 'adminDB'@'%' |
+--------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> quit
Bye
[root@server /]#

结尾

至此,实验结束。希望对你有所帮助,有任何问题请在下方留言。可以关注我的 公众号以及订阅我的文章 ,感谢你的支持,是对我最大的动力,当然了,更多的是因为热爱。

叶泯希

见过花开就好

本文是原创文章,采用CC BY-NC-SA 4.0协议,完整转载请注明来自叶泯希