红帽7使用systemd
实验-systemctl控制服务
yum install httpd -y
systemctl status httpd #查看状态
systemctl start httpd #启动服务
systemctl stop httpd #停止服务
systemctl restart httpd #重启服务
systemctl reload httpd #重新读取配置文件
systemctl enable httpd #开机启动
systemctl disable httpd #开机不启动
systemctl is-enabled httpd #查看开机是否启动
systemctl is-active httpd #查看状态
systemctl mask httpd #mask服务
systemctl umask httpd #umask服务
systemctl list-dependencies httpd #查看服务的依赖性关系
systemctl list-unit-files --type service | grep htpd
ps aux | grep httpd
pstree #开机自动启动的服务
实验-systemctl控制启动级别
0 关机 poweroff.target runlevel0.target
1 单用户 rescue.target runlevel1.target
3 多用户 multi-user.target runlevel3.target
5 图形化用户 graphical.target runlevel5.target
6 重启 reboot.target runlevel6.target
vim /etc/inittab
systemctl get-default
systemctl isolate multi-user.target
systemctl set-default multi-user.target
systemctl list-unit-files --type target | grep runleve
systemctl isolate runlevel3.target
实验-ssh基础操作
在rhel7-1上
systemctl stop firewalld.service
setenforce 0
infonfig eno16777736 192.168.100.1/24
在rhel7-2上
systemctl stop firewalld.service
setenforce 0
ssh 192.168.100.1
ssh root@192.168.100.1
scp /etc/fstab root@192.168.100.1:/home/ #远程拷贝(红帽7默认安装着lrzsz,红帽6需要安装)
scp -r 192.168.100.1:/home/ /han
实验--Windows远程ssh连接工具
CRT
xshell
实验-ssh禁止root直接登入
在rhel7-1上
systemctl stop firewalld.service
setenforce 0
ifconfig eno16777736 192.168.100.1/24
vim /etc/ssh/sshd_config
PermitRoot no #不允许root登入
systemctl restart sshd.service
在rhel7-2上
systemctl stop firewalld.service
setenforce 0
ifconfig eno16777736 192.168.100.2/24
ssh 192.168.100.1 #拒绝
ssh han@192.168.100.1
su - root #可以从han登入root
实验-ssh免密码登入
在rhel7-1上
systemctl stop firewalld.service
setenforce 0
ifconfig eno16777736 192.168.100.1/24
useradd han1
echo 123456 | passwd --stdin han1
ll -a /home/han1
su - han1
vim /etc/ssh/sshd_config
PasswordAuthentication no #禁止用户通过密码认证(但是可以通过秘钥登入)
systemctl restart sshd.service
在rhel7-2上
systemctl stop firewalld.service
setenforce 0
ifconfig eno16777736 192.168.100.2/24
useradd han2
echo 123456 | passwd --stdin han2
su - han2
ssh-keygen
ll -a /home/han2
ssh-copy-id han1@192.168.100.1
ssh han1@192.168.100.1 #实现无密码登入
实验-一次性计划任务(使用的较少)
systemctl status atd.service
at 时间
at> 任务的描述
ctrl+d
例如:
at 6pm Monday
at now + 5 minutes
at 13:15 05/12/2018
atq #查看当前用户在等待的计划任务
atrm <任务号> #删除计划任务
echo han >> /etc/at.deny #阻止那些用户使用at
su - han
at 18:00 #无权使用at
实验-周期性计划任务(使用的较多)
vim /han.sh #shell脚本
#!/bin/bash
touch /file`date+%F`
chmod o+x /han.sh
时间表配置文件的格式
* * * * * 指令( 使用绝对路径)
每分钟 每小时 每天 每月 每周星期几
时间数值的特殊表示方法
* 表示该范围内的任意时间
, 表示间隔的多个不连续的时间点
- 表示一个连续的时间范围
/ 指定间隔的时间频率
应用实例
0 17 * * 1-5 周一到周五每天的17:00
30 8 * * 1,3,5 每周的周一,三,五的8点30分
0 8-18/2 * * * 8点到18点之间每隔2小时
0 * */3 * * 每隔三天
systemctl status crond.service
crontab -e (-u root) #指定用户的周期性计划
30 2 */2 * * /han.sh #描述
crontab -l (-u root) #查看任务
crontab -r (-u root) #删除任务(所有的计划任务都被删除)
echo han >> /etc/cron.deny #不允许用户han做周期性计划任务(红帽7只有deny,红帽6还有allow)
su - han
crontab -e #不允许使用此程序
系统本身的计划任务
vim /etc/cron. #包括每天/每周的任务