update docs

This commit is contained in:
Zhang Peng 2020-02-11 13:11:30 +08:00
parent e963f5e234
commit c1e96a7134
9 changed files with 526 additions and 292 deletions

View File

@ -17,11 +17,7 @@
>
> 📖 [电子书](https://dunwu.github.io/linux-tutorial/) | [电子书(国内)](http://turnon.gitee.io/linux-tutorial/)
| 📖 | 🐚 | 📚 |
| :-----------: | :-----------: | :-----------: |
| [文章](#文章) | [脚本](#脚本) | [资源](#资源) |
## 文章
## 📖 内容
### Linux 命令
@ -41,8 +37,11 @@
> Linux 系统的常见运维工作。
- [linux 典型运维应用](docs/linux/ops/linux-base-ops.md) - 关键词域名解析、防火墙、网卡、NTP、crontab
- [网络运维](docs/linux/ops/network-ops.md)
- [Samba](docs/linux/ops/samba.md)
- [NTP](docs/linux/ops/ntp.md)
- [Firewalld](docs/linux/ops/firewalld.md)
- [Crontab](docs/linux/ops/crontab.md)
- [Systemd](docs/linux/ops/systemd.md)
- [Vim](docs/linux/ops/vim.md)
- [Iptables](docs/linux/ops/iptables.md)
@ -52,7 +51,7 @@
> 部署在 Linux 系统上的软件运维。
>
> 配套安装脚本:🐚 [软件运维配置脚本集合](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/soft)
> 配套安装脚本: [软件运维配置脚本集合](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/soft)
- 开发环境
- [JDK 安装](docs/linux/soft/jdk-install.md)
@ -71,9 +70,9 @@
- [Zookeeper 运维](https://github.com/dunwu/javatech/blob/master/docs/technology/monitor/zookeeper-ops.md)
- [Nacos 运维](docs/linux/soft/nacos-install.md)
- 服务器
- [Nginx 教程 📚](https://github.com/dunwu/nginx-tutorial)
- [Nginx 教程](https://github.com/dunwu/nginx-tutorial) 📚
- [Tomcat 运维](docs/linux/soft/tomcat-install.md)
- [数据库 📚](https://github.com/dunwu/db-tutorial)
- [数据库](https://github.com/dunwu/db-tutorial) 📚
- [Mysql 运维](https://github.com/dunwu/db-tutorial/blob/master/docs/sql/mysql/mysql-ops.md)
- [Redis 运维](https://github.com/dunwu/db-tutorial/blob/master/docs/nosql/redis/redis-ops.md)
@ -90,21 +89,21 @@
- [一篇文章让你彻底掌握 Shell](https://github.com/dunwu/blog/blob/master/source/_posts/coding/shell.md)
- [Git 从入门到精通](https://github.com/dunwu/blog/blob/master/source/_posts/tools/git.md)
## 脚本
## 脚本
### Shell 脚本大全
**Shell 脚本大全** 精心收集、整理了 Linux 环境下的常见 Shell 脚本操作片段。
源码:[**Shell 脚本大全**](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/sys)
源码:[**Shell 脚本大全**](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell)
### CentOS 运维脚本集合
本人作为一名 Java 后端,苦于经常在 CentOS 环境上开荒虚拟机。为提高效率,写了一套 Shell 脚本,提供如下功能:安装常用 lib 库、命令工具、设置 DNS、NTP、配置国内 yum 源、一键安装常用软件等。
源码:[**CentOS 常规操作运维脚本集合**](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/sys)
源码:[**CentOS 常规操作运维脚本集合**](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux)
## 资源
## 📚 资料
- **Linux 命令**
- [命令行的艺术](https://github.com/jlevy/the-art-of-command-line/blob/master/README-zh.md)

View File

@ -1,14 +1,13 @@
<p align="center">
<a href="https://dunwu.github.io/linux-tutorial/" target="_blank" rel="noopener noreferrer">
<img src="http://dunwu.test.upcdn.net/common/logo/linux.svg" alt="logo" width="100px">
</a>
</p>
---
home: true
heroImage: /images/dunwu-logo-200.png
heroText: LINUX-TUTORIAL
tagline: 📚 linux-tutorial 是一个 Linux 教程。
actionLink: /
footer: CC-BY-SA-4.0 Licensed | Copyright © 2018-Now Dunwu
---
<p align="center">
<img src="https://badgen.net/github/license/dunwu/linux-tutorial" alt="license">
</p>
<h1 align="center">linux-tutorial</h1>
# Linux 教程
> 📚 **linux-tutorial** 是一个 Linux 教程。
>
@ -16,136 +15,92 @@
>
> 📖 [电子书](https://dunwu.github.io/linux-tutorial/) | [电子书(国内)](http://turnon.gitee.io/linux-tutorial/)
| 📖 | 🐚 | 📚 |
| :-----------: | :-----------: | :-----------: |
| [文章](#文章) | [脚本](#脚本) | [资源](#资源) |
## 文章
## 📖 内容
### Linux 命令
> 学习 Linux 的第一步:当然是从 [Linux 命令](linux/cli/README.md) 入手了。
> 学习 Linux 的第一步:当然是从 [Linux 命令](docs/linux/cli/README.md) 入手了。
- [查看 Linux 命令帮助信息](linux/cli/linux-cli-help.md) - 关键词:`help`, `whatis`, `info`, `which`, `whereis`, `man`
- [Linux 文件目录管理](linux/cli/linux-cli-dir.md) - 关键词:`cd`, `ls`, `pwd`, `mkdir`, `rmdir`, `tree`, `touch`, `ln`, `rename`, `stat`, `file`, `chmod`, `chown`, `locate`, `find`, `cp`, `mv`, `rm`
- [Linux 文件内容查看命令](linux/cli/linux-cli-file.md) - 关键词:`cat`, `head`, `tail`, `more`, `less`, `sed`, `vi`, `grep`
- [Linux 文件压缩和解压](linux/cli/linux-cli-file-compress.md) - 关键词:`tar`, `gzip`, `zip`, `unzip`
- [Linux 用户管理](linux/cli/linux-cli-user.md) - 关键词:`groupadd`, `groupdel`, `groupmod`, `useradd`, `userdel`, `usermod`, `passwd`, `su`, `sudo`
- [Linux 系统管理](linux/cli/linux-cli-system.md) - 关键词:`reboot`, `exit`, `shutdown`, `date`, `mount`, `umount`, `ps`, `kill`, `systemctl`, `service`, `crontab`
- [Linux 网络管理](linux/cli/linux-cli-net.md) - 关键词:关键词:`curl`, `wget`, `telnet`, `ip`, `hostname`, `ifconfig`, `route`, `ssh`, `ssh-keygen`, `firewalld`, `iptables`, `host`, `nslookup`, `nc`/`netcat`, `ping`, `traceroute`, `netstat`
- [Linux 硬件管理](linux/cli/linux-cli-hardware.md) - 关键词:`df`, `du`, `top`, `free`, `iotop`
- [Linux 软件管理](linux/cli/linux-cli-hardware.md) - 关键词:`rpm`, `yum`, `apt-get`
- [查看 Linux 命令帮助信息](docs/linux/cli/linux-cli-help.md) - 关键词:`help`, `whatis`, `info`, `which`, `whereis`, `man`
- [Linux 文件目录管理](docs/linux/cli/linux-cli-dir.md) - 关键词:`cd`, `ls`, `pwd`, `mkdir`, `rmdir`, `tree`, `touch`, `ln`, `rename`, `stat`, `file`, `chmod`, `chown`, `locate`, `find`, `cp`, `mv`, `rm`
- [Linux 文件内容查看命令](docs/linux/cli/linux-cli-file.md) - 关键词:`cat`, `head`, `tail`, `more`, `less`, `sed`, `vi`, `grep`
- [Linux 文件压缩和解压](docs/linux/cli/linux-cli-file-compress.md) - 关键词:`tar`, `gzip`, `zip`, `unzip`
- [Linux 用户管理](docs/linux/cli/linux-cli-user.md) - 关键词:`groupadd`, `groupdel`, `groupmod`, `useradd`, `userdel`, `usermod`, `passwd`, `su`, `sudo`
- [Linux 系统管理](docs/linux/cli/linux-cli-system.md) - 关键词:`reboot`, `exit`, `shutdown`, `date`, `mount`, `umount`, `ps`, `kill`, `systemctl`, `service`, `crontab`
- [Linux 网络管理](docs/linux/cli/linux-cli-net.md) - 关键词:关键词:`curl`, `wget`, `telnet`, `ip`, `hostname`, `ifconfig`, `route`, `ssh`, `ssh-keygen`, `firewalld`, `iptables`, `host`, `nslookup`, `nc`/`netcat`, `ping`, `traceroute`, `netstat`
- [Linux 硬件管理](docs/linux/cli/linux-cli-hardware.md) - 关键词:`df`, `du`, `top`, `free`, `iotop`
- [Linux 软件管理](docs/linux/cli/linux-cli-software.md) - 关键词:`rpm`, `yum`, `apt-get`
### Linux 系统运维
### Linux 运维
> Linux 系统的常见运维工作。
- [linux 典型运维应用](linux/ops/linux-base-ops.md) - 关键词域名解析、防火墙、网卡、NTP、crontab
- [Samba 应用](linux/ops/samba.md)
- [Systemd 应用](linux/ops/systemd.md)
- [Vim 应用](linux/ops/vim.md)
- [Iptables 应用](linux/ops/iptables.md)
- [oh-my-zsh 应用](linux/ops/zsh.md)
- [网络运维](docs/linux/ops/network-ops.md)
- [Samba](docs/linux/ops/samba.md)
- [NTP](docs/linux/ops/ntp.md)
- [Firewalld](docs/linux/ops/firewalld.md)
- [Crontab](docs/linux/ops/crontab.md)
- [Systemd](docs/linux/ops/systemd.md)
- [Vim](docs/linux/ops/vim.md)
- [Iptables](docs/linux/ops/iptables.md)
- [oh-my-zsh](docs/linux/ops/zsh.md)
### 软件运维
> 部署在 Linux 系统上的软件运维。
>
> 配套安装脚本:🐚 [软件运维配置脚本集合](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/soft)
> 配套安装脚本: [软件运维配置脚本集合](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/soft)
- 开发环境
- [JDK 安装](linux/soft/jdk-install.md)
- [Maven 安装](linux/soft/maven-install.md)
- [Nodejs 安装](linux/soft/nodejs-install.md)
- [JDK 安装](docs/linux/soft/jdk-install.md)
- [Maven 安装](docs/linux/soft/maven-install.md)
- [Nodejs 安装](docs/linux/soft/nodejs-install.md)
- 开发工具
- [Nexus 运维](linux/soft/nexus-ops.md)
- [Gitlab 运维](linux/soft/kafka-install.md)
- [Jenkins 运维](linux/soft/jenkins.md)
- [Svn 运维](linux/soft/svn-ops.md)
- [YApi 运维](linux/soft/yapi-ops.md)
- [Nexus 运维](docs/linux/soft/nexus-ops.md)
- [Gitlab 运维](docs/linux/soft/kafka-install.md)
- [Jenkins 运维](docs/linux/soft/jenkins.md)
- [Svn 运维](docs/linux/soft/svn-ops.md)
- [YApi 运维](docs/linux/soft/yapi-ops.md)
- 中间件服务
- [Elastic 运维](linux/soft/elastic)
- [Kafka 运维](linux/soft/kafka-install.md)
- [RocketMQ 运维](linux/soft/rocketmq-install.md)
- [Elastic 运维](docs/linux/soft/elastic)
- [Kafka 运维](docs/linux/soft/kafka-install.md)
- [RocketMQ 运维](docs/linux/soft/rocketmq-install.md)
- [Zookeeper 运维](https://github.com/dunwu/javatech/blob/master/docs/technology/monitor/zookeeper-ops.md)
- [Nacos 运维](linux/soft/nacos-install.md)
- [Nacos 运维](docs/linux/soft/nacos-install.md)
- 服务器
- [Nginx 教程 📚](https://github.com/dunwu/nginx-tutorial)
- [Tomcat 运维](linux/soft/tomcat-install.md)
- [数据库 📚](https://github.com/dunwu/db-tutorial)
- [Nginx 教程](https://github.com/dunwu/nginx-tutorial) 📚
- [Tomcat 运维](docs/linux/soft/tomcat-install.md)
- [数据库](https://github.com/dunwu/db-tutorial) 📚
- [Mysql 运维](https://github.com/dunwu/db-tutorial/blob/master/docs/sql/mysql/mysql-ops.md)
- [Redis 运维](https://github.com/dunwu/db-tutorial/blob/master/docs/nosql/redis/redis-ops.md)
### 扩展
### Docker
- [Docker 快速入门](docs/docker/docker-quickstart.md)
- [Dockerfile 最佳实践](docs/docker/docker-dockerfile.md)
- [Docker Cheat Sheet](docs/docker/docker-cheat-sheet.md)
- [Kubernetes 应用指南](docs/docker/kubernetes.md)
### 其他
- [Docker 教程](docker/README.md)
- [Docker 快速入门](docker/docker-quickstart.md)
- [Dockerfile 最佳实践](docker/docker-dockerfile.md)
- [Docker Cheat Sheet](docker/docker-cheat-sheet.md)
- [一篇文章让你彻底掌握 Python](https://github.com/dunwu/blog/blob/master/source/_posts/coding/python.md)
- [一篇文章让你彻底掌握 Shell](https://github.com/dunwu/blog/blob/master/source/_posts/coding/shell.md)
- [Git 从入门到精通](https://github.com/dunwu/blog/blob/master/source/_posts/tools/git.md)
## 脚本
## 脚本
### Shell 脚本大全
**Shell 脚本大全** 精心收集、整理了 Linux 环境下的常见 Shell 脚本操作片段。
源码:[**Shell 脚本大全**](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/sys)
源码:[**Shell 脚本大全**](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell)
### CentOS 运维脚本集合
本人作为一名 Java 后端,苦于经常在 CentOS 环境上开荒虚拟机。为提高效率,写了一套 Shell 脚本,提供如下功能:安装常用 lib 库、命令工具、设置 DNS、NTP、配置国内 yum 源、一键安装常用软件等。
源码:[**CentOS 常规操作运维脚本集合**](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/sys)
源码:[**CentOS 常规操作运维脚本集合**](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux)
## 资源
## 🚪 传送门
- **Linux 命令**
- [命令行的艺术](https://github.com/jlevy/the-art-of-command-line/blob/master/README-zh.md)
- [Linux 命令大全](https://man.linuxde.net/)
- [linux-command](https://github.com/jaywcjlove/linux-command)
- **社区网站**
- [Linux 中国](https://linux.cn/) - 各种资讯、文章、技术
- [实验楼](https://www.shiyanlou.com/) - 免费提供了 Linux 在线环境,不用在自己机子上装系统也可以学习 Linux超方便实用。
- [鸟哥的 linux 私房菜](http://linux.vbird.org/) - 非常适合 Linux 入门初学者看的教程。
- [Linux 公社](http://www.linuxidc.com/) - Linux 相关的新闻、教程、主题、壁纸都有。
- [Linux Today](http://www.linuxde.net) - Linux 新闻资讯发布Linux 职业技术学习!。
- **知识相关**
- [Linux 思维导图整理](http://www.jianshu.com/p/59f759207862)
- [Linux 初学者进阶学习资源整理](http://www.jianshu.com/p/fe2a790b41eb)
- [Linux 基础入门(新版)](https://www.shiyanlou.com/courses/1)
- [【译】Linux 概念架构的理解](http://www.jianshu.com/p/c5ae8f061cfe) [En](http://oss.org.cn/ossdocs/linux/kernel/a1/index.html)
- [Linux 守护进程的启动方法](http://www.ruanyifeng.com/blog/2016/02/linux-daemon.html)
- [Linux 编程之内存映射](https://www.shiyanlou.com/questions/2992)
- [Linux 知识点小结](https://blog.huachao.me/2016/1/Linux%E7%9F%A5%E8%AF%86%E7%82%B9%E5%B0%8F%E7%BB%93/)
- [10 大白帽黑客专用的 Linux 操作系统](https://linux.cn/article-6971-1.html)
- **软件工具**
- [超赞的 Linux 软件](https://www.gitbook.com/book/alim0x/awesome-linux-software-zh_cn/details) Github 仓库[Zh](https://github.com/alim0x/Awesome-Linux-Software-zh_CN) [En](https://github.com/VoLuong/Awesome-Linux-Software)
- [程序员喜欢的 9 款最佳的 Linux 文件比较工具](http://os.51cto.com/art/201607/513796.htm)
- [提高 Linux 开发效率的 5 个工具](http://www.codeceo.com/article/5-linux-productivity-tools.html)
- [你要了解的 11 款面向 Linux 系统的一流备份实用工具](http://os.51cto.com/art/201603/508027.htm)
- [16 个很有用的在线工具](http://www.simlinux.com/archives/264.html)
- Adobe 软件的最佳替代品 [原文在这里](https://linux.cn/article-8928-1.html)
- [Evince (Adobe Acrobat Reader)](https://wiki.gnome.org/Apps/Evince) 一个“支持多种文档格式的文档查看器”,可以查看 PDF还支持各种漫画书格式
- [Pixlr (Adobe Photoshop)](https://pixlr.com/) 一个强大的图像编辑工具
- [Inkscape (Adobe Illustrator)](https://inkscape.org/zh/) 一个专业的矢量图形编辑器
- [Pinegrow Web Editor (Adobe Dreamweaver)](https://pinegrow.com/) 一个可视化编辑制作 HTML 网站
- [Scribus (Adobe InDesign)](https://www.scribus.net/) 一个开源电子杂志制作软件
- [Webflow (Adobe Muse)](https://webflow.com/) 一款可以帮助用户不用编码就可以快速创建网站的谷歌浏览器插件。
- [Tupi (Adobe Animate)](http://www.maefloresta.com/portal/) 一款可以创建 HTML5 动画的工具。
- [Black Magic Fusion (Adobe After Effects)](https://www.blackmagicdesign.com) 一款先进的合成软件,广泛应用于视觉特效、广电影视设计以及 3D 动画设计等领域。
- **中国开源镜像**
- [阿里云开源镜像站](http://mirrors.aliyun.com/)
- [网易开源镜像站](http://mirrors.163.com/)
- [搜狐开源镜像站](http://mirrors.sohu.com/)
- [北京交通大学](http://mirror.bjtu.edu.cn/)
- [兰州大学](http://mirror.lzu.edu.cn/)
- [厦门大学](http://mirrors.xmu.edu.cn/)
- [上海交通大学](http://ftp.sjtu.edu.cn/)
- [清华大学](http://mirrors.tuna.tsinghua.edu.cn/)
- [中国科学技术大学](http://mirrors.ustc.edu.cn/)
- [东北大学](http://mirror.neu.edu.cn/)
- [浙江大学](http://mirrors.zju.edu.cn/)
- [东软信息学院](http://mirrors.neusoft.edu.cn/)
◾ 🏠 [DB-TUTORIAL 首页](https://github.com/dunwu/linux-tutorial) ◾ 🎯 [我的博客](https://github.com/dunwu/blog) ◾

View File

@ -1,6 +1,6 @@
# Linux 命令行
## 常用命令
## 📖 内容
- [查看 Linux 命令帮助信息](linux-cli-help.md) - 关键词:`help`, `whatis`, `info`, `which`, `whereis`, `man`
- [Linux 文件目录管理](linux-cli-dir.md) - 关键词:`cd`, `ls`, `pwd`, `mkdir`, `rmdir`, `tree`, `touch`, `ln`, `rename`, `stat`, `file`, `chmod`, `chown`, `locate`, `find`, `cp`, `mv`, `rm`
@ -12,9 +12,12 @@
- [Linux 硬件管理](linux-cli-hardware.md) - 关键词:`df`, `du`, `top`, `free`, `iotop`
- [Linux 软件管理](linux-cli-hardware.md) - 关键词:`rpm`, `yum`, `apt-get`
## 资料
## 📚 资料
- [命令行的艺术](https://github.com/jlevy/the-art-of-command-line/blob/master/README-zh.md)
- [Linux命令大全](https://man.linuxde.net/)
- [linux-command](https://github.com/jaywcjlove/linux-command)
## 🚪 传送门
◾ 🏠 [DB-TUTORIAL 首页](https://github.com/dunwu/linux-tutorial) ◾ 🎯 [我的博客](https://github.com/dunwu/blog) ◾

View File

@ -1,8 +1,17 @@
#
# Linux 系统运维
- [linux 典型运维应用](linux-base-ops.md) - 关键词域名解析、防火墙、网卡、NTP、crontab
## 📖 内容
- [网络运维](network-ops.md)
- [Samba](samba.md)
- [NTP](ntp.md)
- [Firewalld](firewalld.md)
- [Crontab](crontab.md)
- [Systemd](systemd.md)
- [Vim](vim.md)
- [Iptables](iptables.md)
- [oh-my-zsh](zsh.md)
## 🚪 传送门
◾ 🏠 [DB-TUTORIAL 首页](https://github.com/dunwu/linux-tutorial) ◾ 🎯 [我的博客](https://github.com/dunwu/blog) ◾

189
docs/linux/ops/crontab.md Normal file
View File

@ -0,0 +1,189 @@
# 定时任务 - crontab
> 环境CentOS
通过 `crontab` 命令,我们可以在固定的间隔时间执行指定的系统指令或 shell script 脚本。时间间隔的单位可以是分钟、小时、日、月、周及以上的任意组合。这个命令非常适合周期性的日志分析或数据备份等工作。
## crond 服务
Linux 通过 crond 服务来支持 crontab。
### 检查 `crond` 服务
使用 `systemctl list-unit-files` 命令确认 `crond` 服务是否已安装。
```shell
$ systemctl list-unit-files | grep crond
crond.service enabled
```
如果为 enabled表示服务正运行。
### crond 服务命令
开机自动启动 crond 服务:`chkconfig crond on`
或者,按以下命令手动启动:
```shell
systemctl enable crond.service # 开启服务(开机自动启动服务)
systemctl disable crond.service # 关闭服务(开机不会自动启动服务)
systemctl start crond.service # 启动服务
systemctl stop crond.service # 停止服务
systemctl restart crond.service # 重启服务
systemctl reload crond.service # 重新载入配置
systemctl status crond.service # 查看服务状态
```
## crontab
### crontab 命令
crontab 命令格式如下:
```shell
crontab [-u user] file crontab [-u user] [ -e | -l | -r ]
```
说明:
- `-u user`:用来设定某个用户的 crontab 服务;
- `file`file 是命令文件的名字,表示将 file 做为 crontab 的任务列表文件并载入 crontab。如果在命令行中没有指定这个文件crontab 命令将接受标准输入(键盘)上键入的命令,并将它们载入 crontab。
- `-e`:编辑某个用户的 crontab 文件内容。如果不指定用户,则表示编辑当前用户的 crontab 文件。
- `-l`:显示某个用户的 crontab 文件内容,如果不指定用户,则表示显示当前用户的 crontab 文件内容。
- `-r`:从/var/spool/cron 目录中删除某个用户的 crontab 文件,如果不指定用户,则默认删除当前用户的 crontab 文件。
- `-i`:在删除用户的 crontab 文件时给确认提示。
有两种方法写入定时任务:
- 在命令行输入:`crontab -e` 然后添加相应的任务,存盘退出。
- 直接编辑 `/etc/crontab` 文件,即 `vi /etc/crontab`,添加相应的任务。
### crontab 文件
crontab 要执行的定时任务都被保存在 `/etc/crontab` 文件中。
crontab 的文件格式如下:
![img](https://raw.githubusercontent.com/dunwu/images/master/snap/20200211113339.png)
#### 标准字段
**逗号**用于分隔列表。例如,在第 5 个字段(星期几)中使用 `MON,WED,FRI` 表示周一、周三和周五。
**连字符**定义范围。例如,`2000-2010` 表示 2000 年至 2010 年期间的每年,包括 2000 年和 2010 年。
除非用反斜杠(\)转义,否则命令中的**百分号(%)**会被替换成换行符,第一个百分号后面的所有数据都会作为标准输入发送给命令。
| 字段 | 是否必填 | 允许值 | 允许特殊字符 |
| :----------- | :------- | :-------------- | :----------- |
| Minutes | 是 | 059 | `*`,`-` |
| Hours | 是 | 023 | `*`,`-` |
| Day of month | 是 | 131 | `*`,`-` |
| Month | 是 | 112 or JANDEC | `*`,`-` |
| Day of week | 是 | 06 or SUNSAT | `*`,`-` |
`/etc/crontab` 文件示例:
```shell
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# 每两个小时以root身份执行 /home/hello.sh 脚本
0 */2 * * * root /home/hello.sh
```
### crontab 实例
#### 实例 1每 1 分钟执行一次 myCommand
```shell
* * * * * myCommand
```
#### 实例 2每小时的第 3 和第 15 分钟执行
```shell
3,15 * * * * myCommand
```
#### 实例 3在上午 8 点到 11 点的第 3 和第 15 分钟执行
```shell
3,15 8-11 * * * myCommand
```
#### 实例 4每隔两天的上午 8 点到 11 点的第 3 和第 15 分钟执行
```shell
3,15 8-11 */2 * * myCommand
```
#### 实例 5每周一上午 8 点到 11 点的第 3 和第 15 分钟执行
```shell
3,15 8-11 * * 1 myCommand
```
#### 实例 6每晚的 21:30 重启 smb
```shell
30 21 * * * /etc/init.d/smb restart
```
#### 实例 7每月 1、10、22 日的 4 : 45 重启 smb
```shell
45 4 1,10,22 * * /etc/init.d/smb restart
```
#### 实例 8每周六、周日的 1 : 10 重启 smb
```shell
10 1 * * 6,0 /etc/init.d/smb restart
```
#### 实例 9每天 18 : 00 至 23 : 00 之间每隔 30 分钟重启 smb
```shell
0,30 18-23 * * * /etc/init.d/smb restart
```
#### 实例 10每星期六的晚上 11 : 00 pm 重启 smb
```shell
0 23 * * 6 /etc/init.d/smb restart
```
#### 实例 11每一小时重启 smb
```shell
* */1 * * * /etc/init.d/smb restart
```
#### 实例 12晚上 11 点到早上 7 点之间,每隔一小时重启 smb
```shell
0 23-7 * * * /etc/init.d/smb restart
```
## 参考资料
- **文章**
- [crontab 定时任务](https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.html)
- [linux 定时执行脚本](https://blog.csdn.net/z_yong_cool/article/details/79288397)
- **在线工具**
- [https://tool.lu/crontab/](https://tool.lu/crontab/)
- [https://cron.qqe2.com/](https://cron.qqe2.com/)

View File

@ -0,0 +1,38 @@
# 防火墙 - Firewalld
## 一、firewalld 服务命令
```shell
systemctl enable firewalld.service # 开启服务(开机自动启动服务)
systemctl disable firewalld.service # 关闭服务(开机不会自动启动服务)
systemctl start firewalld.service # 启动服务
systemctl stop firewalld.service # 停止服务
systemctl restart firewalld.service # 重启服务
systemctl reload firewalld.service # 重新载入配置
systemctl status firewalld.service # 查看服务状态
```
## 二、firewall-cmd 命令
`firewall-cmd` 命令用于配置防火墙。
```shell
firewall-cmd --version # 查看版本
firewall-cmd --help # 查看帮助
firewall-cmd --state # 显示状态
firewall-cmd --reload # 更新防火墙规则
firewall-cmd --get-active-zones # 查看区域信息
firewall-cmd --get-zone-of-interface=eth0 # 查看指定接口所属区域
firewall-cmd --panic-on # 拒绝所有包
firewall-cmd --panic-off # 取消拒绝状态
firewall-cmd --query-panic # 查看是否拒绝
firewall-cmd --zone=public --list-ports # 查看所有打开的端口
firewall-cmd --zone=public --query-port=80/tcp # 查看是否有开放的 80 TCP 端口
firewall-cmd --zone=public --add-port=80/tcp --permanent # 添加开发端口(--permanent永久生效没有此参数重启后失效
firewall-cmd --zone=public --remove-port=80/tcp --permanent # 永久删除开放的 80 TCP 端口
```
## 参考资料
- [CentOS7 使用 firewalld 打开关闭防火墙与端口](https://www.cnblogs.com/moxiaoan/p/5683743.html)

View File

@ -2,13 +2,13 @@
> 💡 如果没有特殊说明,本文的案例都是针对 Centos 发行版本。
## 1. 网络操作
## 网络操作
### 1.1. 无法访问外网域名
### 无法访问外网域名
1在 hosts 中添加本机实际 IP 和本机实际域名的映射
```bash
```shell
echo "192.168.0.1 hostname" >> /etc/hosts
```
@ -18,7 +18,7 @@ echo "192.168.0.1 hostname" >> /etc/hosts
执行 `vi /etc/resolv.conf` ,添加以下内容:
```bash
```shell
nameserver 114.114.114.114
nameserver 8.8.8.8
```
@ -31,59 +31,7 @@ nameserver 8.8.8.8
3测试一下能否 ping 通 www.baidu.com
### 1.2. 开启、关闭防火墙
firewalld 的基本使用
```bash
启动systemctl start firewalld
关闭systemctl stop firewalld
查看状态systemctl status firewalld
开机禁用systemctl disable firewalld
开机启用systemctl enable firewalld
```
systemctl 是 CentOS7 的服务管理工具中主要的工具,它融合之前 service 和 chkconfig 的功能于一体。
```
启动一个服务systemctl start firewalld.service
关闭一个服务systemctl stop firewalld.service
重启一个服务systemctl restart firewalld.service
显示一个服务的状态systemctl status firewalld.service
在开机时启用一个服务systemctl enable firewalld.service
在开机时禁用一个服务systemctl disable firewalld.service
查看服务是否开机启动systemctl is-enabled firewalld.service
查看已启动的服务列表systemctl list-unit-files|grep enabled
查看启动失败的服务列表systemctl --failed
```
配置 firewalld-cmd
```
查看版本firewall-cmd --version
查看帮助firewall-cmd --help
显示状态firewall-cmd --state
查看所有打开的端口firewall-cmd --zone=public --list-ports
更新防火墙规则firewall-cmd --reload
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域firewall-cmd --get-zone-of-interface=eth0
拒绝所有包firewall-cmd --panic-on
取消拒绝状态firewall-cmd --panic-off
查看是否拒绝firewall-cmd --query-panic
```
开启防火墙端口
```
添加firewall-cmd --zone=public --add-port=80/tcp --permanent --permanent永久生效没有此参数重启后失效
重新载入firewall-cmd --reload
查看firewall-cmd --zone= public --query-port=80/tcp
删除firewall-cmd --zone= public --remove-port=80/tcp --permanent
```
> :point_right: 参考:[CentOS7 使用 firewalld 打开关闭防火墙与端口](https://www.cnblogs.com/moxiaoan/p/5683743.html)
### 1.3. 配置网卡
### 配置网卡
使用 root 权限编辑 `/etc/sysconfig/network-scripts/ifcfg-eno16777736X` 文件
@ -114,54 +62,11 @@ DNS1=8.8.8.8                         # DNS域名解析
修改完后,执行 `systemctl restart network.service` 重启网卡服务。
## 2. 系统维护
## 系统维护
### 2.1. 使用 NTP 进行时间同步
## 自动化脚本
1先安装时钟同步工具 ntp
```
yum -y install ntp
```
ntp 的配置文件路径为: `/etc/ntp.conf`
2启动 NTP 服务
```bash
systemctl start ntpd.service
```
3放开防火墙 123 端口
NTP 服务的端口是 123,使用的是 udp 协议,所以 NTP 服务器的防火墙必须对外开放 udp 123 这个端口。
```
/sbin/iptables -A INPUT -p UDP -i eth0 -s 192.168.0.0/24 --dport 123 -j ACCEPT
```
4执行时间同步
```
/usr/sbin/ntpdate ntp.sjtu.edu.cn
```
ntp.sjtu.edu.cn 是上海交通大学 ntp 服务器。
5自动定时同步时间
执行如下命令,就可以在每天凌晨 3 点同步系统时间:
```
echo "* 3 * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn" >> /etc/crontab
systemctl restart crond.service
```
> :point_right: 参考https://www.cnblogs.com/quchunhui/p/7658853.html
## 3. 自动化脚本
### 3.1. Linux 开机自启动脚本
### Linux 开机自启动脚本
1`/etc/rc.local` 文件中添加命令
@ -174,7 +79,7 @@ systemctl restart crond.service
执行 `vim /etc/rc.local` 命令,输入以下内容:
```bash
```shell
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
@ -195,7 +100,7 @@ Linux 开机的时候,会加载运行 `/etc/rc.d/init.d` 目录下的程序,
简单的说,运行级就是操作系统当前正在运行的功能级别。
```
```shell
不同的运行级定义如下:
# 0 - 停机千万不能把initdefault 设置为0
# 1 - 单用户模式   进入方法#init s = init 1
@ -216,14 +121,14 @@ Linux 开机的时候,会加载运行 `/etc/rc.d/init.d` 目录下的程序,
2查看当前系统的启动级别
```bash
```shell
$ runlevel
N 3
```
3设定启动级别
```
```shell
# 98 为启动序号
# 2 是系统的运行级别,可自己调整,注意不要忘了结尾的句点
$ update-rc.d mysql start 98 2 .
@ -244,69 +149,14 @@ $ update-rc.d mysql start 98 2 .
> :point_right: 参考:
>
> - https://blog.csdn.net/linuxshine/article/details/50717272
> - https://www.cnblogs.com/ssooking/p/6094740.html
> - [linux 添加开机自启动脚本示例详解](https://blog.csdn.net/linuxshine/article/details/50717272)
> - [linux 设置开机自启动](https://www.cnblogs.com/ssooking/p/6094740.html)
### 3.2. 定时执行脚本
### 定时执行脚本
1安装 crontab
## 配置
2开启 crontab 服务
开机自动启动 crond 服务:`chkconfig crond on`
或者,按以下命令手动启动:
```bash
# 启动服务
systemctl start crond.service
# 停止服务
systemctl stop crond.service
# 重启服务
systemctl restart crond.service
# 重新载入配置
systemctl reload crond.service
# 查看状态
systemctl status crond.service
```
3设置需要执行的脚本
有两种方法:
- 在命令行输入:`crontab -e` 然后添加相应的任务,存盘退出。
- 直接编辑 `/etc/crontab` 文件,即 `vi /etc/crontab`,添加相应的任务。
示例:
```bash
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# 每天早上3点时钟同步
* 3 * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn
# 每两个小时以root身份执行 /home/hello.sh 脚本
0 */2 * * * root /home/hello.sh
```
> :point_right: 参考:[linux 定时执行脚本](https://blog.csdn.net/z_yong_cool/article/details/79288397)
## 4. 配置
### 4.1. 设置 Linux 启动模式
### 设置 Linux 启动模式
1. 停机(记得不要把 initdefault 配置为 0因为这样会使 Linux 不能启动)
2. 单用户模式,就像 Win9X 下的安全模式
@ -318,12 +168,11 @@ MAILTO=root
设置方法:
```bash
$ sed -i 's/id:5:initdefault:/id:3:initdefault:/' /etc/inittab
```shell
sed -i 's/id:5:initdefault:/id:3:initdefault:/' /etc/inittab
```
## 5. 参考资料
## 参考资料
- [CentOS7 使用 firewalld 打开关闭防火墙与端口](https://www.cnblogs.com/moxiaoan/p/5683743.html)
- [linux 定时执行脚本](https://blog.csdn.net/z_yong_cool/article/details/79288397)

186
docs/linux/ops/ntp.md Normal file
View File

@ -0,0 +1,186 @@
# 时间服务器 - NTP
## 一、NTP 简介
网络时间协议英语Network Time Protocol缩写NTP是在数据网络潜伏时间可变的计算机系统之间通过分组交换进行时钟同步的一个网络协议位于 OSI 模型的应用层。自 1985 年以来NTP 是目前仍在使用的最古老的互联网协议之一。NTP 由特拉华大学的 David L. Mills英语David L. Mills设计。
**NTP 意图将所有参与计算机的协调世界时UTC时间同步到几毫秒的误差内**。
NTP 要点:
- 地球共有 24 个时区,而以格林威治时间 (GMT) 为标准时间;
- 中国本地时间为 GMT +8 小时;
- 最准确的时间为使用原子钟 (Atomic clock) 所计算的,例如 UTC (Coordinated Universal Time) 就是一例;
- Linux 系统本来就有两种时间,一种是 Linux 以 `1970/01/01` 开始计数的系统时间,一种则是 BIOS 记载的硬件时间;
- Linux 可以透过网络校时,最常见的网络校时为使用 NTP 服务器,这个服务启动在 `udp port 123`
- 时区档案主要放置于 `/usr/share/zoneinfo/` 目录下,而本地时区则参考 `/etc/localtime`
- NTP 服务器为一种阶层式的服务,所以 NTP 服务器本来就会与上层时间服务器作时间的同步化, 因此 `nptd``ntpdate` 两个指令不可同时使用;
- NTP 服务器的联机状态可以使用 `ntpstat``ntpq -p` 来查询;
- NTP 提供的客户端软件为 `ntpdate` 这个指令;
- 在 Linux 下想要手动处理时间时,需以 `date` 设定时间后,以 `hwclock -w` 来写入 BIOS 所记录的时间。
- NTP 服务器之间的时间误差不可超过 1000 秒,否则 NTP 服务会自动关闭。
> 更多 NTP 详情可以参考:[鸟哥的 Linux 私房菜-- NTP 时间服务器](http://cn.linux.vbird.org/linux_server/0440ntp.php)
## 二、ntpd 服务
> 环境CentOS
### yum 安装
CentOS 安装 NTP 很简单,执行以下命令即可:
```shell
yum -y install ntp
```
### ntpd 配置
ntp 的配置文件路径为: `/etc/ntp.conf` ,参考配置:
```shell
# 1. 先处理权限方面的问题,包括放行上层服务器以及开放区网用户来源:
# restrict default kod nomodify notrap nopeer noquery # 拒绝 IPv4 的用户
# restrict -6 default kod nomodify notrap nopeer noquery # 拒绝 IPv6 的用户
restrict default nomodify notrap nopeer noquery
#restrict 192.168.100.0 mask 255.255.255.0 nomodify # 放行同局域网来源(根据网关和子网掩码决定)
restrict 127.0.0.1 # 默认值,放行本机 IPv4 来源
restrict ::1 # 默认值,放行本机 IPv6 来源
# 2. 设定 NTP 主机来源
# 注释掉默认 NTP 来源
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
# 设置国内 NTP 来源
server cn.pool.ntp.org prefer # 以这个主机为优先
server ntp1.aliyun.com
server ntp.sjtu.edu.cn
# 3. 预设时间差异分析档案与暂不用到的 keys 等,不需要更改它:
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys
includefile /etc/ntp/crypto/pw
```
> 注意:如果更改配置,必须重启 NTP 服务(`systemctl restart ntpd`)才能生效。
### 放开防火墙限制
NTP 服务的端口是 `123`,使用的是 udp 协议,所以 NTP 服务器的防火墙必须对外开放 udp 123 这个端口。
如果防火墙使用 **`iptables`**,执行以下命令:
```shell
iptables -A INPUT -p UDP -i eth0 -s 192.168.0.0/24 --dport 123 -j ACCEPT
```
如果防火墙使用 **`firewalld`**,执行以下命令:
```shell
firewall-cmd --zone=public --add-port=123/udp --permanent
```
### ntpd 服务命令
```shell
systemctl enable ntpd.service # 开启服务(开机自动启动服务)
systemctl disable ntpd.service # 关闭服务(开机不会自动启动服务)
systemctl start ntpd.service # 启动服务
systemctl stop ntpd.service # 停止服务
systemctl restart ntpd.service # 重启服务
systemctl reload ntpd.service # 重新载入配置
systemctl status ntpd.service # 查看服务状态
```
### 查看 ntp 服务状态
#### 验证 NTP 服务正常工作
执行 `ntpstat` 可以查看 ntp 服务器有无和上层 ntp 连通,,如果成功,可以看到类似以下的内容:
```shell
$ ntpstat
synchronised to NTP server (5.79.108.34) at stratum 3
time correct to within 1129 ms
polling server every 64 s
```
#### 查看 ntp 服务器与上层 ntp 的状态
```shell
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp1.ams1.nl.le 130.133.1.10 2 u 36 64 367 230.801 5.271 2.791
120.25.115.20 10.137.53.7 2 u 33 64 377 25.930 15.908 3.168
time.cloudflare 10.21.8.251 3 u 31 64 367 251.109 16.976 3.264
```
## 三、ntpdate 命令
> 注意NTP 服务器为一种阶层式的服务,所以 NTP 服务器本来就会与上层时间服务器作时间的同步化, 因此 `nptd``ntpdate` 两个指令不可同时使用。
### 手动执行时间同步
`ntpdate` 命令是 NTP 的客户端软件,它可以用于请求时间同步。
语法:
```shell
/usr/sbin/ntpdate <ntp_server>
```
`ntp_server` 可以从 [国内 NTP 服务器](#国内 NTP 服务器) 中选择。
示例:
```shell
$ ntpdate cn.pool.ntp.org
11 Feb 10:47:12 ntpdate[30423]: step time server 84.16.73.33 offset -49.894774 sec
```
### 自动定时同步时间
如果需要自动定时同步时间,可以利用 [Crontab](#crontab) 工具。本质就是用 crontab 定时执行一次手动时间同步命令 ntp。
示例:执行如下命令,就可以在每天凌晨 3 点同步系统时间:
```shell
echo "* 3 * * * /usr/sbin/ntpdate cn.pool.ntp.org" >> /etc/crontab # 修改 crond 服务配置
systemctl restart crond # 重启 crond 服务以生效
```
## 四、国内 NTP 服务器
以下 NTP 服务器搜集自网络:
```shell
cn.pool.ntp.org # 最常用的国内NTP服务器参考https://www.ntppool.org/zh/use.html
cn.ntp.org.cn # 中国
edu.ntp.org.cn # 中国教育网
ntp1.aliyun.com # 阿里云
ntp2.aliyun.com # 阿里云
ntp.sjtu.edu.cn # 上海交通大学
s1a.time.edu.cn # 北京邮电大学
s1b.time.edu.cn # 清华大学
s1c.time.edu.cn # 北京大学
s1d.time.edu.cn # 东南大学
s1e.time.edu.cn # 清华大学
s2a.time.edu.cn # 清华大学
s2b.time.edu.cn # 清华大学
s2c.time.edu.cn # 北京邮电大学
s2d.time.edu.cn # 西南地区网络中心
s2e.time.edu.cn # 西北地区网络中心
s2f.time.edu.cn # 东北地区网络中心
s2g.time.edu.cn # 华东南地区网络中心
s2h.time.edu.cn # 四川大学网络管理中心
s2j.time.edu.cn # 大连理工大学网络中心
s2k.time.edu.cn # CERNET桂林主节点
```
## 参考资料
- [鸟哥的 Linux 私房菜-- NTP 时间服务器](http://cn.linux.vbird.org/linux_server/0440ntp.php)
- [Linux 配置 ntp 时间服务器](https://www.cnblogs.com/quchunhui/p/7658853.html)

View File

@ -1,5 +1,7 @@
# 软件安装配置
## 📖 内容
- [JDK 安装](jdk-install.md)
- [Elastic 安装](elastic)
- [Gitlab 安装](kafka-install.md)
@ -13,3 +15,7 @@
- [Tomcat 安装](tomcat-install.md)
- [Zookeeper 安装](zookeeper-ops.md)
- [Nacos 安装](nacos-install.md)
## 🚪 传送门
◾ 🏠 [DB-TUTORIAL 首页](https://github.com/dunwu/linux-tutorial) ◾ 🎯 [我的博客](https://github.com/dunwu/blog) ◾