TWO DAY

空不是无,是一种存在,你得用空这种存在填满自己。

                                                                                          ------刘慈欣

总结笔记:

部署postfix邮件服务

1.装包

[root@server0 ~]# yum -y install postfix

2.修改配置文件

[root@server0 ~]# vim /etc/postfix/main.cf

99行    myorigin = server0.example.com   #默认补全的域名结尾

116行  inet_interfaces = all             #监听所有网络接口

164行  mydestination = server0.example.com   #符合的判定为本域邮件

3.重起postfix

[root@server0 ~]# systemctl restart postfix

4.测试:

[root@server0 ~]# useradd yg

[root@server0 ~]# useradd xln

[root@server0 ~]# mail -s test01 -r yg xln

AAAAAAAAAAAAAAA

.

EOT

[root@server0 ~]# mail -u xln

空邮件服务

1.装包

[root@desktop0 ~]# lab smtp-nullclient setup  #搭建邮件服务器脚本

[root@server0 ~]# yum -y install postfix

虚拟机server0:邮件空客户端

1.修改配置文件

[root@server0 ~]# vim /etc/postfix/main.cf

99行    myorigin = desktop0.example.com   #默认补全的域名结尾

116行  inet_interfaces = localhost        #仅允许本机

164行  mydestination =                    #符合判定的为本域邮件-----修改为空

317行  relayhost = [172.25.0.10]         #将邮件交给172.25.0.10

3.重起postfix

[root@server0 ~]# systemctl restart postfix

4.测试

[root@server0 ~]# useradd yg

[root@server0 ~]# useradd xln

[root@server0 ~]#mail -s test01 -r yg xln

虚拟机desktop0:[root@desktop0 ~]# mail -u student

[root@server0 ~]#echo ‘wo men jie hun ba?’ | mail -s test01 -r yg xln

虚拟机desktop0:[root@desktop0 ~]# mail -u studen

[root@server0 ~]vim 1.txt

[root@server0 ~]#mail -s test01 -r yg xln < 1.txt

虚拟机desktop0:[root@desktop0 ~]# mail -u student

3.mariadb数据库

准备:

1.安装mariadb-server数据库程序

2.重起mariadb数据库服务

[root@server0 ~]# systemctl restart mariadb  #重起服务

[root@server0 ~]# systemctl enable mariadb   #设置为开机自起

3密码注册与登陆

为数据库账号修改密码

– mysqladmin [-u用户名] [-p[旧密码]] password '新密码'

[root@server0 ~]# mysql -uroot -p123 

4.禁止监听,只服务于本机

[root@server0 ~]# vim /etc/my.cnf

[mysqld]

skip-networking      //跳过网络监听

[root@server0 ~]# systemctl restart mariadb

开始:

1.创建库nihao

[root@server0 ~]# mysql -uroot -p123

MariaDB [(none)]> create database nihao;

MariaDB [(none)]> show databases;

MariaDB [(none)]> quit

 < :重定向输入,将输入的来源由键盘更改为指定文本文件内容

2导入/恢复到数据库

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

mysql -uroot -p123 nsd1707 < users.sql           #导入数据

# mysql -uroot -p123

MariaDB [(none)]> use nsd1707;      #进入nsd1707数据库

MariaDB [nsd1707]> show tables;     #查看所有表格

MariaDB [nsd1707]> select * from location;  #查看location表内容

MariaDB [nsd1707]> select * from base;      #查看base表内容

3.表记录基本操作

创建--1

MariaDB [nihao]> create table sushe1(id int,name varchar(20),location varchar(20),);  #创建数据表

MariaDB [nihao]> create table sushe2(id int,name varchar(20),location varchar(20),);  #创建数据表

MariaDB [nihao]> create table banji1(id int,name varchar(20),location varchar(20),qq varchar(20));  #创建数据表

MariaDB [nihao]> create table banji2(id int,name varchar(20),location varchar(20),qq varchar(20));  #创建数据表

查看--2

MariaDB [nsd1707]> show tables;     #查看所有表格

MariaDB [nihao]>desc sushe1;   #查看数据表属性;

MariaDB [nihao]>select * from sushe;     #查看数据表内容

插入--3

MariaDB [nihao]>insert into sushe1 values(1,’zhuborong’,’gansu’);    #插入表记录

MariaDB [nihao]>insert into sushe1 values(2,’yankaikai’,’heze’);

MariaDB [nihao]>insert into sushe1 values(3,’suichaoqun’,’zibo’);

MariaDB [nihao]>insert into sushe2 values(1,’zhuborong’,’gansu’);    #插入表记录

MariaDB [nihao]>insert into sushe2 values(2,’yankaikai’,’heze’);

MariaDB [nihao]>insert into sushe2 values(3,’suichaoqun’,’zibo’);

MariaDB [nihao]>insert into banji1 values(1,’zhuborong’,’gansu’,123456);    #插入表记录

MariaDB [nihao]>insert into banji1 values(2,’yankaikai’,’heze’234567);

MariaDB [nihao]>insert into banji1 values(3,’suichaoqun’,’zibo’,345678);

MariaDB [nihao]>insert into banji2 values(1,’zhuborong’,’gansu’,456789);    #插入表记录

MariaDB [nihao]>insert into banji2 values(2,’yankaikai’,’heze’,567890);

MariaDB [nihao]>insert into banji2 values(3,’suichaoqun’,’zibo’,678901);

修改与删除--4

MariaDB [nihao]>select * from sushe where id=2;    #查看表记录

MariaDB [nihao]>update sushe set name=’liguancong’,location=’heze’ where id=2;   #修改表记录

MariaDB [nihao]>delete from sushe where id=2;    #删除表记录

多表组合查询--5

MariaDB [nihao]>select * from suhe1,banji1 where sushe1.name=’liguancong’ and banji1.location=’heze’ and sushe.id=location.id



正式笔记:

• 电子邮件服务器的基本功能

– 为用户提供电子邮箱存储空间(用户名@邮件域名)

– 处理用户发出的邮件 —— 传递给收件服务器

– 处理用户收到的邮件 —— 投递到邮箱

1.快速部署postfix邮件服务器

• 装包、配置、起服务

– 默认的标准配置即可为本机提供发/收邮件服务

– 若有必要,可扩大服务范围(邮件域)

前提:邮件服务器,必须为手工配置永久主机名

虚拟机server0

[root@server0 ~]# echo server0.example.com > /etc/hostname

[root@server0 ~]# cat /etc/hostname

虚拟机desktop0

[root@desktop0 ~]# echo desktop0.example.com > /etc/hostname

[root@desktop0 ~]# cat /etc/hostname

虚拟机server0:

1.装包

[root@server0 ~]# rpm -q postfix

postfix-2.10.1-6.el7.x86_64

[root@server0 ~]# yum -y install postfix

2.修改配置文件

[root@server0 ~]# vim /etc/postfix/main.cf

99行    myorigin = server0.example.com   #默认补全的域名结尾

116行  inet_interfaces = all             #监听所有网络接口

164行  mydestination = server0.example.com   #符合的判定为本域邮件

3.重起postfix

[root@server0 ~]# systemctl restart postfix

4.测试:

[root@server0 ~]# useradd yg

[root@server0 ~]# useradd xln

[root@server0 ~]# mail -s test01 -r yg xln

AAAAAAAAAAAAAAA

.

EOT

[root@server0 ~]# mail -u xln

• mail 发信操作

– mail -s  '邮件标题'    -r   发件人@邮件域名   收件人@邮件域名 

• mail 收信操作

– mail [-u 用户名]

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

2.空客户端邮件服务器

• nullclient,空客户端

– 不提供任何邮箱账号,因此不需要投递邮件

– 但是可以为用户代发邮件

虚拟机desktop0:

[root@desktop0 ~]# lab smtp-nullclient setup  #搭建邮件服务器脚本

虚拟机server0:邮件空客户端

1.安装

[root@server0 ~]# yum -y install postfix

2.修改配置文件

[root@server0 ~]# vim /etc/postfix/main.cf

99行    myorigin = desktop0.example.com   #默认补全的域名结尾

116行  inet_interfaces = localhost        #仅允许本机

164行  mydestination =                    #修改为空

317行  relayhost = [172.25.0.10]         #将邮件交给172.25.0.10

3.重起postfix

[root@server0 ~]# systemctl restart postfix

4.发送邮件

[root@server0 ~]# echo 123 | mail -s test01 -r root student

虚拟机desktop0:[root@desktop0 ~]# mail -u student

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

3.MariaDB数据库

数据库:存放数据的仓库

  数控库------->很多的库----------->每一库有很多表格(表记录、表字端)

• RHEL7 中的 MariaDB 相关包

– mariadb-server:提供服务端有关的系统程序

– mariadb数据库的端口:3306

搭建基本数据库

虚拟机server0:

1.安装mariadb-server数据库程序

2.重起mariadb数据库服务

[root@server0 ~]# systemctl restart mariadb  #重起服务

[root@server0 ~]# systemctl enable mariadb   #设置为开机自起

3.数据库基本操作

[root@server0 ~]# mysql  #默认数据库不需要输入密码、用户名即可登陆

MariaDB [(none)]> show databases;              #查看都有那些库    

MariaDB [(none)]> create database  nsd1707;    #创建新的库

MariaDB [(none)]> show databases;

MariaDB [(none)]> drop database nsd1707;        #删除库

MariaDB [(none)]> show databases;

• 为数据库账号修改密码

– mysqladmin [-u用户名] [-p[旧密码]] password '新密码'

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

   数据库的管理员为root,与系统管理员root不是同一人

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

[root@server0 ~]# mysql -u root -p 

[root@server0 ~]# mysql -uroot -p123    #登陆

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

• 禁止监听,只服务于本机

[root@server0 ~]# vim /etc/my.cnf

[mysqld]

skip-networking      //跳过网络监听

[root@server0 ~]# systemctl restart mariadb

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

– 新建一个数据库名为 nsd1707,其中应该包含来自数

据库复制的内容,复制文件的 URL 为:

​http://classroom/pub/materials/users.sql​

1.创建库nihao

[root@server0 ~]# mysql -uroot -p123

MariaDB [(none)]> create database nihao;

MariaDB [(none)]> show databases;

MariaDB [(none)]> quit

 < :重定向输入,将输入的来源由键盘更改为指定文本文件内容

2导入/恢复到数据库

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

mysql -uroot -p123 nsd1707 < users.sql           #导入数据

# mysql -uroot -p123

MariaDB [(none)]> use nsd1707;      #进入nsd1707数据库

MariaDB [nsd1707]> show tables;     #查看所有表格

MariaDB [nsd1707]> select * from location;  #查看location表内容

MariaDB [nsd1707]> select * from base;      #查看base表内容

4.表记录基本操作

创建--1

MariaDB [nihao]> create table sushe1(id int,name varchar(20),location varchar(20),);  #创建数据表

MariaDB [nihao]> create table sushe2(id int,name varchar(20),location varchar(20),);  #创建数据表

MariaDB [nihao]> create table banji1(id int,name varchar(20),location varchar(20),qq varchar(20));  #创建数据表

MariaDB [nihao]> create table banji2(id int,name varchar(20),location varchar(20),qq varchar(20));  #创建数据表

查看--2

MariaDB [nsd1707]> show tables;     #查看所有表格

MariaDB [nihao]>desc sushe1;   #查看数据表属性;

MariaDB [nihao]>select * from sushe;     #查看数据表内容

插入--3

MariaDB [nihao]>insert into sushe1 values(1,’zhuborong’,’gansu’);    #插入表记录

MariaDB [nihao]>insert into sushe1 values(2,’yankaikai’,’heze’);

MariaDB [nihao]>insert into sushe1 values(3,’suichaoqun’,’zibo’);

MariaDB [nihao]>insert into sushe2 values(1,’zhuborong’,’gansu’);    #插入表记录

MariaDB [nihao]>insert into sushe2 values(2,’yankaikai’,’heze’);

MariaDB [nihao]>insert into sushe2 values(3,’suichaoqun’,’zibo’);

MariaDB [nihao]>insert into banji1 values(1,’zhuborong’,’gansu’,123456);    #插入表记录

MariaDB [nihao]>insert into banji1 values(2,’yankaikai’,’heze’234567);

MariaDB [nihao]>insert into banji1 values(3,’suichaoqun’,’zibo’,345678);

MariaDB [nihao]>insert into banji2 values(1,’zhuborong’,’gansu’,456789);    #插入表记录

MariaDB [nihao]>insert into banji2 values(2,’yankaikai’,’heze’,567890);

MariaDB [nihao]>insert into banji2 values(3,’suichaoqun’,’zibo’,678901);

修改与删除--4

MariaDB [nihao]>select * from sushe where id=2;    #查看表记录

MariaDB [nihao]>update sushe set name=’liguancong’,location=’heze’ where id=2;   #修改表记录

MariaDB [nihao]>delete from sushe where id=2;    #删除表记录

多表组合查询--5

MariaDB [nihao]>select * from suhe1,banji1 where sushe1.name=’liguancong’ and banji1.location=’heze’ and sushe.id=location.id

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

– 除了 root 用户,此数据库nsd1707只能被用户 lisi 查询,

此用户的密码为123

4.数据库的授权

– grant 权限列表 on 数据库名.表名 to 用户名@客户机地址 identified by '密码';

 当lisi从本地登陆输入密码123,将会获得nsd1707数据库所有表的查询权限

# mysql -uroot -p123

MariaDB [nsd1707]>  grant select on nsd1707.* to lisi@localhost identified by '123';

MariaDB [nsd1707]> quit

# mysql -ulisi -p123

MariaDB [nsd1707]> use nsd1707;

MariaDB [nsd1707]> select * from base;

补充:

   desc :显示表结构

MariaDB [mysql]> use mysql;

MariaDB [mysql]> show tables;

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

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

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

4. 在系统 server0 上使用数据库 nsd1707,并使用相

应的 SQL 查询以回答下列问题:

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

# mysql -uroot -p123 

 > use nsd1707;

 > select * from base where password='solicitous';

 > select name,password from base where password='solicitous';

 > select name from base where password='solicitous';

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

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

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

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