学习linux第三十八天

[root@hanlin2 /]# vim /etc/rsyncd.conf (rsync默认的配置文件)

port=873 (指定端口号)
log file=/var/log/rsync.log
pid file=/var/run/rsyncd.pid
address=192.168.3.137
[test] (模块的名字,替代路径)
path=/tmp/rsync (具体的路径)
use chroot=true     (限定在当前路径,针对软连接)
max connections=4
read only=no
list=true
uid=root
gid=root
#auth users=test
#secrets file=/etc/rsyncd.passwd
hosts allow=192.168.3.136(允许哪些ip就访问或者被访问,可以单独ip用空格分离也可以是ip段比如3.0/24 4.0/24)

 

 

rsync --daemon  开启服务
 ps -aux |grep rsync (检测rsync进程是否工作)
netstat -lntp              (检测rsync默认的873端口是否正常工作

 

 systemctl stop firewalld.service  (关闭防火墙)
telnet 192.168.3.137 873 (测试网络连通性)

 

改端口再同步到远程

 

[root@hanlin2 rsync]# vim /etc/rsyncd.conf (改端口 port=8730)
[root@hanlin2 rsync]# ps -aux |grep rsync 
root 4254 0.0 0.0 114652 536 ? Ss 17:55 0:00 rsync --daemon
root 7668 0.0 0.0 112676 984 pts/0 S+ 23:12 0:00 grep --color=auto rsync
[root@hanlin2 rsync]# killall rsync (杀掉跟rsync有关的进程)
[root@hanlin2 rsync]# ps -aux |grep rsync
root 7671 0.0 0.0 112676 984 pts/0 S+ 23:12 0:00 grep --color=auto rsync
[root@hanlin2 rsync]# rsync --daemon(重新 启动rsync进程)
[root@hanlin2 rsync]# ps -aux |grep rsync 
root 7715 0.0 0.0 114652 524 ? Ss 23:12 0:00 rsync --daemon
root 7717 0.0 0.0 112676 984 pts/0 S+ 23:12 0:00 grep --color=auto rsync
[root@hanlin2 rsync]# netstat -lntp (重新检测端口号,发现已经更新掉)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name 
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd 
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1222/dnsmasq 
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1023/sshd 
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1025/cupsd 
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1153/master 
tcp 0 0 192.168.3.137:8730 0.0.0.0:* LISTEN 7715/rsync 
tcp6 0 0 :::111 :::* LISTEN 1/systemd 
tcp6 0 0 :::22 :::* LISTEN 1023/sshd 
tcp6 0 0 ::1:631 :::* LISTEN 1025/cupsd 
tcp6 0 0 ::1:25 :::* LISTEN 1153/master 

[root@hanlinxy tmp]# rsync -avP --port=8730 /tmp/xy.xy 192.168.3.137::test/xy2.xy (指定端口同步到远程)
sending incremental file list

sent 38 bytes received 11 bytes 98.00 bytes/sec
total size is 0 speedup is 0.00

 

rsyncd.conf配置文件详解

port:指定在哪个端口启动rsyncd服务,默认是873端口。

log file:指定日志文件。

pid file:指定pid文件,这个文件的作用涉及服务的启动、停止等进程管理操作。

address:指定启动rsyncd服务的IP。假如你的机器有多个IP,就可以指定由其中一个启动rsyncd服务,如果不指定该参数,默认是在全部IP上启动。

[]:指定模块名,里面内容自定义。

path:指定数据存放的路径。

use chroot true|false:表示在传输文件前首先chroot到path参数所指定的目录下。这样做的原因是实现额外的安全防护,但缺点是需要以roots权限,并且不能备份指向外部的符号连接所指向的目录文件。默认情况下chroot值为true,如果你的数据当中有软连接文件,阿铭建议你设置成false。

max connections:指定最大的连接数,默认是0,即没有限制。

read only ture|false:如果为true,则不能上传到该模块指定的路径下。

list:表示当用户查询该服务器上的可用模块时,该模块是否被列出,设定为true则列出,false则隐藏。

(查询用[root@hanlinxy tmp]# rsync -avP --port=8730 192.168.3.137::
test 改成FALSE有利于安全)

uid/gid:指定传输文件时以哪个用户/组的身份传输。

auth users:指定传输时要使用的用户名。

secrets file:指定密码文件,该参数连同上面的参数如果不指定,则不使用密码验证。注意该密码文件的权限一定要是600。格式:用户名:密码

hosts allow:表示被允许连接该模块的主机,可以是IP或者网段,如果是多个,中间用空格隔开。

当设置了auth users和secrets file后,客户端连服务端也需要用用户名密码了,若想在命令行中带上密码,可以设定一个密码文件

 

指定用户同步

[root@hanlin2 etc]# vim /etc/rsyncd.conf 

auth users=test
secrets file=/etc/rsyncd.passwd
[root@hanlin2 etc]# cat rsyncd.passwd (创建密码文件,输入以下账号和密码)
test:123456a.
[root@hanlin2 etc]# chmod 600 /etc/rsyncd.passwd (设置密码文件权限)

[root@hanlinxy tmp]# rsync -avP --port=8730 /tmp/xy.xy test@192.168.3.137::test/xy2.xy
Password: 
sending incremental file list

 

sent 38 bytes received 11 bytes 19.60 bytes/sec
total size is 0 speedup is 0.00

 

免密输入

在客户端创建密码文件

[root@hanlinxy xy]# cat /etc/rsync.passwd 
[root@hanlinxy xy]# echo "123456a." >!$
echo "123456a." >/etc/rsync.passwd
[root@hanlinxy xy]# cat /etc/rsync.passwd 
123456a.

 

[root@hanlinxy xy]# chmod 600 /etc/rsync.passwd 
服务端指定密码文件

[root@hanlinxy xy]# rsync -avP --port=8730 /tmp/xy.xy --password-file=/etc/rsync.passwd (指定密码文件)test@192.168.3.137::test/xy2.xy
sending incremental file list

 

sent 38 bytes received 11 bytes 98.00 bytes/sec
total size is 0 speedup is 0.00

linux系统日志

 

[root@hanlinxy xy]# less /var/log/messages (查看系统日志)
[root@hanlinxy xy]# cat /etc/logrotate.conf  (系统日志切割机制配置文件)
# see "man logrotate" for details
# rotate log files weekly
weekly (每周切割一次)
# keep 4 weeks worth of backlogs
rotate 4 (切割四次)
# create new (empty) log files after rotating old ones
create (创建新的文件)
# use date as a suffix of the rotated file
dateext (文件的后缀名)
# uncomment this if you want your log files compressed
#compress (是否压缩)
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d (其他的切割配置文件)
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
minsize 1M
rotate 1
}

/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 1
}

# system-specific logs may be also be configured here.


[root@hanlinxy ~]# ls /var/log/messages* 
/var/log/messages /var/log/messages-20180610 /var/log/messages-20180625
/var/log/messages-20180604 /var/log/messages-20180617
 

[root@hanlinxy ~]# ls /etc/logrotate.d
bootlog cups libvirtd numad psacct syslog yum
chrony iscsiuiolog libvirtd.qemu ppp samba wpa_supplicant
[root@hanlinxy ~]# cat /etc/logrotate.d/syslog 
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
missingok
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true (重新加载服务)
endscript
}
 

[root@hanlinxy ~]# dmesg  (关于系统硬件的日志)

[root@hanlinxy ~]# dmesg  -c (临时先清空内存中的硬件日志)

[root@hanlinxy ~]# less /var/log/dmesg (关于系统启动时的日志)
 

[root@hanlinxy ~]# last (调用/var/log/wtmp 显示最近所有登入重启成功的记录)
root pts/0 192.168.3.99 Fri Jun 29 15:20 still logged in 
reboot system boot 3.10.0-693.el7.x Fri Jun 29 15:18 - 15:32 (00:13) 
root pts/0 192.168.3.99 Fri Jun 29 13:52 - crash (01:26) 
root pts/1 192.168.3.99 Thu Jun 28 14:00 - 11:37 (21:36) 
root pts/0 192.168.3.99 Thu Jun 28 14:00 - 13:48 (23:47) 
root tty1 Thu Jun 28 13:48 - 14:55 (1+01:06) 

 

[root@hanlinxy ~]# lastb (调用/var/log/btmp,显示所有失败登入的记录)
(unknown tty1 Thu Jun 28 13:48 - 13:48 (00:00) 
root ssh:notty 192.168.3.99 Thu Jun 21 15:08 - 15:08 (00:00) 
root ssh:notty 192.168.3.99 Thu Jun 21 15:07 - 15:07 (00:00) 
root ssh:notty 192.168.3.99 Thu Jun 21 15:07 - 15:07 (00:00) 
root ssh:notty 192.168.3.99 Thu Jun 21 15:07 - 15:07 (00:00) 
root ssh:notty 192.168.3.99 Thu Jun 21 15:07 - 15:07 (00:00) 
root pts/0 Fri Jun 8 14:37 - 14:37 (00:00) 

[root@hanlinxy ~]# less /var/log/secure (记录每一次登入记录,成功的失败的都会被记录)
 

 

 

screen (相当于是一个后台终端)

 

[root@hanlinxy ~]# yum -y install screen 
已加载插件:fastestmirror, langpacks
base | 3.6 kB 00:00:00 
epel/x86_64/metalink | 6.1 kB 00:00:00 
epel | 3.2 kB 00:00:00 
extras | 3.4 kB 00:00:00 
updates | 3.4 kB 00:00:00 
(1/2): epel/x86_64/updateinfo | 924 kB 00:00:00 
(2/2): epel/x86_64/primary | 3.5 MB 00:00:03 
Loading mirror speeds from cached hostfile
* epel: mirror.premi.st
epel 12603/12603
正在解决依赖关系
--> 正在检查事务
---> 软件包 screen.x86_64.0.4.1.0-0.25.20120314git3c2946.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

============================================================================================
Package 架构 版本 源 大小
============================================================================================
正在安装:
screen x86_64 4.1.0-0.25.20120314git3c2946.el7 base 552 k

事务概要
============================================================================================
安装 1 软件包

总下载量:552 k
安装大小:914 k
Downloading packages:
screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm | 552 kB 00:00:01 
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : screen-4.1.0-0.25.20120314git3c2946.el7.x86_64 1/1 
验证中 : screen-4.1.0-0.25.20120314git3c2946.el7.x86_64 1/1 

已安装:
screen.x86_64 0:4.1.0-0.25.20120314git3c2946.el7 

完毕!
[root@hanlinxy ~]# screen (进入后台)
[detached from 2136.pts-0.hanlinxy] (已经执行了一条命令,编号是2136,在screen里切除ctrl a+d,退出exit

[root@hanlinxy ~]# screen -ls (查看后台的命令有几条)
There is a screen on:
2136.pts-0.hanlinxy (Detached)
1 Socket in /var/run/screen/S-root.

[root@hanlinxy ~]# screen -r 2136 (重新进入放入后台的终端screen里的命令)
[detached from 2136.pts-0.hanlinxy]
[root@hanlinxy ~]# screen -S 212 (给要进的终端起个名字,再进入时可以通过2244也可以通过212)
[detached from 2244.212]
[root@hanlinxy ~]# screen -ls 
There is a screen on:
2244.212 (Detached)
1 Socket in /var/run/screen/S-root.

 

 

转载于:https://my.oschina.net/u/3867255/blog/1859666

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值