Skip to content

Commit a786dd2

Browse files
committed
添加脚本
1 parent 78a9ebf commit a786dd2

166 files changed

Lines changed: 5223 additions & 43 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 76 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,8 @@
11
# Linux 教程
22

3-
## [Linux 命令](docs/linux/cli)
3+
## :shell: 脚本
44

5-
> 根据应用场景,将常见 Linux 命令分门别类的一一介绍。
6-
>
7-
> 如果想快速学习,推荐参考这篇文章:[命令行的艺术(转载)](docs/linux/cli/命令行的艺术.md)
8-
9-
1. [查看 Linux 命令帮助信息](docs/linux/cli/01.查看Linux命令帮助信息.md) - 关键词:`help`, `whatis`, `info`, `which`, `whereis`, `man`
10-
2. [Linux 文件目录管理](docs/linux/cli/02.Linux文件目录管理.md) - 关键词:`cd`, `ls`, `pwd`, `mkdir`, `rmdir`, `tree`, `touch`, `ln`, `rename`, `stat`, `file`, `chmod`, `chown`, `locate`, `find`, `cp`, `mv`, `rm`
11-
3. [Linux 文件内容查看命令](docs/linux/cli/03.Linux文件内容查看编辑.md) - 关键词:`cat`, `head`, `tail`, `more`, `less`, `sed`, `vi`, `grep`
12-
4. [Linux 文件压缩和解压](docs/linux/cli/04.Linux文件压缩和解压.md) - 关键词:`tar`, `gzip`, `zip`, `unzip`
13-
5. [Linux 用户管理](docs/linux/cli/05.Linux用户管理.md) - 关键词:`groupadd`, `groupdel`, `groupmod`, `useradd`, `userdel`, `usermod`, `passwd`, `su`, `sudo`
14-
6. [Linux 系统管理](docs/linux/cli/06.Linux系统管理.md) - 关键词:`reboot`, `exit`, `shutdown`, `date`, `mount`, `umount`, `ps`, `kill`, `systemctl`, `service`, `crontab`
15-
7. [Linux 网络管理](docs/linux/cli/07.Linux网络管理.md) - 关键词:关键词:`curl`, `wget`, `telnet`, `ip`, `hostname`, `ifconfig`, `route`, `ssh`, `ssh-keygen`, `firewalld`, `iptables`, `host`, `nslookup`, `nc`/`netcat`, `ping`, `traceroute`, `netstat`
16-
8. [Linux 硬件管理](docs/linux/cli/08.Linux硬件管理.md) - 关键词:`df`, `du`, `top`, `free`, `iotop`
17-
9. [Linux 软件管理](docs/linux/cli/09.Linux软件管理.md) - 关键词:`rpm`, `yum`, `apt-get`
18-
19-
## [Linux 工具](docs/linux/tool)
20-
21-
- [Git](docs/linux/tool/git)
22-
- [Vim](docs/linux/tool/vim.md)
23-
24-
## [Linux 脚本](docs/lang)
25-
26-
- [一篇文章让你彻底掌握 shell 语言](docs/lang/shell.md)
27-
- [一篇文章让你彻底掌握 python 语言](docs/lang/python.md)
28-
29-
## [Linux 运维](docs/linux/ops)
30-
31-
### Linux 服务器运维
32-
33-
- [Linux 典型运维应用](docs/linux/ops/linux典型运维应用.md)
34-
- [samba 使用详解](docs/linux/ops/samba使用详解.md)
35-
36-
### 软件安装、配置、调优
37-
38-
> :bulb: **说明**
39-
>
40-
> 这里总结了一些常用开发软件的安装、配置、使用指南。
41-
>
42-
> 此外,提供了一键安装、配置脚本,:point_right: [**软件安装配置脚本**](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/ops/soft)
43-
>
44-
> [环境部署工具](https://github.com/dunwu/linux-tutorial/tree/master/codes/deploy) :适合开发、运维人员,在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。
5+
以下内容均含配套执行脚本,方便日常的 linux 运维。
456

467
| 软件 | 说明 |
478
| ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
@@ -60,4 +21,77 @@
6021
| [Zookeeper 安装](docs/linux/soft/zookeeper.md) | 分布式系统协调软件 |
6122
| [Nacos 安装](linux/soft/nacos.md) | 微服务发现、管理 |
6223

63-
## [Docker](docs/docker)
24+
## :memo: 知识点
25+
26+
- [Linux 命令教程](docs/linux/cli)
27+
- [Docker 教程](docs/docker)
28+
- [Git 教程](docs/linux/tool/git)
29+
- [Vim](docs/linux/tool/vim.md)
30+
- 脚本语言
31+
- [一篇文章让你彻底掌握 shell 语言](docs/lang/shell.md)
32+
- [一篇文章让你彻底掌握 python 语言](docs/lang/python.md)
33+
- 运维
34+
- [Linux 典型运维应用](docs/linux/ops/linux典型运维应用.md)
35+
- [samba 使用详解](docs/linux/ops/samba使用详解.md)
36+
37+
## :books: 学习资源
38+
39+
### 命令行检索
40+
41+
- [Linux命令大全](http://man.linuxde.net/)
42+
- [linux-command](https://jaywcjlove.gitee.io/linux-command/)
43+
44+
### 社区网站
45+
46+
- [Linux 中国](https://linux.cn/) - 各种资讯、文章、技术
47+
- [实验楼](https://www.shiyanlou.com/) - 免费提供了 Linux 在线环境,不用在自己机子上装系统也可以学习 Linux,超方便实用。
48+
- [鸟哥的 linux 私房菜](http://linux.vbird.org/) - 非常适合 Linux 入门初学者看的教程。
49+
- [Linux 公社](http://www.linuxidc.com/) - Linux 相关的新闻、教程、主题、壁纸都有。
50+
- [Linux Today](http://www.linuxde.net) - Linux 新闻资讯发布,Linux 职业技术学习!。
51+
52+
### 知识相关
53+
54+
- [Linux 思维导图整理](http://www.jianshu.com/p/59f759207862)
55+
- [Linux 初学者进阶学习资源整理](http://www.jianshu.com/p/fe2a790b41eb)
56+
- [Linux 基础入门(新版)](https://www.shiyanlou.com/courses/1)
57+
- [【译】Linux 概念架构的理解](http://www.jianshu.com/p/c5ae8f061cfe) [En](http://oss.org.cn/ossdocs/linux/kernel/a1/index.html)
58+
- [Linux 守护进程的启动方法](http://www.ruanyifeng.com/blog/2016/02/linux-daemon.html)
59+
- [Linux 编程之内存映射](https://www.shiyanlou.com/questions/2992)
60+
- [Linux 知识点小结](https://blog.huachao.me/2016/1/Linux%E7%9F%A5%E8%AF%86%E7%82%B9%E5%B0%8F%E7%BB%93/)
61+
- [10 大白帽黑客专用的 Linux 操作系统](https://linux.cn/article-6971-1.html)
62+
63+
### 软件工具
64+
65+
- [超赞的 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)
66+
- [程序员喜欢的 9 款最佳的 Linux 文件比较工具](http://os.51cto.com/art/201607/513796.htm)
67+
- [提高 Linux 开发效率的 5 个工具](http://www.codeceo.com/article/5-linux-productivity-tools.html)
68+
- [你要了解的 11 款面向 Linux 系统的一流备份实用工具](http://os.51cto.com/art/201603/508027.htm)
69+
- [16 个很有用的在线工具](http://www.simlinux.com/archives/264.html)
70+
- Adobe 软件的最佳替代品 [原文在这里](https://linux.cn/article-8928-1.html)
71+
- [Evince (Adobe Acrobat Reader)](https://wiki.gnome.org/Apps/Evince) 一个“支持多种文档格式的文档查看器”,可以查看 PDF,还支持各种漫画书格式
72+
- [Pixlr (Adobe Photoshop)](https://pixlr.com/) 一个强大的图像编辑工具
73+
- [Inkscape (Adobe Illustrator)](https://inkscape.org/zh/) 一个专业的矢量图形编辑器
74+
- [Pinegrow Web Editor (Adobe Dreamweaver)](https://pinegrow.com/) 一个可视化编辑制作 HTML 网站
75+
- [Scribus (Adobe InDesign)](https://www.scribus.net/) 一个开源电子杂志制作软件
76+
- [Webflow (Adobe Muse)](https://webflow.com/) 一款可以帮助用户不用编码就可以快速创建网站的谷歌浏览器插件。
77+
- [Tupi (Adobe Animate)](http://www.maefloresta.com/portal/) 一款可以创建 HTML5 动画的工具。
78+
- [Black Magic Fusion (Adobe After Effects)](https://www.blackmagicdesign.com) 一款先进的合成软件,广泛应用于视觉特效、广电影视设计以及 3D 动画设计等领域。
79+
80+
### 中国开源镜像站点
81+
82+
- 阿里云开源镜像站:http://mirrors.aliyun.com/
83+
- 网易开源镜像站:http://mirrors.163.com/
84+
- 搜狐开源镜像站:http://mirrors.sohu.com/
85+
- 北京交通大学:http://mirror.bjtu.edu.cn/ \<教育网荐\>
86+
- 兰州大学:http://mirror.lzu.edu.cn/ \<西北高校 FTP 搜索引擎\>
87+
- 厦门大学:http://mirrors.xmu.edu.cn/
88+
- 上海交通大学:http://ftp.sjtu.edu.cn/
89+
- 清华大学:http://mirrors.tuna.tsinghua.edu.cn/
90+
- http://mirrors6.tuna.tsinghua.edu.cn/
91+
- http://mirrors4.tuna.tsinghua.edu.cn/
92+
- 中国科学技术大学:http://mirrors.ustc.edu.cn/
93+
- http://ipv4.ustc.edu.cn/ \<教育网、电信\>
94+
- http://ipv6.ustc.edu.cn/ \<IPv6 only\>
95+
- 东北大学:http://mirror.neu.edu.cn/
96+
- 浙江大学:http://mirrors.zju.edu.cn/
97+
- 东软信息学院:http://mirrors.neusoft.edu.cn/
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/bin/bash
2+
#mail:xuel@anchnet.com
3+
#data:2017/9/7
4+
#AutoInstall ELK scripts
5+
#Software:elasticsearch-5.4.1/logstash-5.4.1/filebeat-5.4.1/kibana-5.4.1
6+
clear
7+
echo "##########################################"
8+
echo "# Auto Install ELK. ##"
9+
echo "# Press Ctrl + C to cancel ##"
10+
echo "# Any key to continue ##"
11+
echo "##########################################"
12+
read -p
13+
software_dir="/usr/local/software"
14+
elasticsearch_url="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.1.tar.gz"
15+
kibana_url="https://artifacts.elastic.co/downloads/kibana/kibana-5.4.1-linux-x86_64.tar.gz"
16+
logstash_url="https://artifacts.elastic.co/downloads/logstash/logstash-5.4.1.tar.gz"
17+
filebeat_url="https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.4.1-linux-x86_64.tar.gz"
18+
sys_version=`cat /etc/redhat-release |awk '{print $4}'|cut -d. -f1`
19+
IP=`ip addr|grep "inet "|grep -v 127.0.0.1|awk '{print $2}'|cut -d/ -f1`
20+
jvm_conf="/usr/local/elasticsearch/config/jvm.options"
21+
sys_mem=`free -m|grep Mem:|awk '{print $2}'|awk '{sum+=$1} END {print sum/1024}'|cut -d. -f1`
22+
23+
#wget software
24+
wget_fun() {
25+
if [ ! -d ${software_dir} ];then
26+
mkdir -p ${software_dir} && cd ${software_dir}
27+
else
28+
cd ${software_dir}
29+
fi
30+
for software in $elasticsearch_url $kibana_url $logstash_url $filebeat_url
31+
do
32+
wget -c $software
33+
done
34+
clear
35+
}
36+
#initial system:install java wget;set hostname;disable firewalld
37+
init_sys() {
38+
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
39+
[ "${sys_version}" != "7" ] && echo "Error:This Scripts Support Centos7.xx" && exit 1
40+
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
41+
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
42+
setenforce 0
43+
yum install -y java-1.8.0-openjdk wget net-tools
44+
hostnamectl set-hostname elk-server
45+
systemctl stop firewalld
46+
cat >>/etc/security/limits.conf<<EOF
47+
* soft nofile 65536
48+
* hard nofile 65536
49+
* soft nGproc 65536
50+
* hard nproc 65536
51+
EOF
52+
}
53+
54+
#install elasticsearch
55+
install_elasticsearch() {
56+
cd $software_dir
57+
tar zxf elasticsearch-5.4.1.tar.gz
58+
mv elasticsearch-5.4.1 /usr/local/elasticsearch
59+
mkdir -p /usr/local/elasticsearch/data /usr/local/elasticsearch/logs
60+
useradd elasticsearch
61+
chown -R elasticsearch:elasticsearch /usr/local/elasticsearch
62+
echo "vm.max_map_count = 655360" >>/etc/sysctl.conf && sysctl -p
63+
if [ ${sys_mem} -eq 0 ];then
64+
sed -i "s#`grep "^-Xmx" ${jvm_conf}`#"-Xmx512m"#g" ${jvm_conf}
65+
sed -i "s#`grep "^-Xms" ${jvm_conf}`#"-Xms512m"#g" ${jvm_conf}
66+
else
67+
sed -i "s#`grep "^-Xmx" ${jvm_conf}`#"-Xmx${sys_mem}g"#g" ${jvm_conf}
68+
sed -i "s#`grep "^-Xms" ${jvm_conf}`#"-Xms${sys_mem}g"#g" ${jvm_conf}
69+
fi
70+
cat >>/usr/local/elasticsearch/config/elasticsearch.yml<<EOF
71+
cluster.name: my-application
72+
node.name: elk-server
73+
path.data: /usr/local/elasticsearch/data
74+
path.logs: /usr/local/elasticsearch/logs
75+
network.host: 127.0.0.1
76+
http.port: 9200
77+
discovery.zen.ping.unicast.hosts: ["elk-server"]
78+
EOF
79+
su - elasticsearch -c "nohup /usr/local/elasticsearch/bin/elasticsearch &"
80+
}
81+
82+
#install logstash
83+
install_logstash() {
84+
cd $software_dir
85+
tar -zxf logstash-5.4.1.tar.gz
86+
mv logstash-5.4.1 /usr/local/logstash
87+
cat>/usr/local/logstash/config/01-syslog.conf<<EOF
88+
input {
89+
beats {
90+
port => "5044"
91+
}
92+
}
93+
output {
94+
elasticsearch {
95+
hosts => "127.0.0.1:9200"
96+
}
97+
stdout { codec => rubydebug }
98+
}
99+
EOF
100+
nohup /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/01-syslog.conf & >/dev/null
101+
}
102+
103+
#install filebeat
104+
install_filebeat() {
105+
cd $software_dir
106+
tar -zxf filebeat-5.4.1-linux-x86_64.tar.gz
107+
mv filebeat-5.4.1-linux-x86_64 /usr/local/filebeat
108+
cat >/usr/local/filebeat/filebeat.yml<<EOF
109+
filebeat.prospectors:
110+
- input_type: log
111+
paths:
112+
- /var/log/*.log
113+
output.logstash:
114+
hosts: ["127.0.0.1:5044"]
115+
EOF
116+
cd /usr/local/filebeat/
117+
nohup /usr/local/filebeat/filebeat & >/dev/null
118+
}
119+
120+
#install kibana
121+
install_kibana() {
122+
cd $software_dir
123+
tar -zxf kibana-5.4.1-linux-x86_64.tar.gz
124+
mv kibana-5.4.1-linux-x86_64 /usr/local/kibana
125+
cat >> /usr/local/kibana/config/kibana.yml <<EOF
126+
server.port: 5601
127+
server.host: "0.0.0.0"
128+
elasticsearch.url: "http://127.0.0.1:9200"
129+
EOF
130+
nohup /usr/local/kibana/bin/kibana & >/dev/null
131+
}
132+
133+
check() {
134+
port=$1
135+
program=$2
136+
check_port=`netstat -lntup|grep ${port}|wc -l`
137+
check_program=`ps -ef|grep ${program}|grep -v grep|wc -l`
138+
if [ $check_port -gt 0 ] && [ $check_program -gt 0 ];then
139+
action "${program} run is ok!" /bin/true
140+
else
141+
action "${program} run is error!" /bin/false
142+
fi
143+
}
144+
145+
main() {
146+
init_sys
147+
wget_fun
148+
install_elasticsearch
149+
install_filebeat
150+
install_logstash
151+
install_kibana
152+
echo -e "\033[32m Checking Elasticsearch...\033[0m"
153+
sleep 20
154+
check :9200 "elasticsearch"
155+
echo -e "\033[32m Checking Logstash...\033[0m"
156+
sleep 2
157+
check ":9600" "logstash"
158+
echo -e "\033[32m Checking Kibana...\033[0m"
159+
sleep 2
160+
check ":5601" "kibana"
161+
action "ELK install is success!" /bin/true
162+
echo "url:http://$IP:5601"
163+
}
164+
main

codes/linux/ops/tool/Cpu_Limit.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# auth:kaliarch
3+
# func:sys info check
4+
# version:v1.0
5+
# sys:centos6.x/7.x
6+
7+
set -e
8+
[ $(id -u) -gt 0 ] && exit 1
9+
10+
# cpu使用超过百分之多少进行限制
11+
PEC_CPU=80
12+
13+
# 限制进程使用百分之多少,如果程序为多线程,单个cpu限制为85,如果为多核心,就需要按照比例写,例如cpu为2c,像限制多线程占比80%,就写170
14+
LIMIT_CPU=85
15+
# 日志
16+
LOG_DIR=/var/log/cpulimit/
17+
18+
# 超过阀值进程pid
19+
PIDARG=$(ps -aux |awk -v CPU=${PEC_CPU} '{if($3 > CPU) print $2}')
20+
CPULIMITCMD=$(which cpulimit)
21+
22+
install_cpulimit() {
23+
[ ! -d /tmp ] && mkdir /tmp || cd /tmp
24+
wget -c https://github.com/opsengine/cpulimit/archive/v0.2.tar.gz
25+
tar -zxf v0.2.tar.gz
26+
cd cpulimit-0.2 && make
27+
[ $? -eq 0 ] && cp src/cpulimit /usr/bin/
28+
}
29+
30+
31+
do_cpulimit() {
32+
[ ! -d ${LOG_DIR} ] && mkdir -p ${LOG_DIR}
33+
for i in ${PIDARG};
34+
do
35+
MSG=$(ps -aux |awk -v pid=$i '{if($2 == pid) print $0}')
36+
echo ${MSG}
37+
[ ! -d /tmp ] && mkdir /tmp || cd /tmp
38+
nohup ${CPULIMITCMD} -p $i -l ${LIMIT_CPU} &
39+
echo "$(date) -- ${MSG}" >> ${LOG_DIR}$(date +%F).log
40+
done
41+
}
42+
43+
main() {
44+
45+
hash cpulimit
46+
if [ $? -eq 0 ];then
47+
do_cpulimit
48+
else
49+
install_cpulimit && do_cpulimit
50+
fi
51+
}
52+
53+
main

codes/linux/ops/tool/Custom_Rm.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# function:自定义rm命令,每天晚上定时清理
3+
4+
CMD_SCRIPTS=$HOME/.rm_scripts.sh
5+
TRASH_DIR=$HOME/.TRASH_DIR
6+
CRON_FILE=/var/spool/cron/root
7+
BASHRC=$HOME/.bashrc
8+
9+
[ ! -d ${TRASH_DIR} ] && mkdir -p ${TRASH_DIR}
10+
cat > $CMD_SCRIPTS <<EOF
11+
PARA_CNT=\$#
12+
TRASH_DIR=$TRASH_DIR
13+
for i in \$*; do
14+
DATE=\$(date +%F%T)
15+
fileName=\$(basename \$i)
16+
mv \$i \$TRASH_DIR/\$fileName.\$DATE
17+
done
18+
EOF
19+
20+
sed -i "s@$(grep 'alias rm=' $BASHRC)@alias rm='bash ${CMD_SCRIPTS}'@g" $BASHRC
21+
source $HOME/.bashrc
22+
23+
echo "0 0 * * * rm -rf $TRASH_DIR/*" >> $CRON_FILE
24+
echo "删除目录:$TRASH_DIR"
25+
echo "删除脚本:$CMD_SCRIPTS"
26+
echo "请执行:source $BASHRC 来加载文件或退出当前shell重新登录"

0 commit comments

Comments
 (0)