1. 程式人生 > >LINUX系統工程師技術(Engineer)-------第二天

LINUX系統工程師技術(Engineer)-------第二天

郵件服務器的基本搭建 mariadb數據庫的部署

兩臺虛擬機,均修改防火器與主機名

防火墻將原來的----------public狀態---------修改成-------trusted狀態

虛擬機server0:

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

# echo server0.example.com ?> ?/etc/hostname

# cat /etc/hostname


虛擬機desktop0:

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

# echo desktop0.example.com ?> ?/etc/hostname

# cat /etc/hostname


? 電子郵件服務器的基本功能

– 為用戶提供電子郵箱存儲空間(用戶名@郵件域名)

– 處理用戶發出的郵件 —— 傳遞給收件服務器

– 處理用戶收到的郵件 —— 投遞到郵箱


? ? ? 用戶發郵件的協議: ?SMTP ?端口25

? ? ? 用戶收郵件的協議: ?pop3 ?端口110 ? ?IMAP 端口143 ? ? ? ?

? ?

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

虛擬機server0

搭建基本郵件服務器

1. 安裝postfix服務端程序

[root@server0 ~]# rpm -q postfix

postfix-2.10.1-6.el7.x86_64


2.配置postfix服務,修改配置文件

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

?76行 ? myhostname = server0.example.com ? ? #指定主機名

?83行 ? mydomain = example.com ? ? ? ? ? ? ? #指定域名

?99行 ? myorigin = server0.example.com ? ?#默認補全的郵件後綴

?116行 inet_interfaces = all ? ? ? ? ? ? #允許所有客戶端

?164行 mydestination = server0.example.com

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #判斷郵件後綴為本域郵件

? ?補充:vim ?命令模式 ? ? ?u 撤銷


3.重起postfix服務,設置為開機自起

# systemctl restart postfix ? ? ? ? ? ? ? ? ? ? ??

# systemctl enable ?postfix ?


4. 測試郵件的收發


[root@server0 ~]# useradd yg

[root@server0 ~]# echo 123 | passwd --stdin yg


[root@server0 ~]# useradd xln

[root@server0 ~]# echo 123 | passwd --stdin xln


? mail 發信操作

– mail -s ‘郵件標題‘ ? -r 發件人 ? ?收件人


? mail 收信操作

– mail [-u 用戶名]


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


? 一行中只有一個 ?“.” ? ?的時候,代表結束

?

[root@server0 ~]# 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‘;------刪除以root用戶名和空密碼的


> select user,host,password from user ;


> desc ?user; ? #查看表結構












LINUX系統工程師技術(Engineer)-------第二天