环境准备:还原 Classroom(DNS_Server)、Server、Desktop

设置server与desktop防火墙默认区域为trusted

Server:IP	172.25.0.10
Desktop:IP	172.25.0.11
DNS_Server:
	server0.example.com		172.25.0.10
	desktop0.example.com		172.25.0.11

# firewall-cmd --set-default-zone=trusted

##################################################################################### 搭建基本邮件服务器

电子邮件通信 • 电子邮件服务器的基本功能 – 为用户提供电子邮箱存储空间(用户名@邮件域名) – 处理用户发出的邮件 —— 传递给收件服务器 – 处理用户收到的邮件 —— 投递到邮箱

用户发邮件的协议 :SMTP 端口号 25 用户收邮件的协议 :pop3 端口号 110 IMAP 端口号 143

电子邮箱地址:zhsan@sina.com、lisi@sina.com

快速部署postfix邮件服务器 • 装包、配置、起服务

server0:搭建邮件服务(server0.example.com) 1.设置永久的主机名(server0.example.com)/etc/hostname # echo server0.example.com >/etc/hostname #修改主机名

2.安装postfix软件包(服务端) # rpm -q postfix #查看是否有安装postfix

3.修改配置文件/etc/postfix/main.cf

# vim /etc/postfix/main.cf
  76行	 myhostname = server0.example.com	#指定主机名(DNS中注册过)
  83行	 mydomain = example.com			#指定域名
  99行   myorigin = server0.example.com 	#默认补全的发件人域名后缀
  116行  inet_interfaces = all         #设置监听的网络接口(改localhost为all,允许所有使用)
  164行  mydestination = server0.example.com	#收件人的域名后缀,判断为本域邮件
  

4.重启postfix服务,设置为开机自启

# systemctl restart postfix
# systemctl enable postfix

5、创建用户,zhang3,lisi

# useradd zhang3
# useradd lisi
# echo 123 | passwd --stdin zhang3
# echo 123 | passwd --stdin lisi

6、测试收发邮件

# mail -s 'Title test'  zhang3 lisi@server0.example.com		//发邮件
# mail -u lisi	//收邮件

desktop0:搭建邮件服务(desktop0.example.com)

1.设置永久的主机名(desktop0.example.com)/etc/hostname
# echo desktop0.example.com >/etc/hostname

2.安装postfix软件包
# rpm -q postfix		#查看是否有安装postfix

3.修改配置文件/etc/postfix/main.cf
  76行	 myhostname = desktop0.example.com		#指定主机名(DNS中注册过)
  83行	 mydomain = example.com			#指定域名
  99行   myorigin = desktop0.example.com 		#默认补全的发件人域名
  116行  inet_interfaces = all         #设置监听的网络接口
  164行  mydestination = desktop0.example.com	#收件人的域名后缀,判断为本域邮件
  
4.重起postfix服务
# systemctl restart postfix
# systemctl enable postfix

server0:创建yg用户,设置密码123
# useradd yg
# echo 123 | passwd --stdin yg

desktop0:创建xln用户,设置密码123
# useradd xln
# echo 123 | passwd --stdin xln

server0: mail -s 'test01' -r  yg   xln@desktop0.example.com		//邮件主题test01,发件人yg,收件人xln
desktop0:mail -u xln

##################################################################################### 使用mail命令发信/收信 • mail 发信操作 – mail -s '邮件标题' 收件人 [@收件域]...

• mail 收信操作 – mail [-u 用户名]

##################################################################################### nullclient邮件服务

• nullclient,空客户端 – 不提供任何邮箱账号,因此不需要投递邮件 – 但是可以为用户代发邮件

环境准备:还原server、desktop

设置server与desktop防火墙默认区域为trusted

# firewall-cmd --set-default-zone=trusted

#####################################################################################

后端常规邮件服务器(Desktop0) 空客户端邮件服务器(Server0)

一、配置常规邮件服务器( Desktop0)

1.设置永久的主机名(desktop0.example.com)/etc/hostname
# echo desktop0.example.com >/etc/hostname
	
2. 修改/etc/postfix/main.cf   
 99  myorigin = desktop0.example.com        #发件来源域
 116 inet_interfaces = all        			#所有网络
 164 mydestination = desktop0.example.com  	#将投递域设为desktop0.example.com 

3.重起postfix服务
# systemctl restart postfix
# systemctl enable postfix

二、nullclient,空客户端邮件服务器(Server0)

1.设置永久的主机名(server0.example.com)/etc/hostname
# echo server0.example.com >/etc/hostname

2. 修改/etc/postfix/main.cf  
 99  myorigin = desktop0.example.com        #发件来源域
 116 inet_interfaces = loopback-only        #仅本机(或localhost)
 164 mydestination =                        #将投递域设为空
 264 mynetworks = [::1]/128,127.0.0.0/8,172.25.0.0/24    #信任网络 
 316 relayhost = [desktop0.example.com]     #目标邮件服务器(desktop0.example.com=172.25.0.10)

3.重起postfix服务
# systemctl restart postfix
# systemctl enable postfix

三、测试: 在server上发一封邮件给student,最后desktop0上student收到 在server上和desktop0上分别创建student,

# useradd student
# echo 123 | passwd --stdin student
# echo this is a test. | mail -s 'test01' -r  root   student		//在Server0上发送测试邮件
# mail -u student			// 在Server0上查看,没有邮件
# mail -u student			// 在Desktop0上查看,有测试邮件

##################################################################################### 数据库服务基础

MariaDB 数据库的管理员 root ,不同系统的管理员

部署mariadb数据库服务器 • RHEL7 中的 MariaDB 相关包 – mariadb-server:提供服务端有关的系统程序 – mariadb:提供客户端及管理工具 – mariadb数据库服务端口:3306

[root@server0 ~]# yum -y install mariadb-server		#mariadb数据库
[root@server0 ~]# systemctl restart mariadb			#启动MariaDB服务
[root@server0 ~]# mysql			#打开(进入)MariaDB(默认无密码)

MariaDB [(none)]> show  databases;           #查看所有的库
MariaDB [(none)]> create database nsd1705;   #创建库nsd1705
MariaDB [(none)]> show  databases;

MariaDB [(none)]> drop  database  nsd1705;   #删除nsd1705库
MariaDB [(none)]> show  databases;
MariaDB [(none)]> exit /quit                      #退出数据库服务

#####################################################################################

mariadb服务端配置调整 • 禁止监听,只服务于本机

[root@server0 ~]# vim /etc/my.cnf
[mysqld]
skip-networking     //跳过网络监听(只服务于本机)
.. ..
[root@server0 ~]# systemctl restart mariadb

• 为数据库账号修改密码 – mysqladmin [-u用户名] [-p[旧密码]] password '新密码'


[root@server0 ~]# mysqladmin -u root   password  '123'		#配置密码为123

[root@server0 ~]# mysql -u root -p123		#进入MariaDB数据库

##################################################################################### – 使用/选择数据库: use 数据库名; – 列出库里有哪些表: show tables;


[root@server0 ~]# mysql -u root -p123
MariaDB [mysql]> show databases;
MariaDB [mysql]> use  mysql;  		#选择数据库      
MariaDB [mysql]> show tables;
MariaDB [mysql]> desc user;         #显示表的结构

//显示user表中user,host,password内容
MariaDB [mysql]> select user,host,password from user;

//显示user表中user,password内容
MariaDB [none]> select user,password from mysql.user;
MariaDB [mysql]> select user,password from user;

##################################################################################### 导入/恢复到数据库 – mysql [-u用户名] [-p[密码]] 数据库名 >/< 备份文件.sql

重定向输入: <


[root@server0 ~]# mysql -u root -p123
MariaDB [(none)]> create database nsd;
MariaDB [(none)]> show databases;
MariaDB [(none)]> exit

# wget http://172.25.254.254/pub/materials/users.sql

# mysql -u root -p123 nsd < users.sql   #导入数据到nsd库中

[root@server0 ~]# mysql -u root -p123
MariaDB [nsd]> use nsd;
MariaDB [nsd]> show tables;
MariaDB [nsd]> select * from location;
MariaDB [nsd]> select * from base;

##################################################################################### 数据库的授权: – GRANT 权限列表 ON 数据库名.表名 TO 用户名@客户机地址 IDENTIFIED BY '密码'; 权限列表:select、insert、updat、delete、all

– 除了 root 用户,此数据库nsd只能被用户 lisi 查询,此用户的密码为123

[root@server0 ~]# mysql -u root -p123 
MariaDB [nsd]> grant select on  nsd.* to  lisi@localhost  identified  by '123'; 
MariaDB [nsd]> select user,password from mysql.user;		//查看lisi用户是否存在

当lisi利用密码123进行本地登陆数据库时,将会获得nsd库中所有表的查询权限

[root@server0 ~]# mysql -u lisi -p123 //验证是否能够登陆

##################################################################################### 案例5:使用数据库查询

1. 禁止空密码root用户访问 mariadb 数据库
MariaDB [mysql]> use mysql;
MariaDB [mysql]> select user,host,password from user;  
MariaDB [mysql]> select user,host,password from user  where user='root' and password='';
MariaDB [mysql]> delete from user  where user='root' and password='';



2. 在系统 server0 上使用数据库 nsd,并使用相应的 SQL 查询以回答下列问题:
1)密码是 solicitous 的人的名字?
MariaDB [nsd]> use nsd;
MariaDB [nsd]> select *  from nsd.base where password='solicitous';
MariaDB [nsd]> select name from base where password='solicitous';
MariaDB [nsd]> select name,password from base where password='solicitous';


2)有多少人的姓名是 Barbara 同时居住在 Sunnyvale?
MariaDB [nsd]>use nsd;
MariaDB [nsd]> select * from base,location where base.name='Barbara' and location.city='Sunnyvale' and base.id=location.id;
MariaDB [nsd]> select count(*) from base,location where base.name='Barbara' and location.city='Sunnyvale' and base.id=location.id;