Linux课程第二十天学习笔记

####################3.用户和访问权限####################
[[email protected] ~]# mysql -uroot -pwestos
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

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

MariaDB [(none)]> SELECT Host,User,Password FROM mysql.user;
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| 127.0.0.1 | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| ::1       | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
+-----------+------+-------------------------------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> CREATE USER [email protected] identified by ‘westos‘;
Query OK, 0 rows affected (0.00 sec)
##创建用户westos密码westos。localhost表示只能本机访问‘%‘表示远端访问授权

MariaDB [(none)]> SELECT Host,User,Password FROM mysql.user;
+-----------+--------+-------------------------------------------+
| Host      | User   | Password                                  |
+-----------+--------+-------------------------------------------+
| localhost | root   | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| 127.0.0.1 | root   | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| ::1       | root   | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| localhost | westos | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
+-----------+--------+-------------------------------------------+
4 rows in set (0.00 sec)
##多了一行"westos"的信息

MariaDB [(none)]> Ctrl-C -- exit!        ##按"ctrl+c"退出
Aborted
[[email protected] ~]# mysql -uwestos -pwestos
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

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

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> CREATE DATABASE westos;
ERROR 1044 (42000): Access denied for user ‘westos‘@‘localhost‘ to database ‘westos‘
MariaDB [(none)]> Ctrl-C -- exit!
Aborted
[[email protected] ~]# mysql -uroot -pwestos
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

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

MariaDB [(none)]> SELECT Host,User,Password,Create_priv FROM mysql.user;
+-----------+--------+-------------------------------------------+-------------+
| Host      | User   | Password                                  | Create_priv |
+-----------+--------+-------------------------------------------+-------------+
| localhost | root   | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | Y           |
| 127.0.0.1 | root   | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | Y           |
| ::1       | root   | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | Y           |
| localhost | westos | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | N           |
+-----------+--------+-------------------------------------------+-------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> GRANT CREATE on *.* to [email protected];
Query OK, 0 rows affected (0.00 sec)
##用户授权CREATE*.*表示所有库的所有表

MariaDB [(none)]> SHOW GRANTS FOR [email protected];
+----------------------------------------------------------------------------------------------------------------+
| Grants for [email protected]                                                                                    |
+----------------------------------------------------------------------------------------------------------------+
| GRANT CREATE ON *.* TO ‘westos‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘*28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96‘ |
+----------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> SELECT Host,User,Password,Create_priv FROM mysql.user;
+-----------+--------+-------------------------------------------+-------------+
| Host      | User   | Password                                  | Create_priv |
+-----------+--------+-------------------------------------------+-------------+
| localhost | root   | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | Y           |
| localhost | westos | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | Y           |
| 127.0.0.1 | root   | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | Y           |
| ::1       | root   | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | Y           |
+-----------+--------+-------------------------------------------+-------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> Ctrl-C -- exit!
Aborted
[[email protected] ~]# mysql -uwestos -pwestos
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

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

MariaDB [(none)]> CREATE DATABASE westos;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> Ctrl-C -- exit!
Aborted
[[email protected] ~]# mysql -uroot -pwestos
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

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

MariaDB [(none)]> SELECT Host,User,Create_priv,Insert_priv FROM mysql.user;
+-----------+--------+-------------+-------------+
| Host      | User   | Create_priv | Insert_priv |
+-----------+--------+-------------+-------------+
| localhost | root   | Y           | Y           |
| 127.0.0.1 | root   | Y           | Y           |
| ::1       | root   | Y           | Y           |
| localhost | westos | Y           | N           |
+-----------+--------+-------------+-------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> GRANT INSERT on *.* to [email protected];    ##用户授权INSERT
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW GRANTS FOR [email protected];+------------------------------------------------------------------------------------------------------------------------+
| Grants for [email protected]                                                                                            |
+------------------------------------------------------------------------------------------------------------------------+
| GRANT INSERT, CREATE ON *.* TO ‘westos‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘*28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96‘ |
+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> SELECT Host,User,Create_priv,Insert_priv FROM mysql.user;
+-----------+--------+-------------+-------------+
| Host      | User   | Create_priv | Insert_priv |
+-----------+--------+-------------+-------------+
| localhost | root   | Y           | Y           |
| 127.0.0.1 | root   | Y           | Y           |
| ::1       | root   | Y           | Y           |
| localhost | westos | Y           | Y           |
+-----------+--------+-------------+-------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;    ##重载授权表。没起作用使用此命令前权限已变成"Y"
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> REVOKE CREATE on *.* from [email protected];        ##移除权限CREATE
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SELECT Host,User,Create_priv,Insert_priv FROM mysql.user;
+-----------+--------+-------------+-------------+
| Host      | User   | Create_priv | Insert_priv |
+-----------+--------+-------------+-------------+
| localhost | root   | Y           | Y           |
| 127.0.0.1 | root   | Y           | Y           |
| ::1       | root   | Y           | Y           |
| localhost | westos | N           | Y           |
+-----------+--------+-------------+-------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> DROP USER [email protected];        ##删除用户westos
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SELECT Host,User,Create_priv,Insert_priv FROM mysql.user;
+-----------+------+-------------+-------------+
| Host      | User | Create_priv | Insert_priv |
+-----------+------+-------------+-------------+
| localhost | root | Y           | Y           |
| 127.0.0.1 | root | Y           | Y           |
| ::1       | root | Y           | Y           |
+-----------+------+-------------+-------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> Ctrl-C -- exit!
Aborted

####################4.密码恢复####################
[[email protected] ~]# systemctl stop mariadb
[[email protected] ~]# mysqld_safe --skip-grant-tables &    ##相当于开启mysql的单用户模式
[1] 12220
[[email protected] ~]# 161129 02:47:38 mysqld_safe Logging to ‘/var/log/mariadb/mariadb.log‘.
161129 02:47:38 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[[email protected] ~]# mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

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

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| westos             |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> SELECT Host,User,Password FROM mysql.user;
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| 127.0.0.1 | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
| ::1       | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 |
+-----------+------+-------------------------------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> UPDATE mysql.user set Password=‘redhat‘ WHERE User=‘root‘;    ##更新密码
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

MariaDB [(none)]> SELECT Host,User,Password FROM mysql.user;
+-----------+------+----------+
| Host      | User | Password |
+-----------+------+----------+
| localhost | root | redhat   |
| 127.0.0.1 | root | redhat   |
| ::1       | root | redhat   |
+-----------+------+----------+
3 rows in set (0.00 sec)
##密码全部变成明文不安全

MariaDB [(none)]> UPDATE mysql.user set Password=password (‘redhat‘) WHERE User=‘root‘;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
##将密码修改成密文

MariaDB [(none)]> SELECT Host,User,Password FROM mysql.user;
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| 127.0.0.1 | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| ::1       | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
+-----------+------+-------------------------------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> Ctrl-C -- exit!
Aborted
[[email protected] ~]# jobs
[1]+  Stopped                 mysqld_safe --skip-grant-tables
[[email protected] ~]# killall -9 mysqld_safe
[1]+  Killed                  mysqld_safe --skip-grant-tables
[[email protected] ~]# ps aux | grep mysql
mysql    12375  0.1  9.9 924612 100800 pts/0   Sl   02:47   0:01 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root     12837  0.0  0.0 112640   940 pts/0    S+   03:04   0:00 grep --color=auto mysql
[[email protected] ~]# kill -9 12375
[[email protected] ~]# ps aux | grep mysql
root     12863  0.0  0.0 112640   936 pts/0    S+   03:06   0:00 grep --color=auto mysql
[[email protected] ~]# systemctl restart mariadb
[[email protected] ~]# mysql -uroot -predhat
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

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

MariaDB [(none)]> Ctrl-C -- exit!
Aborted
[[email protected] ~]# mysqladmin -uroot -predhat password westos        ##修改密码
[[email protected] ~]# mysql -uroot -pwestos
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

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

MariaDB [(none)]> Ctrl-C -- exit!
Aborted

####################5.备份####################
==准备工作==
[[email protected] ~]# mysql -uroot -pwestos
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

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

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| westos             |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> USE westos;
Database changed
MariaDB [westos]> SHOW TABLES;
Empty set (0.00 sec)

MariaDB [westos]> CREATE TABLE linux (
    -> username varchar(10) not null,
    -> password varchar(50) not null,
    -> class varchar(5) );
Query OK, 0 rows affected (0.12 sec)

MariaDB [westos]> DESC linux;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(10) | NO   |     | NULL    |       |
| password | varchar(50) | NO   |     | NULL    |       |
| class    | varchar(5)  | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

MariaDB [westos]> INSERT INTO linux VALUES (‘lee‘,‘123‘,‘18‘);
Query OK, 1 row affected (0.09 sec)

MariaDB [westos]> INSERT INTO linux VALUES (‘linuxc‘,‘123‘,‘‘);
Query OK, 1 row affected (0.08 sec)

MariaDB [westos]> SELECT * FROM linux;
+----------+----------+-------+
| username | password | class |
+----------+----------+-------+
| lee      | 123      | 18    |
| linuxc   | 123      |       |
+----------+----------+-------+
2 rows in set (0.00 sec)

MariaDB [westos]> Ctrl-C -- exit!
Aborted

==备份==
[[email protected] ~]# mysqldump -uroot -pwestos westos
--------------------------------------------------
>太多截取重要信息

--
-- Table structure for table `linux`
--

DROP TABLE IF EXISTS `linux`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `linux` (
  `username` varchar(10) NOT NULL,
  `password` varchar(50) NOT NULL,
  `class` varchar(5) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `linux`
--

LOCK TABLES `linux` WRITE;
/*!40000 ALTER TABLE `linux` DISABLE KEYS */;
INSERT INTO `linux` VALUES (‘lee‘,‘123‘,‘18‘),(‘linuxc‘,‘123‘,‘‘);
/*!40000 ALTER TABLE `linux` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET [email protected]_TIME_ZONE */;
--------------------------------------------------
##不加"--no-data"备份表的数据结构和表的内容
[[email protected] ~]# mysqldump -uroot -pwestos --no-data westos
--------------------------------------------------
>太多截取重要信息

--
-- Table structure for table `linux`
--

DROP TABLE IF EXISTS `linux`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `linux` (
  `username` varchar(10) NOT NULL,
  `password` varchar(50) NOT NULL,
  `class` varchar(5) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET [email protected]_TIME_ZONE */;
--------------------------------------------------
##加上"--no-data"只备份表的数据结构
[[email protected] ~]# mysqldump -uroot -pwestos westos > /mnt/westos.sql
[[email protected] ~]# mysql -uroot -pwestos -e "SHOW DATABASES;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| westos             |
+--------------------+
##"-e"非交互式可以用来制作脚本
[[email protected] ~]# mysql -uroot -pwestos -e "DROP DATABASE westos;"
[[email protected] ~]# mysql -uroot -pwestos -e "SHOW DATABASES;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
[[email protected] ~]# mysql -uroot -pwestos westos < /mnt/westos.sql
ERROR 1049 (42000): Unknown database ‘westos‘
##必须先创建一个westos库
[[email protected] ~]# mysql -uroot -pwestos -e "CREATE DATABASE westos;"
[[email protected] ~]# mysql -uroot -pwestos westos < /mnt/westos.sql    ##恢复数据
[[email protected] ~]# mysql -uroot -pwestos -e "SHOW DATABASES;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| westos             |
+--------------------+
[[email protected] ~]# mysql -uroot -pwestos -e "SELECT * FROM westos.linux"
+----------+----------+-------+
| username | password | class |
+----------+----------+-------+
| lee      | 123      | 18    |
| linuxc   | 123      |       |
+----------+----------+-------+

####################6.web管理####################
yum install php php-mysql httpd -y
systemctl start httpd
systemctl enable httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --reload

tar -jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html
cd /var/www/html
mv phpMyAdmin-3.4.0-all-languages myadmin
cd myadmin/
cp -p config.sample.inc.php config.inc.php
vim config.inc.php
 17 $cfg[‘blowfish_secret‘] = ‘test‘; /* YOU MUST FILL IN THIS FOR COOKIE AUTH    ! */

systemctl restart httpd
http://172.25.50.100/myadmin

#####################
#####   SMTP    #####
#####################

####################DNS配置####################
172.25.50.100-->maillinux
172.25.50.200-->mailwestos

[[email protected] ~]# hostnamectl set-hostname maillinux.linux.com
[[email protected] ~]# vim /etc/yum.repos.d/rhel_dvd.repo
[[email protected] ~]# yum clean all
Loaded plugins: langpacks
Cleaning repos: rhel_dvd
Cleaning up everything
[[email protected] ~]# reboot
等待重启

[[email protected] ~]# hostnamectl set-hostname mailwestos.westos.com
[[email protected] ~]# vim /etc/yum.repos.d/rhel_dvd.repo
[[email protected] ~]# yum clean all
Loaded plugins: langpacks
Cleaning repos: rhel_dvd
Cleaning up everything
[[email protected] ~]# reboot
等待重启

[[email protected] ~]# yum install bind -y
......
[[email protected] ~]# vim /etc/named.conf
--------------------------------------------------
 11         listen-on port 53 { any; };

17         allow-query     { any; };

32         dnssec-validation no;
:wq
--------------------------------------------------
[[email protected] ~]# vim /etc/named.rfc1912.zones
--------------------------------------------------
 25 zone "linux.com" IN {
 26         type master;
 27         file "linux.com.zone";
 28         allow-update { none; };
 29 };
 30
 31 zone "westos.com" IN {
 32         type master;
 33         file "westos.com.zone";
 34         allow-update { none; };
 35 };
 36
:wq
--------------------------------------------------
[[email protected] ~]# cd /var/named
[[email protected] named]# cp -p named.localhost westos.com.zone
[[email protected] named]# vim westos.com.zone
--------------------------------------------------
  1 $TTL 1D
  2 @       IN SOA  dns.westos.com. root.westos.com. (
  3                                         0       ; serial
  4                                         1D      ; refresh
  5                                         1H      ; retry
  6                                         1W      ; expire
  7                                         3H )    ; minimum
  8                 NS      dns.westos.com.
  9 dns             A       172.25.50.100
 10 westos.com.     MX 1    172.25.50.200.
:wq
--------------------------------------------------
[[email protected] named]# cp -p westos.com.zone linux.com.zone
[[email protected] named]# vim linux.com.zone
--------------------------------------------------
:%s/westos/linux/g

10 linux.com.      MX 1    172.25.50.100.
:wq
--------------------------------------------------
[[email protected] named]# systemctl start named
[[email protected] named]# systemctl enable named
ln -s ‘/usr/lib/systemd/system/named.service‘ ‘/etc/systemd/system/multi-user.target.wants/named.service‘
[[email protected] named]# systemctl stop firewalld
[[email protected] named]# systemctl disable firewalld
rm ‘/etc/systemd/system/basic.target.wants/firewalld.service‘
rm ‘/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service‘
[[email protected] named]# vim /etc/resolv.conf
--------------------------------------------------
  4 nameserver 172.25.50.100
:wq
--------------------------------------------------
[[email protected] named]# dig -t mx linux.com |grep MX
;linux.com.            IN    MX
linux.com.        86400    IN    MX    1 172.25.50.100.
[[email protected] named]# dig -t mx westos.com |grep MX
;westos.com.            IN    MX
westos.com.        86400    IN    MX    1 172.25.50.200.

[[email protected] ~]]# vim /etc/resolv.conf
--------------------------------------------------
  4 nameserver 172.25.50.100
:wq
--------------------------------------------------
[[email protected] ~]# dig -t mx linux.com |grep MX
;linux.com.            IN    MX
linux.com.        86400    IN    MX    1 172.25.50.100.
[[email protected] ~]# dig -t mx westos.com |grep MX
;westos.com.            IN    MX
westos.com.        86400    IN    MX    1 172.25.50.200.

####################SMTP配置####################
smtp用于邮件投递默认使用25端口

是谁发送的邮件
本机登陆web页面控制服务器发送邮件
所以发送邮件的是服务器

MX记录        ##邮件交换记录

http的服务由iiswindowsapachelinux等提供
stmp的服务由sendmailqmailpostfixredhat集成等提供

popimap用于邮件接收其服务由Dovecot豆腐块等提供

MTA邮件传输代理就是邮件服务器用于寄信和收信
MDA邮件接受代理将从MTA接收到的邮件放入正确的本地邮箱
MUA邮件用户代理是用在Client端的软件比如OutLook

mail [email protected]
Subject: 111
222
333
.        ##"."加"回车"表示结束编辑
EOT

1)基本配置
[[email protected] ~]# netstat -antlpe | grep :25
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      0          21796      1468/master         
tcp6       0      0 ::1:25                  :::*                    LISTEN      0          21797      1468/master     
##只开放了环回地址的25端口
[[email protected] ~]# vim /etc/postfix/main.cf
-----------------------------------------------
 75 myhostname = maillinux.linux.com
 83 mydomain = linux.com
 99 myorigin = $mydomain
113 inet_interfaces = all
116 #inet_interfaces = localhost
164 mydestination = $myhostname, $mydomain, localhost        ##我接收哪些目的地址
:wq
-----------------------------------------------
##localhost表示什么也不加
[[email protected] ~]# systemctl restart postfix.service
[[email protected] ~]# netstat -antlpe | grep :25
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      0          37160      1582/master         
tcp6       0      0 :::25                   :::*                    LISTEN      0          37161      1582/master

=====测试:不带域名和dns无关=====
[[email protected] ~]# mail root
Subject: aaa
aaaaaa
aaaaaa
.
EOT
[[email protected] ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
BD25917E85C      434 Wed Nov 30 21:35:30  [email protected]
                (connect to 172.25.50.200[172.25.50.200]:25: No route to host)
                                         [email protected]

-- 0 Kbytes in 1 Request.
[[email protected] ~]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 root                  Wed Nov 30 21:44  19/545   "aaa"
& 1
Message  1:
From [email protected]  Wed Nov 30 21:44:45 2016
Return-Path: <[email protected]>
X-Original-To: root
Delivered-To: [email protected]
Date: Wed, 30 Nov 2016 21:44:45 -0500
To: [email protected]
Subject: aaa
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

aaaaaa
aaaaaa

& q
Held 1 message in /var/spool/mail/root
====================

[[email protected] ~]# scp /etc/postfix/main.cf [email protected]:/etc/postfix/main.cf
The authenticity of host ‘172.25.50.200 (172.25.50.200)‘ can‘t be established.
ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘172.25.50.200‘ (ECDSA) to the list of known hosts.
[email protected]‘s password:
main.cf                                       100%   27KB  26.5KB/s   00:00

[[email protected] ~]# vim /etc/postfix/main.cf
-----------------------------------------------
:%s/linux/westos/g
:wq
-----------------------------------------------
[[email protected] ~]# systemctl restart postfix.service

=====测试:踢出队列=====
[[email protected] ~]# mail [email protected]
Subject: bbb
bbbbbb
bbbbbb
.
EOT
[[email protected] ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
11DD917E85C      434 Wed Nov 30 21:47:14  [email protected]
                (connect to 172.25.50.200[172.25.50.200]:25: No route to host)
                                         [email protected]

-- 0 Kbytes in 1 Request.
[[email protected] ~]# postsuper -d 11DD917E85C    ##踢出队列
postsuper: 11DD917E85C: removed
postsuper: Deleted: 1 message
[[email protected] ~]# mailq
Mail queue is empty
====================

=====测试:刷新队列=====
[[email protected] ~]# mail [email protected]
Subject: ccc
cccccc
cccccc
.
EOT
[[email protected] ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
18E4717E85C      434 Wed Nov 30 21:47:56  [email protected]
                (connect to 172.25.50.200[172.25.50.200]:25: No route to host)
                                         [email protected]

-- 0 Kbytes in 1 Request.

[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# systemctl disable firewalld.service
rm ‘/etc/systemd/system/basic.target.wants/firewalld.service‘
rm ‘/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service‘

[[email protected] ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
18E4717E85C      434 Wed Nov 30 21:47:56  [email protected]
                (connect to 172.25.50.200[172.25.50.200]:25: No route to host)
                                         [email protected]

-- 0 Kbytes in 1 Request.
[[email protected] ~]# postqueue -f        ##刷新队列重新发送
[[email protected] ~]# mailq
Mail queue is empty

[[email protected] ~]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 root                  Wed Nov 30 21:48  22/742   "ccc"
& 1
Message  1:
From [email protected]  Wed Nov 30 21:48:21 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 30 Nov 2016 21:47:55 -0500
To: [email protected]
Subject: ccc
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

cccccc
cccccc

& q
Held 1 message in /var/spool/mail/root
邮件发送成功
====================

=====测试:westos回信=====
[[email protected] ~]# mail [email protected]
Subject: ddd
dddddd
dddddd
.
EOT
[[email protected] ~]# mailq
Mail queue is empty

[[email protected] ~]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 2 messages 1 new
    1 root                  Wed Nov 30 21:44  20/556   "aaa"
>N  2 root                  Wed Nov 30 22:34  22/743   "ddd"
& 2
Message  2:
From [email protected]  Wed Nov 30 22:34:36 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 30 Nov 2016 22:34:36 -0500
To: [email protected]
Subject: ddd
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

dddddd
dddddd

& q
Held 2 messages in /var/spool/mail/root
====================

=====测试:发给域名=====
[[email protected] ~]# mail @westos.com
Subject: eee
eeeeee
eeeeee
.
EOT
[[email protected] ~]# mailq
Mail queue is empty

[[email protected] ~]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 2 messages 1 new
    1 root                  Wed Nov 30 21:48  23/753   "ccc"
>N  2 root                  Wed Nov 30 22:47  22/743   "eee"
& 2
Message  2:
From [email protected]  Wed Nov 30 22:47:56 2016
Return-Path: <[email protected]>
X-Original-To: ""@westos.com
Delivered-To: MAILER-D[email protected]
Date: Wed, 30 Nov 2016 22:47:55 -0500
To: ""@westos.com
Subject: eee
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

eeeeee
eeeeee

& q
Held 2 messages in /var/spool/mail/root
====================

=====测试:发给普通用户加域名=====
[[email protected] ~]# mail [email protected]
Subject: fff   
ffffff
ffffff
.
EOT
[[email protected] ~]# mailq
Mail queue is empty

[[email protected] ~]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 2 messages
>   1 root                  Wed Nov 30 21:48  23/753   "ccc"
    2 root                  Wed Nov 30 22:47  23/754   "eee"
& q
Held 2 messages in /var/spool/mail/root                ##没有收到新消息
[[email protected] ~]# mail -u student
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/mail/student": 1 message 1 new
>N  1 root                  Wed Nov 30 22:53  22/752   "fff"
& 1
Message  1:
From [email protected]  Wed Nov 30 22:53:15 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 30 Nov 2016 22:53:14 -0500
To: [email protected]
Subject: fff
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

ffffff
ffffff

& q
Held 1 message in /var/mail/student
====================

2)排错方法
> /var/mail/root
> /var/mail/student
> /var/log/maillog
cat /var/log/maillog

3)mta
[[email protected] ~]# man alternatives
-----------------------------------------------
       alternatives - maintain symbolic links determining default commands

--config name
              Present the user with a configuration menu for choosing the mas‐
              ter  link  and slaves for link group name. Once chosen, the link
              group is set to manual mode.

--display name
              Display information about the link group of which  name  is  the
              master  link.   Information  displayed includes the group‘s mode
              (auto or manual), which alternative the symlink currently points
              to, what other alternatives are available (and their correspond‐
              ing slave alternatives), and the  highest  priority  alternative
              currently installed.

--list Display information about all link groups.
-----------------------------------------------
[[email protected]llinux ~]# alternatives --list |grep mta
mta    auto    /usr/sbin/sendmail.postfix
[[email protected] ~]# alternatives --display mta        
mta - status is auto.
 link currently points to /usr/sbin/sendmail.postfix
/usr/sbin/sendmail.postfix - priority 30
 slave mta-mailq: /usr/bin/mailq.postfix
 slave mta-newaliases: /usr/bin/newaliases.postfix
 slave mta-pam: /etc/pam.d/smtp.postfix
 slave mta-rmail: /usr/bin/rmail.postfix
 slave mta-sendmail: /usr/lib/sendmail.postfix
 slave mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz
 slave mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz
 slave mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz
 slave mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz
Current `best‘ version is /usr/sbin/sendmail.postfix.
[[email protected] ~]# ll /usr/sbin/sendmail
lrwxrwxrwx. 1 root root 21 May  6  2014 /usr/sbin/sendmail -> /etc/alternatives/mta
[[email protected] ~]# ll /etc/alternatives/mta
lrwxrwxrwx. 1 root root 26 May  6  2014 /etc/alternatives/mta -> /usr/sbin/sendmail.postfix
[[email protected] ~]# ll /usr/sbin/sendmail.postfix
-rwxr-xr-x. 1 root root 247832 Jan 26  2014 /usr/sbin/sendmail.postfix

4)postconf
[[email protected] ~]# postconf -d |grep inet            ##查看默认配置
inet_interfaces = all
inet_protocols = all
local_header_rewrite_clients = permit_inet_interfaces
[[email protected] ~]# postconf -n |grep inet            ##查看当前配置
inet_interfaces = all
inet_protocols = all
[[email protected] ~]# postconf -e "inet_interfaces=localhost"    ##修改当前配置
[[email protected] ~]# postconf -n |grep inet
inet_interfaces = localhost
inet_protocols = all
[[email protected] ~]# postconf -e "inet_interfaces=all"
[[email protected] ~]# postconf -n |grep inet
inet_interfaces = all
inet_protocols = all
[[email protected] ~]# systemctl restart postfix.service

5)收件人别名
[[email protected] ~]# vim /etc/aliases
-----------------------------------------------
 97 admin:          root
 98 more:           :include:/etc/moreusers
:wq
-----------------------------------------------
[[email protected] ~]# vim /etc/moreusers
-----------------------------------------------
  1 root
  2 student
:wq
-----------------------------------------------
[[email protected] ~]# postalias /etc/aliases
[[email protected] ~]# systemctl restart postfix.service
[[email protected] ~]# > /var/mail/root
[[email protected] ~]# > /var/mail/student

=====测试:[email protected]=====
[[email protected] ~]# mail [email protected]
Subject: 111
111111
111111
.
EOT
[[email protected] ~]# mailq
Mail queue is empty

[[email protected] ~]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 root                  Thu Dec  1 01:47  22/746   "111"
& 1
Message  1:
From [email protected]  Thu Dec  1 01:47:58 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Thu, 01 Dec 2016 01:47:57 -0500
To: [email protected]
Subject: 111
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

111111
111111

& q
Held 1 message in /var/spool/mail/root
====================

=====测试:[email protected]=====
[[email protected] ~]# mail [email protected]
Subject: 222
222222
222222
.
EOT
[[email protected] ~]# mailq
Mail queue is empty

[[email protected] ~]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 2 messages 1 new
    1 root                  Thu Dec  1 01:47  23/757   "111"
>N  2 root                  Thu Dec  1 01:49  25/872   "222"
& 2
Message  2:
From [email protected]  Thu Dec  1 01:49:41 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Delivered-To: [email protected]
Date: Thu, 01 Dec 2016 01:49:40 -0500
To: [email protected]
Subject: 222
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

222222
222222

& q
Held 2 messages in /var/spool/mail/root
[[email protected] ~]# mail -u student
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/mail/student": 1 message 1 new
>N  1 root                  Thu Dec  1 01:49  25/875   "222"
& 1
Message  1:
From [email protected]  Thu Dec  1 01:49:41 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Delivered-To: [email protected]
Date: Thu, 01 Dec 2016 01:49:40 -0500
To: [email protected]
Subject: 222
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

222222
222222

& q
Held 1 message in /var/mail/student
====================

6)发件人地址欺骗
[[email protected] ~]# vim /etc/postfix/generic
-----------------------------------------------
241 [email protected] [email protected]
:wq
-----------------------------------------------
[[email protected] ~]# postmap /etc/postfix/generic
[[email protected] ~]# ls /etc/postfix/
access     generic     header_checks  master.cf  transport
canonical  generic.db  main.cf        relocated  virtual
[[email protected] ~]# cat /etc/postfix/generic.db
]/K&эh^[email protected]@linux.com
[[email protected] ~]# postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
[[email protected] ~]# postconf -n | grep smtp_generic_maps
smtp_generic_maps = hash:/etc/postfix/generic
[[email protected] ~]# systemctl restart postfix.service

=====测试:发件人地址欺骗=====
[[email protected] ~]# mail [email protected]
Subject: 333
333333
333333
.
EOT
[[email protected] ~]# mailq
Mail queue is empty

[[email protected] ~]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 3 messages 1 new
    1 root                  Thu Dec  1 01:47  23/757   "111"
    2 root                  Thu Dec  1 01:49  26/883   "222"
>N  3 root                  Thu Dec  1 02:25  22/748   "333"
& 3
Message  3:
From [email protected]  Thu Dec  1 02:25:11 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Thu, 01 Dec 2016 02:25:10 -0500
To: [email protected]
Subject: 333
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

333333
333333

& q
Held 3 messages in /var/spool/mail/root
====================

7)使用telnet登陆并发送邮件
[[email protected] ~]# yum install telnet -y
......
[[email protected] ~]# telnet 172.25.50.100 25
Trying 172.25.50.100...
Connected to 172.25.50.100.
Escape character is ‘^]‘.
220 maillinux.linux.com ESMTP Postfix
ehlo hello
250-maillinux.linux.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
666666
666666
.
250 2.0.0 Ok: queued as 5988117E85F
quit
221 2.0.0 Bye
Connection closed by foreign host.
You have new mail in /var/spool/mail/root
[[email protected] ~]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 4 messages 1 new
    1 root                  Thu Dec  1 01:47  23/757   "111"
    2 root                  Thu Dec  1 01:49  26/883   "222"
    3 root                  Thu Dec  1 02:25  23/759   "333"
>N  4 [email protected]      Thu Dec  1 02:37  14/511   
& 4
Message  4:
From [email protected]  Thu Dec  1 02:37:38 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Status: R

666666
666666

& q
Held 4 messages in /var/spool/mail/root

8)收件人地址转换
[[email protected] ~]# > /var/mail/root

[[email protected] ~]# vim /etc/postfix/virtual
-----------------------------------------------
295 [email protected] [email protected]
:wq
-----------------------------------------------
[[email protected] ~]# postmap /etc/postfix/virtual
[[email protected] ~]# ls /etc/postfix/
access     generic        main.cf    relocated  virtual
canonical  header_checks  master.cf  transport  virtual.db
[[email protected] ~]# cat /etc/postfix/virtual.db
c/.0<эh^
[[email protected] ~]# postconf -e "virtual_alias_maps=hash:/etc/postfix/virtual"
[[email protected] ~]# postconf -n virtual_alias_maps
virtual_alias_maps = hash:/etc/postfix/virtual
[[email protected] ~]# systemctl restart postfix.service
[[email protected] ~]# mail [email protected]
Subject: 000
000000
000000
.
EOT
[[email protected] ~]# mailq
Mail queue is empty

=====测试:收件人地址转换=====
[[email protected] ~]# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 root                  Thu Dec  1 04:01  22/748   "000"
& 1
Message  1:
From [email protected]  Thu Dec  1 04:01:47 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Thu, 01 Dec 2016 04:01:46 -0500
To: [email protected]
Subject: 000
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

000000
000000

& q
Held 1 message in /var/spool/mail/root
====================

时间: 2024-10-11 06:00:37

Linux课程第二十天学习笔记的相关文章

Linux课程第二十一天学习笔记

##########################   SMTP    ########################## 重新配置DNS,以及SMTP基本配置(略) ####################MTA配置####################9)access[[email protected] ~]# cd /etc/postfix/[[email protected] postfix]# lsaccess     generic        main.cf    relo

Linux课程第二十二天学习笔记

####################空壳邮件####################[[email protected] ~]# vim /etc/named.rfc1912.zones ----------------------------------------------- 37 zone "westos.org" IN { 38         type master; 39         file "westos.org.zone"; 40    

Linux课程第八天学习笔记

####################3.日志分析工具journal####################systemd-journald            ##进程名称 ####################[[email protected] ~]# cd /root/Desktop/[[email protected] Desktop]# ps aux |grep journaldroot       365  0.2  0.2  41164  2608 ?        Ss 

Linux课程第一天学习笔记

####################虚拟机控制####################[[email protected] Desktop]$ rht-vmctl start desktop        ##开启desktop虚拟机Error: desktop not started (is already running)            ##报错,desktop已经运行[[email protected] Desktop]$ rht-vmctl view desktop     

Linux课程第二天学习笔记

5)vim 文本方式编辑文件vim [filename]        ##进入到命令模式命令模式不能编辑文件,如果要编辑文件要进入插入模式按"i"进入插入模式如果完成编辑,按"Esc"退出插入模式,输入":wq",保存退出 vim [filename] 如果文件名字不存在,会自动创建vim 没有操作对象直接打开,编辑文件后要输入":wq [filename]" ":q!"表示不保存,强制退出":

Linux课程第九天学习笔记

####################"which"和"whereis"的使用:[[email protected] Desktop]# which ls alias ls='ls --color=auto'    /usr/bin/ls[[email protected] Desktop]# whereis ls ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz 百

Linux课程第十八天学习笔记

############更改default.target的链接源为reboot.target############ reboot.target    ##init6 修复方法:rm -fr /etc/systemd/system/default.targetln -s /usr/lib/systemd/system/graphical.target /etc/systemd/system/default.target ####################[[email protected]

Linux课程第十二天学习笔记

################################  2.用户权限列表    ################################ ####################1.权限列表的定义####################指定特殊用户对某个文件有特殊权限的记录表格 ####################2.权限列表的识别####################-rw-r--r--+ 1 root root   12 Nov  1 09:56 file-rw-r

Linux Shell脚本编程学习笔记和实战

http://www.1987.name/141.html shell基础 终端打印.算术运算.常用变量 Linux下搜索指定目录下特定字符串并高亮显示匹配关键词 从键盘或文件中获取标准输入 [read命令] 文件的描述符和重定向 数组.关联数组和别名使用 函数的定义.执行.传参和递归函数 条件测试操作与流程控制语句 获取时间日期格式和延时 [date.sleep命令] 内部字段分隔符IFS和脚本的调试DEBUG 显示.读取或拼接文件内容 [cat命令] 文件查找与打印文件列表 [find命令]