Skip to content

Commit

Permalink
update 2022年02月 9日 17:52:06
Browse files Browse the repository at this point in the history
  • Loading branch information
No-Github committed Feb 9, 2022
1 parent b068ec6 commit aafb38b
Show file tree
Hide file tree
Showing 41 changed files with 863 additions and 173 deletions.
40 changes: 40 additions & 0 deletions 1earn/Integrated/Linux/God-Linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,46 @@ python -m SimpleHTTPServer 8000
curl ifconfig.me
```

**无依赖下载(仅支持http)**
- [linux在没有curl和wget的情况下如何用shell实现下载功能](https://zgao.top/linux%e5%9c%a8%e6%b2%a1%e6%9c%89curl%e5%92%8cwget%e7%9a%84%e6%83%85%e5%86%b5%e4%b8%8b%e5%a6%82%e4%bd%95%e7%94%a8shell%e5%ae%9e%e7%8e%b0%e4%b8%8b%e8%bd%bd%e5%8a%9f%e8%83%bd/)

```bash
#!/bin/bash
# 无依赖的http下载
# https://zgao.top/linux%e5%9c%a8%e6%b2%a1%e6%9c%89curl%e5%92%8cwget%e7%9a%84%e6%83%85%e5%86%b5%e4%b8%8b%e5%a6%82%e4%bd%95%e7%94%a8shell%e5%ae%9e%e7%8e%b0%e4%b8%8b%e8%bd%bd%e5%8a%9f%e8%83%bd/
# https://github.com/c4pr1c3/cuc-ns/blob/master/chap0x07/exp/webgoat/wget.sh

function DOWNLOAD() {

local URL=$1

if [ -z "${URL}" ]; then
printf "Usage: %s \"URL\" [e.g.: %s http://www.xxx.com/test.json]" \
"${FUNCNAME[0]}" "${FUNCNAME[0]}"
return 1;
fi

read proto server path <<< "${URL//"/"/ }"
DOC=/${path// //}
HOST=${server//:*}
PORT=${server//*:}
[[ x"${HOST}" == x"${PORT}" ]] && PORT=80

exec 3<>/dev/tcp/${HOST}/$PORT
echo -en "GET ${DOC} HTTP/1.0\r\nHost: ${HOST}\r\n\r\n" >&3
while IFS= read -r line ; do
[[ "$line" == $'\r' ]] && break
done <&3
nul='\0'
while IFS= read -d '' -r x || { nul=""; [ -n "$x" ]; }; do
printf "%s$nul" "$x"
done <&3
exec 3>&-
}

DOWNLOAD "$1"
```

---

## shell
Expand Down
26 changes: 15 additions & 11 deletions 1earn/Integrated/Linux/Power-Linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -2180,17 +2180,6 @@ firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload
```

**ab**

> ab 是 apache 的压力测试工具
安装
```bash
apt install -y apache2-utils

yum install -y httpd-tools
```

**更多配置案例**

[httpd.md](./实验/httpd.md)
Expand Down Expand Up @@ -2337,6 +2326,20 @@ ln -s /home/node-v12.17.0-linux-x64/bin/npm /usr/local/bin/npm
npm install --unsafe-perm=true --allow-root
```

**模块安装和卸载**
```bash
# 安装
npm i -g [xxx模块]

# clone 到本地安装
git clone https://github.com/xxx/[xxx模块]
cd [xxx模块]
npm i -g

# 卸载
npm uninstall [xxx模块]
```

**forever**

> forever 是一个简单的命令式 nodejs 的守护进程,能够启动,停止,重启 App 应用。forever 完全基于命令行操作,在forever进程之下,创建 node 的子进程,通过 monitor 监控 node 子进程的运行情况,一旦文件更新或进程挂掉,forever 会自动重启 node 服务器,确保应用正常运行。
Expand Down Expand Up @@ -2470,6 +2473,7 @@ server {
}
}
```

`nginx -t ` 检测文件是否有误

```bash
Expand Down
9 changes: 9 additions & 0 deletions 1earn/Integrated/Linux/Speed-Linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,11 @@ ln file1 file2
tar -jxvf test.tar.bz2 # 解压
```

- .tbz
```bash
tar -xjvf test.tbz # 解压
```

- .gz
```bash
gunzip FileName.gz # 解压1
Expand Down Expand Up @@ -2504,6 +2509,10 @@ setfacl -b <File/Folder> # 删除 ACL
jobs # 显示 Linux 中的任务列表及任务状态
jobs -l # 显示进程号

kill %1 # 表示杀掉1号作业任务
fg %1 # 表示让1号作业回到前台
bg %1 # 转后台运行

pidof program # 找出 program 程序的进程 PID
pidof -x script # 找出 shell 脚本 script 的进程 PID

Expand Down
1 change: 1 addition & 0 deletions 1earn/Integrated/Linux/实验/Nginx.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ server {
---

## 添加https

```bash
openssl req -new -x509 -nodes -days 365 -newkey rsa:1024 -out httpd.crt -keyout httpd.key # 生成自签名证书,信息不要瞎填,Common Name一定要输你的网址

Expand Down
52 changes: 52 additions & 0 deletions 1earn/Integrated/Linux/实验/httpd.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@ httpd 是 apache 开源项目的一部分,如果只需要 web 服务器,现

---

## 安装

**centos 安装**

```bash
yum -y install httpd
```

**debian 下安装**

```bash
apt-get install apache2

systemctl status apache2

# 删除
apt-get remove apache2
```

默认配置在 `/etc/apache2/` 目录下

配置文件说明:
- apache2.conf - apache2服务器的主配置文件
- conf.d - 配置文件的附加片断
- magic - 是有关mod_mime_magic模块的数据
- ports.conf - 服务器监听IP和端口设置的配置文件
- mods-available - 一些.conf和.load 文件
- sites-available - 站点的配置文件
- /var/www - 默认情况下发布的网页文件的目录

---

## 案例1

- 配置 http 服务,以虚拟主机的方式建立一个 web 站点;
Expand Down Expand Up @@ -438,6 +470,8 @@ firewall-cmd --reload

访问 `机器相应ip/1.php`

---

## 泛解析

```bash
Expand All @@ -449,6 +483,24 @@ firewall-cmd --reload

---

## 修改 header 头

以 debian 为例,修改 /etc/apache2/conf-available/security.conf

将內容中 ServerTokens 对应的值改为 Prod
```diff
-- ServerTokens OS
++ ServerTokens Prod
```

前后区别

![](../../../../assets/img/Integrated/Linux/实验/httpd/1.png)

![](../../../../assets/img/Integrated/Linux/实验/httpd/2.png)

---

## Source & Reference

- [Linux下Apache与httpd的区别与关系](https://blog.csdn.net/yxfabcdefg/article/details/32324035)
Expand Down
4 changes: 2 additions & 2 deletions 1earn/Integrated/Linux/笔记/IO模型.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ IO 复用模型在第二阶段与阻塞 IO 和非阻塞 IO 是完全一致的。

## Source & Reference

- https://shuyi.tech/archives/head-first-of-linux-io-model
- https://cloud.tencent.com/developer/article/1684951
* https://shuyi.tech/archives/head-first-of-linux-io-model
* https://cloud.tencent.com/developer/article/1684951
79 changes: 76 additions & 3 deletions 1earn/Integrated/Linux/笔记/shell编程.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@

**资源教程**
- [dylanaraps/pure-bash-bible](https://github.com/dylanaraps/pure-bash-bible#get-the-username-of-the-current-user)
- [wangdoc/bash-tutorial](https://github.com/wangdoc/bash-tutorial) - Bash 教程
- [穷佐罗的Linux书](https://zorrozou.github.io/)

**相关文章**
- [10分钟学会Bash调试](https://mp.weixin.qq.com/s/MQjqu55BN6LqSsIAvevRQA)
- [如何并发执行Linux命令](https://mp.weixin.qq.com/s/L3u2e-GKl_yL3saJMMFazA)
- [终于知道 Shell 中单引号双引号的区别了](https://mp.weixin.qq.com/s/tyHIlRsg1rYjw-E_h-C2rA)
- [Bash编程基础知识](https://mp.weixin.qq.com/s/tSWnoO3IAET3C7iYY7ns6Q)
- [SHELL编程之执行过程](https://zorrozou.github.io/docs/books/shellbian-cheng-zhi-zhi-xing-guo-cheng.html)
- [SHELL编程之语法基础](https://zorrozou.github.io/docs/books/shellbian-cheng-zhi-yu-fa-ji-chu.html)
- [SHELL编程之执行环境](https://zorrozou.github.io/docs/books/shellbian-cheng-zhi-zhi-xing-huan-jing.html)
- [SHELL编程之特殊符号](https://zorrozou.github.io/docs/books/shellbian-cheng-zhi-te-shu-fu-hao.html)
- [SHELL编程之内建命令](https://zorrozou.github.io/docs/books/shellbian-cheng-zhi-nei-jian-ming-ling.html)
- [SHELL编程之常用技巧](https://zorrozou.github.io/docs/books/shellbian-cheng-zhi-chang-yong-ji-qiao.html)

---

Expand Down Expand Up @@ -1112,6 +1120,51 @@ fi
两个数字相等!
```

> 以下部分来自 : https://zorrozou.github.io/docs/books/shellbian-cheng-zhi-yu-fa-ji-chu.html
```bash
#!/bin/bash

DIR="/etc"
#第一种写法
ls -l $DIR &> /dev/null
ret=$?

if [ $ret -eq 0 ]
then
echo "$DIR is exist!"
else
echo "$DIR is not exist!"
fi

#第二种写法
if ls -l $DIR &> /dev/null
then
echo "$DIR is exist!"
else
echo "$DIR is not exist!"
fi
```

我曾经在无数的脚本中看到这里的第一种写法,先执行某个命令,然后记录其返回值,再使用 `[]` 进行分支判断。我想,这样写的人应该都是没有真正理解if语法的语义,导致做出了很多脱了裤子再放屁的事情。当然,if语法中后面最常用的命令就是`[]`。请注意我的描述中就是说`[]`是一个命令,而不是别的。实际上这也是bash编程新手容易犯错的地方之一,尤其是有其他编程经验的人,在一开始接触bash编程的时候都是将`[]`当成if语句的语法结构,于是经常在写`[]`的时候里面不写空格,即:

```bash
#正确的写法
if [ $ret -eq 0 ]
#错读的写法
if [$ret -eq 0]
```
同样的,当我们理解清楚了`[]`本质上是一个shell命令的时候,大家就知道这个错误是为什么了:命令加参数要用空格分隔。我们可以用type命令去检查一个命令:
```bash
[zorro@zorrozou-pc0 bash]$ type [
[ is a shell builtin
```
所以,实际上`[]`是一个内建命令,等同于test命令。所以上面的if语句也可以写成:
```bash
if test $ret -eq 0
```
### for
for 循环一般格式为:
Expand Down Expand Up @@ -1670,6 +1723,26 @@ command > /dev/null 2>&1
---
## 交互
如想在脚本中使用fdisk命令新建一个分区
```bash
#!/bin/bash
fdisk /dev/sdb << EOF
n
p
w
EOF
```
注意,仅作演示,不要执行
---
## 文件包含
和其他语言一样,Shell 也可以包含外部脚本。这样可以很方便的封装一些公用的代码作为一个独立的文件。
Expand Down Expand Up @@ -1809,6 +1882,6 @@ command1 && command2
## Source & Reference
- [Shell脚本编程30分钟入门](https://github.com/qinjx/30min_guides/blob/master/shell.md)
- [Shell 教程](https://www.runoob.com/linux/linux-shell.html)
- [Bash编程基础知识](https://mp.weixin.qq.com/s/tSWnoO3IAET3C7iYY7ns6Q)
* [Shell脚本编程30分钟入门](https://github.com/qinjx/30min_guides/blob/master/shell.md)
* [Shell 教程](https://www.runoob.com/linux/linux-shell.html)
* [Bash编程基础知识](https://mp.weixin.qq.com/s/tSWnoO3IAET3C7iYY7ns6Q)
8 changes: 4 additions & 4 deletions 1earn/Integrated/Linux/笔记/信息.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ find / \( -perm -o w -perm -o x \) -type d 2>/dev/null # world-writeable & exe
## Source & Reference
- [Linux 常用配置及硬件检测命令](https://www.oldking.net/893.html)
- [basic-linux-privilege-escalation](https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/)
- [在 Linux 上测试硬盘读写速度](http://einverne.github.io/post/2019/10/test-disk-write-and-read-speed-in-linux.html)
- [linux网络流量查看命令](https://blog.51cto.com/ityunwei2017/2158128)
* [Linux 常用配置及硬件检测命令](https://www.oldking.net/893.html)
* [basic-linux-privilege-escalation](https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/)
* [在 Linux 上测试硬盘读写速度](http://einverne.github.io/post/2019/10/test-disk-write-and-read-speed-in-linux.html)
* [linux网络流量查看命令](https://blog.51cto.com/ityunwei2017/2158128)
7 changes: 4 additions & 3 deletions 1earn/Integrated/Linux/笔记/包管理.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ zypper 是一个简单易用的命令行包管理器,它使用了一个软件包

---

**Source & Reference**
- [包管理器的进化](https://linux.cn/article-9931-1.html)
- [Ubuntu PPA 使用指南 ](https://linux.cn/article-10456-1.html)
## Source & Reference

* [包管理器的进化](https://linux.cn/article-9931-1.html)
* [Ubuntu PPA 使用指南 ](https://linux.cn/article-10456-1.html)
1 change: 1 addition & 0 deletions 1earn/Integrated/Linux/笔记/发行版.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ Slackware 走了一条同其他的发行版本(Red Hat、Debian、Gentoo、SuS
- https://zh.wikipedia.org/wiki/Linux
- https://upload.wikimedia.org/wikipedia/commons/1/1b/Linux_Distribution_Timeline.svg
- https://distrowatch.com/
- https://linux.cn/article-14215-1.html
4 changes: 2 additions & 2 deletions 1earn/Integrated/Linux/笔记/守护进程.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ includedir /etc/xinetd.d: 表示告诉 xinetd 要包含的文件或目录

## Source & Reference

- [Linux守护进程(init.d和xinetd)](https://www.cnblogs.com/itech/archive/2010/12/27/1914846.html)
- https://www.cnblogs.com/sunsky303/p/10940700.html
* [Linux守护进程(init.d和xinetd)](https://www.cnblogs.com/itech/archive/2010/12/27/1914846.html)
* [Xinetd服务的安装与配置详解](https://www.cnblogs.com/sunsky303/p/10940700.html)
Loading

0 comments on commit aafb38b

Please sign in to comment.