第二十八天作业

第二十八天作业

1.部署备份服务器使用rsync ,把网站项目实时同步到 备份服务器 (利用脚本形式,做个定时任务 每5分钟执行同步一次)
环境:虚拟机

ip :10.0.1.0

网关:10.0.1.2

子网掩码:255.255.255.0


服务端ip:10.0.1.111
客户端ip:10.0.1.113




服务端部署(备份服务器):rsync
     第一步:下载安装软件
	 [root@localhost ~]# yum install -y rsync
	 第二步:编写配置文件
	 [root@localhost ~]# vim /etc/rsyncd.conf
	 uid=rsync                               
     gid=rsync                               
     port=873                                
     fake super = yes                        
     use chroot = no                         
     max connections= 200                    
     timeout = 300                           
     pid file = /var/run/rsyncd.pid          
     lock file = /var/run/rsync.lock         
     log file = /var/log/rsyncd.log          
     ignore errors                           
     read only = false                       
     list = false                            
     hosts allow = 10.0.1.0/24             
     #hosts deny =             
     auth users = rsync_backup               
     secrets file = /etc/rsync.password      
     [backup]                                
     comment =" welcome to RSYNC backup"
     path = /backup                          
     第三步:创建rsync服务虚拟用户
	 [root@localhost ~]# useradd rsync -M -s /sbin/nologin
	 第四步:创建rsync服务的认证密码文件并修改权限
	 [root@localhost ~]# echo "rsync_backup:123456">/etc/rsync.password
	 [root@localhost ~]# chmod 600 /etc/rsync.password 
	 第五步:创建备份文件所需的目录并修改用户文件的属主和属组
	 [root@localhost ~]# mkdir /backup
	 [root@localhost ~]# chown rsync.rsync /backup -R
     第六步:启动备份rsync服务
	 [root@localhost ~]# systemctl start rsyncd
     [root@localhost ~]# systemctl enable rsyncd












命令注解:


这段配置是Rsync服务器(rsyncd)的配置文件片段,通常保存在 `/etc/rsyncd.conf` 中。以下是对各项配置的解释:

- **uid = rsync**:设置rsync守护进程运行时的用户ID为rsync。

- **gid = rsync**:设置rsync守护进程运行时的组ID为rsync。

- **port = 873**:指定rsync服务监听的TCP端口号,默认为873。

- **fake super = yes**:让rsync模拟超级用户权限,以便在chroot环境下进行某些操作。

- **use chroot = no**:禁止在处理每一个模块时切换到一个独立的根目录(chroot jail),这对于某些高级用途可能不适用。

- **max connections = 200**:设置rsync服务器最大并发连接数为200。

- **timeout = 300**:设置超时时间为300秒,超过这个时间的无活动连接将被断开。

- **pid file = /var/run/rsyncd.pid**:指定rsync守护进程PID文件的位置。

- **lock file = /var/run/rsync.lock**:指定rsync锁定文件的位置,用于多进程同步。

- **log file = /var/log/rsyncd.log**:设置rsync服务器的日志文件路径。

- **ignore errors**:忽略文件传输过程中的一些错误。

- **read only = false**:设置rsync模块是否为只读,此处设置为可读写。

- **list = false**:禁止列出模块信息。

- **hosts allow = 10.0.1.0/24**:允许来自10.0.1.0/24子网的客户端连接。

- **auth users = rsync_backup**:定义允许连接的认证用户列表,此处为rsync_backup。

- **secrets file = /etc/rsync.password**:设置密码文件,其中包含允许连接的用户名及其密码。

- **[backup]**:定义一个名为"backup"的模块。

- **comment = "welcome to RSYNC backup"**:为"backup"模块添加注释信息。

- **path = /backup**:指定"backup"模块对应的本地文件系统路径为"/backup"。

总结:这是一个配置了rsync服务器允许来自10.0.1.0/24子网的客户端以用户rsync_backup的身份通过密码认证,访问本地"/backup"目录的配置文件。





客户端部署(网站服务器):rsync  配置文件不用改默认即可
     第一步:下载安装软件
	 [root@localhost ~]# yum install -y rsync
	 第二步:创建一个密码文件
	 [root@localhost ~]# echo "123456" >/etc/rsync.password
	 [root@localhost ~]# chmod 600 /etc/rsync.password
     第三步:测试用免交互方式同步文件
	 [root@localhost ~]# rsync -avz /oldboy/* rsync_backup@10.0.1.111::backup --password-file=/etc/rsync.password
	 
	 






	 
	 
	
	 
	 
	 具体实现过程
	 ip:10.0.1.111
	 服务端:
	 
	 [root@web1 ~]# yum install -y rsync
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package rsync.x86_64 0:3.1.2-12.el7_9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package               Arch                   Version                        Repository               Size
===========================================================================================================
Installing:
 rsync                 x86_64                 3.1.2-12.el7_9                 updates                 408 k

Transaction Summary
===========================================================================================================
Install  1 Package

Total download size: 408 k
Installed size: 820 k
Downloading packages:
rsync-3.1.2-12.el7_9.x86_64.rpm                                                     | 408 kB  00:00:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : rsync-3.1.2-12.el7_9.x86_64                                                             1/1 
  Verifying  : rsync-3.1.2-12.el7_9.x86_64                                                             1/1 

Installed:
  rsync.x86_64 0:3.1.2-12.el7_9                                                                            

Complete!
[root@web1 ~]# vim /etc/rsyncd.conf
把这一串粘进去
     uid=rsync                               
     gid=rsync                               
     port=873                                
     fake super = yes                        
     use chroot = no                         
     max connections= 200                    
     timeout = 300                           
     pid file = /var/run/rsyncd.pid          
     lock file = /var/run/rsync.lock         
     log file = /var/log/rsyncd.log          
     ignore errors                           
     read only = false                       
     list = false                            
     hosts allow = 10.0.1.0/24             
     #hosts deny =             
     auth users = rsync_backup               
     secrets file = /etc/rsync.password      
     [backup]                                
     comment =" welcome to RSYNC backup"

[root@web1 ~]# useradd rsync -M -s /sbin/nologin
[root@web1 ~]# echo "rsync_backup:123456">/etc/rsync.password
[root@web1 ~]#  chmod 600 /etc/rsync.password
[root@web1 ~]# mkdir /backup
[root@web1 ~]# chown rsync.rsync /backup -R
[root@web1 ~]# systemctl start rsyncd
[root@web1 ~]# systemctl enable rsyncd
ln -s '/usr/lib/systemd/system/rsyncd.service' '/etc/systemd/system/multi-user.target.wants/rsyncd.service'

	 
	 
	 
	 
	 
	 
	 客户端
	 ip:10.0.1.113
	 
	 [root@web02 ~]# yum install -y rsync
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package rsync.x86_64 0:3.1.2-12.el7_9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package               Arch                   Version                        Repository               Size
===========================================================================================================
Installing:
 rsync                 x86_64                 3.1.2-12.el7_9                 updates                 408 k

Transaction Summary
===========================================================================================================
Install  1 Package

Total download size: 408 k
Installed size: 820 k
Downloading packages:
rsync-3.1.2-12.el7_9.x86_64.rpm                                                     | 408 kB  00:00:06     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : rsync-3.1.2-12.el7_9.x86_64                                                             1/1 
  Verifying  : rsync-3.1.2-12.el7_9.x86_64                                                             1/1 

Installed:
  rsync.x86_64 0:3.1.2-12.el7_9                                                                            

Complete!
[root@web02 ~]# echo "123456" >/etc/rsync.password
[root@web02 ~]# chmod 600 /etc/rsync.password
[root@web02 ~]# rsync -avz /oldboy/* rsync_backup@10.0.1.111::backup --password-file=/etc/rsync.password
sending incremental file list
rsync: change_dir "/oldboy" failed: No such file or directory (2)

sent 24 bytes  received 20 bytes  8.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179) [sender=3.1.2]
[root@web02 ~]# rsync -avz /etc/passwd rsync_backup@10.0.1.111::backup --password-file=/etc/rsync.password
sending incremental file list
passwd

sent 559 bytes  received 43 bytes  92.62 bytes/sec
total size is 1,070  speedup is 1.78

















实现服务端和客户端b互相免密连接



ssh-keygen

cd /root/.ssh 

mv id_rsa.pub authorized_keys

scp  -r  /root/.ssh   10.0.1.113:/root 







企业文件目录增量实时同步 删除不同步
wget -O/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install inotify-tools  rsync


#!/bin/bash
path1=/data/web
ip=10.0.1.113         
/usr/bin/inotifywait -mrq --timefmt %y/%m'%d %H:/%M' --format '%T %w%f' -emodify,create,attrib $path1 | while read file;
do
rsync -avz $path1  root@$ip:/backup
echo "${file} was rsynced" >> /var/log/rsync.log 2>&1
done







具体实操演示

客户端
ip:10.0.1.113

mkdir -p /data/web

cd /data
mkdir web

以上是我自己没有这个目录,你如果有的话,就不需要了,生产环境中应根据自己的需求更换目录的



rsync -avz /data/web rsync_backup@10.0.1.111::backup --password-file=/etc/rsync.password    不需要密码

或者
rsync -avz /etc/hosts rsync_backup@10.0.1.111::backup    需要密码   
这里的密码是你配置的虚拟用户的密码



下载inotify-tools
wget -O/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install inotify-tools  rsync

创建一个目录或者你可以找个地方存放脚本

cd /data/sh

mkdir -p /data/sh

这里我有就不创建了

vi in.sh

#!/bin/bash
path1=/data/web
ip=10.0.1.113         
/usr/bin/inotifywait -mrq --timefmt %y/%m'%d %H:/%M' --format '%T %w%f' -emodify,create,attrib $path1 | while read file;
do
rsync -avz $path1  root@$ip:/backup
echo "${file} was rsynced" >> /var/log/rsync.log 2>&1
done


给予执行权限
chmod +x in.sh
bash in.sh









 代码注解


#!/bin/bash
path1=/data/web
ip=10.0.1.111         填的是rsync灾备服务器ip
/usr/bin/inotifywait -mrq --timefmt %y/%m'%d %H:/%M' --format '%T %w%f' -emodify,create,attrib $path1 | while read file;
do
rsync -avz $path1  root@$ip:/backup
echo "${file} was rsynced" >> /var/log/rsync.log 2>&1
done

 
 -emodify,  修改文件
 create, 创建
 attrib   修改属性
 
 自己也可以定义一下删除,这里我们是备份并监控
 delete
 






服务端
[root@web1 backup]# ls
data  hosts  passwd  web  www_2024-03-20.tar.gz

此时服务端应是已经配置过的服务端 因为它是灾备服务器 rsync都应该已经安装过来了

主要我们是在客户端写个脚本,监控他实时备份的过程
监控其他客户端的过程,实时的过程









效果测试:


客户端

此时你再打开一个窗口,开第二个窗口

用touch新建文件就可以了
再去看脚本的运行监控情况


[root@web02 ~]# cd /data/sh/
[root@web02 sh]# ls
backup.sh  in.sh
[root@web02 sh]# bash in.sh 
sending incremental file list
web/
web/1
web/10
web/100
web/11
web/12
web/13
web/14
web/15
web/16
web/17
web/18
web/19
web/2
web/20
web/21
web/22
web/23
web/24
web/25
web/26
web/27
web/28
web/29
web/3
web/30
web/31
web/32
web/33
web/34
web/35
web/36
web/37
web/38
web/39
web/4
web/40
web/41
web/42
web/43
web/44
web/45
web/46
web/47
web/48
web/49
web/5
web/50
web/51
web/52
web/53
web/54
web/55
web/56
web/57
web/58
web/59
web/6
web/60
web/61
web/62
web/63
web/64
web/65
web/66
web/67
web/68
web/69
web/7
web/70
web/71
web/72
web/73
web/74
web/75
web/76
web/77
web/78
web/79
web/8
web/80
web/81
web/82
web/83
web/84
web/85
web/86
web/87
web/88
web/89
web/9
web/90
web/91
web/92
web/93
web/94
web/95
web/96
web/97
web/98
web/99
web/{1.10}.txt

sent 5,039 bytes  received 1,939 bytes  13,956.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,396 bytes  received 17 bytes  2,826.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list
web/
web/1.txt
web/10.txt
web/2.txt
web/3.txt
web/4.txt
web/5.txt
web/6.txt
web/7.txt
web/8.txt
web/9.txt

sent 1,938 bytes  received 210 bytes  4,296.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,575 bytes  received 17 bytes  3,184.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  1,058.67 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,575 bytes  received 17 bytes  3,184.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,575 bytes  received 17 bytes  3,184.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,571 bytes  received 17 bytes  3,176.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,575 bytes  received 17 bytes  3,184.00 bytes/sec
total size is 0  speedup is 0.00






服务端

[root@web1 ~]# cd /backup/web/
[root@web1 web]# ls
[root@web1 web]# ls
1           14     20  28     34     40  48     54     60  68     74     80  88     94
10          15     21  29     35     41  49     55     61  69     75     81  89     95
100         16     22  2.txt  36     42  4.txt  56     62  6.txt  76     82  8.txt  96
10.txt      17     23  3      37     43  5      57     63  7      77     83  9      97
11          18     24  30     38     44  50     58     64  70     78     84  90     98
{1.10}.txt  19     25  31     39     45  51     59     65  71     79     85  91     99
12          1.txt  26  32     3.txt  46  52     5.txt  66  72     7.txt  86  92     9.txt
13          2      27  33     4      47  53     6      67  73     8      87  93






注意:这个脚本运行时执行备份和实时同步传输 ,但是如果退出了,就不可以了,没办法实现监控和备份了,

bash in.sh &

[root@web02 sh]# bash in.sh &
[1] 3177


这个命令代表可以可以后台运行,他会给你个进程号
只要执行备份,你这边可以监控到的



演示效果

这两个客户端是一个哦,我分两个窗口打开的
客户端1
[root@web02 web]# touch nnwwqq{1..2}.txt



客户端2


[root@web02 sh]# bash in.sh &
[1] 3177
[root@web02 sh]# sending incremental file list
web/
web/nnwwqq1.txt
web/nnwwqq2.txt

sent 1,869 bytes  received 58 bytes  3,854.00 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list

sent 1,790 bytes  received 17 bytes  3,614.00 bytes/sec
total size is 0  speedup is 0.00





服务器端

[root@web1 web]# ls
1           17     26     35     44     53     62     71     80     9   9.txt        nwq8.txt
10          18     27     36     45     54     63     72     81     90  nnwwqq1.txt  nwq9.txt
100         19     28     37     46     55     64     73     82     91  nnwwqq2.txt
10.txt      1.txt  29     38     47     56     65     74     83     92  nwq10.txt
11          2      2.txt  39     48     57     66     75     84     93  nwq1.txt
{1.10}.txt  20     3      3.txt  49     58     67     76     85     94  nwq2.txt
12          21     30     4      4.txt  59     68     77     86     95  nwq3.txt
13          22     31     40     5      5.txt  69     78     87     96  nwq4.txt
14          23     32     41     50     6      6.txt  79     88     97  nwq5.txt
15          24     33     42     51     60     7      7.txt  89     98  nwq6.txt
16          25     34     43     52     61     70     8      8.txt  99  nwq7.txt







需求:
比方说如果你想要他在每5分钟执行

此时就要配置定时任务了,用到crond这个工具




1.
编辑crontab文件
crontab -e



2.
5 * * * * /bin/bash /data/sh/in.sh
在每天的凌晨2点0分(0 2)执行/data/sh/in.sh这个脚本。


3.
确保脚本有执行权限
chmod +x /data/sh/in.sh

4.
检查cron服务状态
crontab -l









具体演示过程

[root@web02 sh]# crontab -e
crontab: installing new crontab
添加下面这行

0 2 * * * /bin/bash /data/sh/in.sh >/dev/null 2>&1

检查一下
[root@web02 sh]# crontab -l
*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1
#time sync by lidao at 2017-03-08
*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1
5 * * * * /bin/bash /data/sh/in.sh >/dev/null 2>&1






2 .测试 邮件报警发送

测试你的邮箱能收到邮件

echo "nginx服务挂了" | mailx -s "预警" 123@qq.com

准备

准备邮箱图示

img

img

img

img

img

SQRLLCVNTQXQHAQX这个是授权码唯一的这就不展示了

服务器地址:

POP3服务器: pop.163.com

SMTP服务器: smtp.163.com

IMAP服务器: imap.163.com


                邮件
 
 linux服务器---企业邮箱163 -----运维人员(QQ邮箱)




准备:
安装postfix       yum -y install postfix
安装mailx          yum install mailx -y

启用postfix          systemctl enable postfix
                     systemctl start postfix
关闭防火墙             systemctl stop firewalld  
selinux                getenforce 0


 systemctl stop firewalld
 getenforce 0

 systemctl enable postfix
 systemctl restart postfix
 systemctl status postfix



1.配置163企业邮箱
2.编写linux服务邮件相关配置文件
[root@master ~]# vi /etc/mail.rc


set smtp-auth-user=用户名@163.com
set smtp-auth-password=客户端授权密码
set smtp-auth=login


set from=15178374440@163.com  你自己的账户
set smtp=smtp.163.com   填写配置的邮箱
set smtp-auth-user=15178374440@163.com  自己的账户
set smtp-auth-password=SQRLLCVNTQXQHAQX   授权码唯一 (为了安全所以这个是无效的授权码)
set smtp-auth=login  自动登录





[root@master ~]# vim /etc/mail.rc
把下面这个粘贴进去,如果粘贴格式有问题 ,可以用:set paste 模式确保粘贴不会出现问题


set from=15178374440@163.com
set smtp=smtp.163.com
set smtp-auth-user=15178374440@163.com
set smtp-auth-password=SQRLLCVNTQXQHAQX
set smtp-auth=login
[root@master ~]# systemctl restart postfix.service




3.发送邮件测试
echo "系统有异常问题,请检查系统" |mail -s "异常警告" 15178374440@163.com
echo "nginx服务挂了" | mailx -s "预警" 15178374440@163.com

cat /etc/hosts | mailx -s "Hosts File Content" 15178374440@163.com
cat /etc/hosts | mailx -s "Hosts File Content" 3078499367@qq.com

也可以目录信息发送到邮箱里








具体过程演示



[root@web ~]# yum -y install postfix
Loaded plugins: fastestmirror
base                                                                                | 3.6 kB  00:00:00     
extras                                                                              | 2.9 kB  00:00:00     
updates                                                                             | 2.9 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be updated
---> Package postfix.x86_64 2:2.10.1-9.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package                 Arch                   Version                         Repository            Size
===========================================================================================================
Updating:
 postfix                 x86_64                 2:2.10.1-9.el7                  base                 2.4 M

Transaction Summary
===========================================================================================================
Upgrade  1 Package

Total download size: 2.4 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
postfix-2.10.1-9.el7.x86_64.rpm                                                     | 2.4 MB  00:00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 2:postfix-2.10.1-9.el7.x86_64                                                           1/2 
  Cleanup    : 2:postfix-2.10.1-6.el7.x86_64                                                           2/2 
  Verifying  : 2:postfix-2.10.1-9.el7.x86_64                                                           1/2 
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                                           2/2 

Updated:
  postfix.x86_64 2:2.10.1-9.el7                                                                            

Complete!
[root@web ~]# yum install mailx -y
Loaded plugins: fastestmirror
base                                                                                | 3.6 kB  00:00:00     
extras                                                                              | 2.9 kB  00:00:00     
updates                                                                             | 2.9 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package mailx.x86_64 0:12.5-19.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package                Arch                    Version                        Repository             Size
===========================================================================================================
Installing:
 mailx                  x86_64                  12.5-19.el7                    base                  245 k

Transaction Summary
===========================================================================================================
Install  1 Package

Total download size: 245 k
Installed size: 466 k
Downloading packages:
mailx-12.5-19.el7.x86_64.rpm                                                        | 245 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mailx-12.5-19.el7.x86_64                                                                1/1 
warning: /etc/mail.rc created as /etc/mail.rc.rpmnew
  Verifying  : mailx-12.5-19.el7.x86_64                                                                1/1 

Installed:
  mailx.x86_64 0:12.5-19.el7                                                                               

Complete!

[root@web ~]# systemctl stop firewalld
[root@web ~]# getenforce 0
Disabled
[root@web ~]# systemctl enable postfix
[root@web ~]# systemctl restart postfix
[root@web ~]# systemctl status postfix
postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled)
   Active: active (running) since Thu 2024-03-21 11:33:18 CST; 11s ago
  Process: 12325 ExecStop=/usr/sbin/postfix stop (code=exited, status=0/SUCCESS)
  Process: 12341 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 12338 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 12335 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
 Main PID: 12413 (master)
   CGroup: /system.slice/postfix.service
           ├─12413 /usr/libexec/postfix/master -w
           ├─12414 pickup -l -t unix -u
           └─12415 qmgr -l -t unix -u

Mar 21 11:33:18 web systemd[1]: Starting Postfix Mail Transport Agent...
Mar 21 11:33:18 web postfix/postfix-script[12411]: starting the Postfix mail system
Mar 21 11:33:18 web postfix/master[12413]: daemon started -- version 2.10.1, configuration /etc/postfix
Mar 21 11:33:18 web systemd[1]: Started Postfix Mail Transport Agent.




[root@web ~]# echo "系统有异常问题,请检查系统" |mail -s "异常警告" 15178374440@163.com
[root@web ~]# echo "nginx服务挂了" | mailx -s "预警" 15178374440@163.com

这条命令是别的邮箱给添加进去,这样你可以发送到别的邮箱了,当然你不加也可以的
[root@web ~]# cat /etc/hosts | mailx -s "Hosts File Content" 3078499367@qq.com
[root@web ~]# echo "nginx服务挂了" | mailx -s "预警" 3078499367@qq.com



总结:现在你的服务端的邮件服务器就是163邮箱服务了,任何你发出去的邮箱都是163为邮件服务发送出去的
邮件测试效果

img

img

posted @   三思博客  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示