################################################################################################
修改防火墙和主机名:
虚拟机server0:
firewall-cmd --set-default-zone=trusted
vim /etc/hostname
server0.example.com
虚拟机desktop0:
fireawall-cmd --set-default-zone=trusted
vim /etc/hostname
desktop0.example

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

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

      用户发邮件的协议:  SMTP  端口25
      用户收邮件的协议:  pop3  端口110    IMAP 端口143  
############################################################################################
虚拟机server0:
搭建基本的邮件服务器
一.安装postfix服务端程序:
#yum -y install postfix   //安装postfix服务端程序
#rpm -q postfix   //查看是否安装成功

二.配置postfix服务,修改配置文件

#vim /etc/postfix/main.cf   //配置文件的路径
 myhostname = server0.example.com           //配置主机名
 mydomain = example.com                     //指定域名
 myorigin =  server0.example.com            //发件人地址域  默认自动补全的后缀
 inet_interfaces = all                      //允许所有客户端
 mydestination = server0.example.com        //判断邮件后缀是否为本域邮件

三.重起postfix服务,设置为开机自起
# systemctl restart postfix                       
# systemctl enable  postfix

四.测试

邮件的收发:
虚拟机server0:
#useradd yg
#echo 123 | passwd -- stdin yg  //设置yg用户密码
#useradd xln
#echo 123 | passwd -- stdin xln  //设置xln用户密码

发送邮件:
 – mail -s '邮件标题'   -r 发件人    收件人
#su - yg
#mail -s 'test' -r yg xln   //邮件主题为test 发件人yg 收件人 xln -s表示subject -r表示source
 123
 456
 .
书写邮件内容 当有一行只有一个.时,表示书写完毕

接收邮件:
    – mail [-u 用户名]
#su - xln
#mail -u xln
  输入 邮件编号 1 查看邮件内容
  quit 退出
########################################################################################

nullclient邮件服务

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


一、配置desktop0为邮件服务器
1.配置postfix服务,修改配置文件
[root@desktop0 ~]# vim /etc/postfix/main.cf

 99行    myorigin = desktop0.example.com   
 116行  inet_interfaces = all           
 164行  mydestination = desktop0.example.com

[root@desktop0 ~]# systemctl restart postfix
[root@desktop0 ~]# systemctl enable postfix

二、配置server0为空客户端邮件服务器
[root@server0 ~]# vim /etc/postfix/main.cf

  99行     myorigin = desktop0.example.com
  116行   inet_interfaces = localhost
  164行   mydestination =             //关闭接收端口
  317行   relayhost = [172.25.0.10]   #指定交给邮件服务器IP地址
   
[root@server0 ~]# systemctl restart postfix

三、测试
虚拟机server0上
# echo   abc   |   mail -s Test1 -r  yg   student

虚拟机desktop0上
# mail -u student
######################################################################################
 数据库服务基础

常见的关系型 数据库管理系统
– 微软的 SQL Server
– IBM的 DB2
– 甲骨文的 Oracle、MySQL
– 社区开源版 MariaDB


RHEL7 中的 MariaDB 相关包
    – mariadb-server:提供服务端有关的系统程序
               端口号 : 3306

一、部署mariadb数据库
1.安装mariadb-server数据库软件
[root@server0 ~]# yum -y install mariadb-server

2.启动mariadb服务
[root@server0 ~]# systemctl restart mariadb
[root@server0 ~]# systemctl enable mariadb


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

[root@server0 ~]# mysql

MariaDB [(none)]> show databases;           #查看数据库
MariaDB [(none)]> create database nsd1709;  #创建数据库
MariaDB [(none)]> show databases;         

MariaDB [(none)]> drop database nsd1709;    #删除数据库
MariaDB [(none)]> show databases;

MariaDB [(none)]> create database nsd;   
MariaDB [(none)]> show databases;

MariaDB [(none)]> quit                     #退出数据库

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

      数据库管理员为root,但与系统用户root没有关系

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

[root@server0 ~]# mysqladmin -u  root   password  '123'

[root@server0 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@server0 ~]# mysql  -u  root  -p
Enter password:

[root@server0 ~]# mysql -u root -p123      #免交互登陆


禁止监听,只服务于本机
[root@server0 ~]# vim /etc/my.cnf   #数据库主配置文件
[mysqld]
skip-networking         #跳过网络监听
......
[root@server0 ~]# systemctl restart mariadb

MariaDB [(none)]> 交互指令
– 列出数据库:show databases;
– 使用/选择数据库:use 数据库名;
– 列出库里有哪些表:show tables;
– 创建数据库:CREATE database 数据库名;
– 删除数据库:DROP database 数据库名;



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

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

# wget http://172.25.254.254/pub/materials/users.sql
# mysql -u root -p123 nsd < users.sql

# mysql -u root -p123

MariaDB [nsd]> use nsd;          #进入nsd库
MariaDB [nsd]> show tables;      #查看都有那些表格


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

 查询操作
# mysql -u root -p123
MariaDB [nsd]> use nsd;

MariaDB [nsd]> select * from base;
MariaDB [nsd]> select * from location;

MariaDB [nsd]> select id,name from base;

MariaDB [nsd]> select * from base where name='tom';

MariaDB [nsd]> select * from location where city='beijing';

#######################################################
  数据库授权

MariaDB [(none)]> 交互指令
– grant 权限列表  on  数据库名.表名   to  用户名@localhost
  identified by '密码';

   当lisi用户从本地localhost登陆,输入密码123,将会获得库nsd所有表的查询权限

# mysql -u root -p123

MariaDB [(none)]> grant select on nsd.* to lisi@localhost identified by '123';

查看MariaDB数据库中,用户表信息

MariaDB [mysql]> select user,password from mysql.user;

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

2. 在系统 server0 上使用数据库 nsd,并使用相
应的 SQL 查询以回答下列问题:

1) 密码是 solicitous 的人的名字?

> select * from nsd.base where password='solicitous';
> select * from nsd.base where password='solicitous' and  id='3';

> select * from nsd.base where name='Barbara' or  id='3';

2) 有多少人的姓名是 Barbara 同时居住在 Sunnyvale?

> use nsd;

> select * from base,location
where base.name='Barbara' and location.city='Sunnyvale'   and  base.id=location.id;

> select count(*) from base,location    
where base.name='Barbara' and location.city='Sunnyvale' and  base.id=location.id;

> insert base values(6,'Barbara',123456);  #插入表记录
> insert location values(6,'Sunnyvale');   #插入表记录
> select * from base;
> select * from location;



1. 禁止空密码root用户访问 mariadb 数据库

> use mysql;

> select user,host,password from user where password=''and user='root';

> delete from user where password='' and user='root';

> select user,host,password from user ;

> desc  user;   #查看表结构