页面“C基础”与“Centos7服务器初始化”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
 
 
第1行: 第1行:
 +
=站内相关资源=
 +
[[容器初始化]]
 +
= 如果机器多[[Salt-ssh批量初始化机器]]=
 +
[[Salt-ssh批量初始化机器]]
  
 +
=如果机器少=
 +
==我现在用的shell==
 +
<pre>
 +
#!/bin/bash
 +
#Authon: linuxsa.org 201911
 +
# usage bash  osinit.sh 2>&1 | tee osinit.log 
 +
#http://wiki.linuxchina.net/index.php/Centos7%E5%88%9D%E5%A7%8B%E5%8C%96
  
 +
#常用开发包 gcc etc
 +
yum groupinstall "Development Tools" -y
 +
#常用命令 ifconfig etc
 +
yum install -y  net-tools    yum-utils rsync
  
   
+
yum install epel-release -y
good
+
yum install iftop tcpdump -y
http://akaedu.github.io/book/
 
  
 +
# ins docker
 +
# step 1: 安装必要的一些系统工具
 +
yum install -y yum-utils device-mapper-persistent-data lvm2
 +
# Step 2: 添加软件源信息
 +
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  
[https://zhuanlan.zhihu.com/p/90971489 C语言编程学习必备的一些网站,干货收藏!]
+
# Step 3: 更新并安装 Docker-CE
 +
yum makecache fast
  
[https://www.bilibili.com/video/BV17s411N78s/?spm_id_from=333.788.videocard.0 带你学C带你飞》]
+
yum -y install docker-ce
 +
# Step 4: 开启Docker服务
 +
systemctl enable docker
 +
systemctl start docker
  
=2021学习C APUE=
 
http://www.apuebook.com/
 
  
[https://www.zhihu.com/topic/19705459/hot UNIX环境高级编程(书籍)笔记什么都 有呀 ]
+
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
  
[https://www.zhihu.com/question/19939011 《UNIX环境高级编程》这本书怎么看?怎么学习]
+
yum install zabbix-agent -y  && systemctl  enable zabbix-agent
  
 +
#install docker-compose etc
  
 +
yum -y install vim wget curl yum-utils bash-completion bash-completion-extras epel-release lrzsz telnet python-pip
 +
#这个看情况
 +
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
 +
#mv  docker-compose /usr/local/bin/docker-compose
 +
sudo chmod +x /usr/local/bin/docker-compose
 +
chmod +x /usr/local/bin/docker-compose
 +
#pip install docker-compose
  
==看法 ==
+
#mkdir -p /home/data/docker
第二章和第六章可以跳跳,回头看
+
mkdir -p /data/docker
  
7.中文版翻译有瑕疵,但是整体还是不错,不至于对阅读产生影响(信号量那章有细节问题,但是信号量那张和csapp第八章几乎重复)
+
echo '{"graph": "/data/docker"}' >/etc/docker/daemon.json
  
首先,不要抱着一口气把这本书学完的心态去看。      尝试根据自己的兴趣,选择一个规模适当的开源项目,去阅读它的源代码。(例如我选择的就是一个小型的http服务器--Mongoose)当在某一方面发现自己有很多问题时,很希望去弄清楚时,这时候就可以去翻开手中的APUE,带着问题去阅读。这时候学习的效率必然比盲目地去看书更高,而且遗忘率也会降低。但是,仅仅读完是不够的。      很多时候,你看书的时候,会感觉自己看懂了,但是没过多久,又会发现自己忘了。或者,有时候你根本没看懂,而只是囫囵吞枣地看过去。所以,看完后,最好的方法就是写博客。尝试按照自己的理解以及逻辑,去将你学到的知识系统地阐述出来。这样,就算你以后忘了,再去翻翻博文,也能很快就捡起来。
+
# cat /etc/docker/daemon.json
 +
#{"graph": "/home/data/docker"}
  
十个最值得阅读学习的C开源项目代码
+
systemctl restart docker
  
    Webbench
+
#验证docker储存位置
    Tinyhttpd
+
docker system info | grep "Root Dir"
    cJSON
 
    CMockery
 
    Libev
 
    Memcached
 
    Lua
 
    SQLite
 
    UNIX v6
 
    NETBSD
 
  
建议先看 >> Unix/Linux编程实践教程
+
#开机自启动要用的
  
https://book.douban.com/subject/1219329/
+
chmod +x /etc/rc.d/rc.local
  
http://item.kongfz.com/book/32040616.html?push_type=2&min_price=57.00&utm_source=101004009001
+
setenforce 0
 +
sed -i 's/enforcing/disabled/g' /etc/selinux/config
  
https://detail.tmall.com/item.htm?spm=a1z10.1-b.w9858442-8055933095.4.fH3HiL&id=19729431809
+
#firewall
 +
systemctl enable firewalld
  
[https://github.com/woai3c/recommended-books 常用计算机书的下载]
 
  
[https://blog.csdn.net/qwe6620692/article/details/88107248  学习C语言,如何看懂及掌握一个程序!]
+
#修改源
 +
#CentOS 7
 +
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
 +
#或者
 +
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  
[https://blog.51cto.com/chinalx1/2143904 十个经典的C开源项目代码]
+
#CentOS 8
 +
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
 +
#或者
 +
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
  
[https://developer.51cto.com/art/201903/593703.htm 初学玩转C语言,这17个小项目收下不谢]
+
#3. 运行 yum makecache 生成缓存
 +
yum makecache
 +
</pre>
  
https://zhuanlan.zhihu.com/p/83185476
+
==centos7初始化 ==
  
== tinyhttpd C 语言实现最简单的 HTTP 服务器 学习 ==
+
== ssh config==
 +
<pre>
 +
echo "ssh-rsa AAAAB3NzaC you_prk_key root@ops
 +
"  >> /root/.ssh/authorized_keys
  
[https://www.shuzhiduo.com/A/ZOJPY9Ge5v/ tinyhttpd ------ C 语言实现最简单的 HTTP 服务器]
+
sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/g" /etc/ssh/sshd_config
  
https://github.com/nengm/Tinyhttpd
+
sed -i "s/^PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
  
[https://blog.csdn.net/baiwfg2/article/details/45582723 tinyhttpd源码详解]
+
systemctl restart sshd
 +
#service sshd restart
  
[https://blog.csdn.net/konghhhhh/article/details/103752962 tinyhttp整理(一)]
+
</pre>
 +
==网络配置==
 +
<pre>
 +
cat  /etc/sysconfig/network-scripts/ifcfg-eth0
 +
TYPE="Ethernet"
 +
BOOTPROTO=static 
 +
IPADDR0=192.168.0.16
 +
NETMASK=255.255.255.0 
 +
GATEWAY0=192.168.0.1
 +
DNS1=223.5.5.5  
 +
DNS2=114.114.114.114
  
[https://blog.csdn.net/weixin_30387663/article/details/99664160  tinyhttp源码阅读(注释)]
+
DEVICE="eth0"
 +
ONBOOT="yes"
  
[https://juejin.cn/post/6870760453619122183  Tinyhttp源码分析及知识点总结 ]
+
</pre>
  
[https://www.bilibili.com/video/BV1hy4y1C71M/?spm_id_from=333.788.videocard.1 b站 C/C++ tinyHttp服务器小项目及源码讲解1]
+
== 安装常用软件==
 +
<pre> yum install python-devel
 +
yum install vim  wget  net-tools  psmisc links  lsof telnet  zlib-devel curl  tmux  mariadb    -y  # screen
  
[https://blog.csdn.net/wwxy1995/article/details/99362666  tinyhttpd深入解析与源码剖析]
+
yum groupinstall "Development Tools" -y
 +
</pre>
 +
===CentOS7 安装ifconfig===
 +
<pre>
  
[https://blog.csdn.net/qq_40677350/article/details/90201758 Tinyhttpd-master 源码学习笔记1]
+
不知道dig 是哪个软件包 提供的 请用 yum provides  command #绝对路径
  
[https://blog.csdn.net/yzhang6_10/article/details/51534409  Tinyhttp源码分析]
+
yum  provides /sbin/ifconfig
  
[https://github.com/EZLippi/Tinyhttpd Tinyhttpd非官方镜像,Fork自sourceForge,仅供学习]
+
******
 +
net-tools-1.60-114.el6.x86_64 : Basic networking tools
 +
Repo        : base
 +
匹配来自于:
 +
Filename    : /sbin/ifconfig
 +
*****
  
 +
由上可见安装的软件为net-tools
  
 +
ifconfig, netstat, route, and other
  
 +
[root@centos7 hcmdb]# yum info  net-tools 
 +
已安装的软件包
 +
名称    :net-tools
 +
架构    :x86_64
 +
版本    :2.0
 +
发布    :0.17.20131004git.el7
 +
大小    :917 k
 +
源    :installed
 +
简介    : Basic networking tools
 +
网址    :http://sourceforge.net/projects/net-tools/
 +
协议    : GPLv2+
 +
描述    : The net-tools package contains basic networking tools,
 +
        : including ifconfig, netstat, route, and others.
 +
        : Most of them are obsolete. For replacement check iproute package.
  
[https://www.jianshu.com/p/18cfd6019296 tinyhttp源码分析]
+
yum -y  install net-tools  vim  wget
 +
#yum/dnf install net-tools  vim  wget
  
我把一些核心代码和相应的注释贴在这里,如果你感兴趣全部,可以移步我的github。
+
centos7精简安装后,使用中发现没有killall命令。
https://github.com/zhaozhengcoder/rebuild-the-wheel/tree/master/tinyhttpd
+
可以通过以下命令解决:
  
 +
yum install psmisc
 +
 +
简单介绍一下 psmisc :
  
[https://www.google.com/search?q=Tinyhttp+%E4%BB%A3%E7%A0%81%E5%AE%8C%E5%85%A8%E8%AE%B2%E8%A7%A3&newwindow=1&safe=active&sxsrf=ALeKk00sI_LE3rix9st768kTRNvSLADqfQ%3A1616990574286&source=hp&ei=blFhYIrjDoTcswW95aqACg&iflsig=AINFCbYAAAAAYGFffrh-H2QmmZeV5OlApkx5kRBpdYOT&oq=Tinyhttp+%E4%BB%A3%E7%A0%81%E5%AE%8C%E5%85%A8%E8%AE%B2%E8%A7%A3&gs_lcp=Cgdnd3Mtd2l6EANQ0QhY0Qhg2gpoAHAAeACAAQCIAQCSAQCYAQCgAQKgAQGqAQdnd3Mtd2l6&sclient=gws-wiz&ved=0ahUKEwiK0qGmz9TvAhUE7qwKHb2yCqAQ4dUDCAY&uact=5 Tinyhttp 代码完全讲解]
+
Psmisc软件包包含三个帮助管理/proc目录的程序。
 +
安装下列程序: fuser, killall,pstree和pstree.x11(到pstree的链接)
 +
fuser 显示使用指定文件或者文件系统的进程的PID。
 +
killall 杀死某个名字的进程,它向运行指定命令的所有进程发出信号。
 +
pstree 树型显示当前运行的进程。
 +
pstree.x11 与pstree功能相同,只是在退出前需要确认
  
==Mongoose-基于C的Web服务器代码学习 ==
 
  
[https://www.jianshu.com/p/745c03a8864a Mongoose-基于C的Web服务器 介绍和使用]
+
</pre>
  
 +
==常用软件==
 +
<pre>
  
[https://blog.csdn.net/hnzwx888/article/details/84971205  Web服务器----mongoose]
+
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  
https://github.com/cesanta/mongoose
+
yum install  nmap-ncat lsof -y #nc (nmap-ncat)
  
[https://www.cnblogs.com/skynet/archive/2010/07/24/1784110.html  Mongoose源码剖析:外篇之web服务器 ]
+
lsof -i:1080
  
[https://blog.csdn.net/lixiaogang_theanswer/article/details/102753370  Mongoose-6.14源码剖析之基础篇]
+
yum groupinstall "Development Libraries"
  
== 我的笔记 ==
+
yum groupinstall "Development Tools"
apue.3e/include/apue.h
 
=== chapter 1===
 
[https://zhuanlan.zhihu.com/p/136700729 APUE读书笔记-01UNIX系统概述]
 
  
这是原文学不过是 Second Edition  firefox 放大 就可以看  找一下 第三版本吧 Third Edition
 
https://vaqeteart.gitee.io/file_bed/shared/books/APUE2/toc.html
 
 
=understanding_unix_programming =
 
 
==chapter 2  who ==
 
 
===see also===
 
[https://blog.csdn.net/u010307522/article/details/72862589  who命令实现]
 
 
=C IDE=
 
 
https://www.jetbrains.com/zh-cn/clion/
 
 
[[Eclipse]]
 
 
[[Anjuta on linux]]
 
 
https://atom.io/
 
 
=pre=
 
init main( int argc, char *argv[]);
 
argc 是命令行参数的数目 也包括自身 没有后台的参数 那么 argc=1
 
 
argv 指向参数的各个指针所构成的数组, argv[0]表示命令本身,argv[1] 表示第一个参数
 
 
=基础=
 
 
==计算机为什么要用二进制==
 
Everything over Binary 模拟路转换成为数字电路
 
 
https://blog.csdn.net/weixin_44296862/article/details/95277924
 
 
https://blog.csdn.net/c46550/article/details/90951557
 
 
[https://wenku.baidu.com/view/77074002e009581b6ad9eb2c.html 一位全加器]
 
=== signed char 类型的范围为 -128~127===
 
<pre>
 
按八位来算:
 
在计算机里面是用补码表示的,128的二进制码是:10000000,这个东西在计算里面并不是128,因为最高位是符号,它是个负数,那么负数的原码是多少呢,我们知道如果补码的符号位为“1”,表示是一个负数,求原码的操作可以是:符号位为1,其余各位取反,然后再整个数加1。
 
所以,10000000取反后就是11111111,把符号位去了就是01111111再加1就是10000000就是-128了。
 
其实你看-127是10000001,这个很好理解,-128加1不就是-127
 
[https://blog.csdn.net/zy986718042/article/details/71699079 浅谈char类型范围]
 
 
补码表示时,-0和+0补码相同都是0 000 0000,所义导致可以多表示一个负数,...这个负数是最小的那个..
 
 
</pre>
 
</pre>
[https://blog.csdn.net/czg13548930186/article/details/52602279?ops_request_misc=&request_id=&biz_id=102&utm_term=%25E6%25B5%2585%25E6%259E%2590%25E4%25B8%25BA%25E4%25BB%2580%25E4%25B9%2588char%25E7%25B1%25BB%25E5%259E%258B%25E7%259A%2584%25E8%258C%2583%25E5%259B%25B4%25E6%2598%25AF%2520%25E2%2580%2594128~%2520127&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-52602279.pc_search_result_no_baidu_js  浅析为什么char类型的范围是 —128~+127]
 
 
 
[https://wenwen.sogou.com/z/q871193299.htm?ch=fromnewwenwen.pc char 其数值表示 范围的计算]
 
 
[https://www.bilibili.com/video/BV1Gt4y1D73z?from=search&seid=13506202580160943636 b站 C语言数据类型及数值范围]
 
  
===原码 补码 反码 ===
+
==nginx==
 
<pre>
 
<pre>
1.原码
+
yum install wget  -y
最高位表示符号位。剩下的位数,是这个数的绝对值的二进制
 
 
 
就比方说 一个完整的int型变量在内存中占的是4个字节,32位的编译器中 那么这时候他的二进制表示是00000000 00000000 00000000 00000000
 
 
 
所以
 
  
10的原码就是00000000 00000000 00000000 00001010
+
wget https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm
  
那么负数的原码就是例如
+
wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm
  
-10的原码10000000 00000000 00000000 00001010
+
yum install nginx  -y
 
 
符号位是第一位 0为正数 1为负数
 
 
 
2.反码
 
    正数的反码就是其原码.
 
 
 
    负数的反码就是在其原码的基础之上 符号位不变,其他位取反.
 
   
 
3.补码
 
 
 
    正数的补码就是其原码.
 
 
 
    负数的补码就是在其反码的基础之上+1
 
   
 
 
</pre>
 
</pre>
 
+
==jdk==
[https://www.cnblogs.com/wangxiaoqi/p/6419676.html  C语言中的原码、反码和补码 ]
 
 
 
[https://www.cnblogs.com/burningc/p/10741253.html  C语言之原码、反码和补码 ]
 
 
 
[https://blog.csdn.net/liuyangsyouxiang/article/details/6050525  C语言——源码、反码、补码]
 
 
 
[https://www.bilibili.com/video/BV1Wx411g7Jg/?spm_id_from=333.788.videocard.1 b站原码 反码 补码]
 
 
 
=gdb=
 
 
<pre>
 
<pre>
 +
java.security.InvalidKeyException: Illegal key size or default parameters
  
 +
new vm 就要加上 unlime
  
 
+
  文件 UnlimitedJCEPolicyJDK7.zip
start  st 开始执行程序,在main函数的第一条语句前面停下来
+
规制办法
step      s  下一条语句,如果该语句为函数调用,则进入函数执行其中的第一条语句
+
evan@evankalilatop:~/xk/jdk$ cat jdkpath
  next    n  执行下一条语句,如果该语句为函数调用,不会进入函数内部执行(即不会一步步地调试函数内部语句)
+
替换 ${jdk_home}/jre/lib/security 下local_policy.jar, US_export_policy.jar
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
使用例子  结合他看C代码 爽到不行了
 
184
 
185gcc -g 11.2.c -o 11.2
 
186gdb 11.2
 
187
 
188(gdb) start
 
189(gdb) s  #一直用step命令(简写为s)进入函数中 ,n命令呢
 
190
 
191
 
192step s  下一条语句,如果该语句为函数调用,则进入函数执行其中的第一条语句
 
193next n  执行下一条语句,如果该语句为函数调用,不会进入函数内部执行(即不会一步步地调试函数内部语句)
 
 
 
 
</pre>
 
</pre>
  
=c=
+
==修改文件句柄数==
 
<pre>
 
<pre>
 +
#临时修改,立刻生效
 +
ulimit -n 655350       
  
/*                                                                                                                                                                                        
+
#永久修改
20答案是 Tuesday  因为列数定了是10                                                                                                                                                           
+
echo "* soft nofile 655360" >> /etc/security/limits.conf
21days[2] === days[2][10]                                                                                                                                                                   
+
echo "* hard nofile 655360" >> /etc/security/limits.conf
22                                                                                                                                                                                           
 
23解说                                                                                                                                                                                       
 
24days[2][0]=T                                                                                                                                                                               
 
25days[2][1]=u                                                                                                                                                                               
 
26days[2][2]=e                                                                                                                                                                               
 
27days[2][3]=s                                                                                                                                                                               
 
28days[2][4]=d                                                                                                                                                                               
 
29days[2][5]=a                                                                                                                                                                               
 
30days[2][6]=y                                                                                                                                                                               
 
31days[2][7]=                                                                                                                                                                               
 
32days[2][8]=                                                                                                                                                                               
 
33days[2][9]=                                                                                                                                                                               
 
34                                                                                                                                                                                           
 
35               
 
 
</pre>
 
</pre>
==eg ==
+
[https://www.jianshu.com/p/23ee9db2a620 使用ulimit 命令、/etc/security/limits.conf、proc 调整系统参数]
=== 石头剪刀布===
 
<pre>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <time.h>
 
  
int main(void)
+
==kernel 优化==
{
 
char gesture[3][10] = { "scissor", "stone", "cloth" };
 
int man, computer, result, ret;
 
 
 
srand(time(NULL));
 
while (1) {
 
computer = rand() % 3;
 
  printf("\nInput your gesture (0-scissor 1-stone 2-cloth):\n");
 
ret = scanf("%d", &man);
 
  if (ret != 1 || man < 0 || man > 2) {
 
printf("Invalid input! Please input 0, 1 or 2.\n");
 
continue;
 
}
 
printf("Your gesture: %s\tComputer's gesture: %s\n",
 
gesture[man], gesture[computer]);
 
 
 
result = (man - computer + 4) % 3 - 1;
 
if (result > 0)
 
printf("You win!\n");
 
else if (result == 0)
 
printf("Draw!\n");
 
else
 
printf("You lose!\n");
 
}
 
return 0;
 
}
 
 
 
 
 
/*
 
0、1、2三个整数分别是剪刀石头布在程序中的内部表示,用户也要求输入0、1或2,然后和计算机随机生成的0、1或2比胜负。这个程序的主体是一个死循环,需要按Ctrl-C退出程序。以往我们写的程序都只有打印输出,在这个程序中我们第一次碰到处理用户输入的情况。在这里只是简单解释一下,以后再细讲。scanf("%d", &man)这个调用的功能是等待用户输入一个整数并回车,这个整数会被scanf函数保存在man这个整型变量里。如果用户输入合法(输入的确实是整数而不是字符串),则scanf函数返回1,表示成功读入一个数据。但即使用户输入的是整数,我们还需要进一步检查是不是在0~2的范围内,写程序时对用户输入要格外小心,用户有可能输入任何数据,他才不管游戏规则是什么。
 
 
 
和printf类似,scanf也可以用%c、%f、%s等转换说明。如果在传给scanf的第一个参数中用%d、%f或%c表示读入一个整数、浮点数或字符,则第二个参数的形式应该是&运算符加一个相应类型的变量名,表示读进来的数存到这个变量中;如果在第一个参数中用%s读入一个字符串,则第二个参数应该是数组名,数组名前面不加&,因为数组类型做右值时自动转换成指针类型,而scanf后面这个参数要的就是指针类型,在第 10 章 gdb有scanf读入字符串的例子。&运算符的作用也是得到一个指针类型,这个运算符以后再详细解释。
 
 
 
留给读者的思考问题是:(man - computer + 4) % 3 - 1这个神奇的表达式是如何比较出0、1、2这三个数字在“剪刀石头布”意义上的大小的
 
*/
 
 
 
</pre>
 
 
 
[https://wenku.baidu.com/view/55e520da5022aaea998f0f5e.html 石头剪刀布_C语言]
 
 
 
https://blog.csdn.net/guoqingchun/article/details/8104197
 
 
 
 
 
===Linux下C语言获取目录中的文件列表 ===
 
 
<pre>
 
<pre>
/*
+
#set sysctl 有空把这些意思拿出来
  * dir.c
+
sysctl_config(){
  *
+
cp /etc/sysctl.conf /et/sysctl.conf.bak
Linux下C语言获取目录中的文件列表 https://www.cnblogs.com/dgwblog/p/12158373.html
+
cat > /etc/sysctl.conf << EOF
http://c.biancheng.net/cpp/html/1548.html 怎样使用C语言列出某个目录下的文件?
+
  net.ipv4.ip_forward = 0
  * Created on: 2020年11月2日
+
  net.ipv4.conf.default.rp_filter = 1
  *      Author: evan
+
  net.ipv4.conf.default.accept_source_route = 0
  */
+
kernel.sysrq = 0
#include <sys/types.h>
+
kernel.core_uses_pid = 1
#include <dirent.h>
+
net.ipv4.tcp_syncookies = 1
#include <unistd.h>
+
  kernel.msgmnb = 65536
#include <stdio.h>
+
  kernel.msgmax = 65536
int main(){
+
  kernel.shmmax = 68719476736
DIR *dir;
+
  kernel.shmall = 4294967296
struct dirent *ptr;
+
  net.ipv4.tcp_max_tw_buckets = 6000
dir = opendir("/home/evan/t1/");
+
net.ipv4.tcp_sack = 1
while((ptr = readdir(dir)) != NULL)
+
net.ipv4.tcp_window_scaling = 1
printf("d_name:%s\n",ptr->d_name);
+
net.ipv4.tcp_rmem = 4096 87380 4194304
closedir(dir);
+
net.ipv4.tcp_wmem = 4096 16384 4194304
return 0;
+
net.core.wmem_default = 8388608
 +
net.core.rmem_default = 8388608
 +
  net.core.rmem_max = 16777216
 +
net.core.wmem_max = 16777216
 +
net.core.netdev_max_backlog = 262144
 +
net.core.somaxconn = 262144
 +
net.ipv4.tcp_max_orphans = 3276800
 +
net.ipv4.tcp_max_syn_backlog = 262144
 +
net.ipv4.tcp_timestamps = 0
 +
net.ipv4.tcp_synack_retries = 1
 +
net.ipv4.tcp_syn_retries = 1
 +
net.ipv4.tcp_tw_recycle = 1
 +
net.ipv4.tcp_tw_reuse = 1
 +
net.ipv4.tcp_mem = 94500000 915000000 927000000
 +
net.ipv4.tcp_fin_timeout = 1
 +
net.ipv4.tcp_keepalive_time = 1200
 +
net.ipv4.ip_local_port_range = 1024 65535
 +
EOF
 +
/sbin/sysctl -p
 +
echo "sysctl set OK!!"
 
}
 
}
  
  
/* 结果
+
使用PAM模块限制资源:
*
+
# vi /etc/pam.d/login
d_name:.
+
session required pam_limits.so
d_name:..
 
d_name:1.py
 
d_name:22.py
 
 
 
*/
 
 
 
 
 
 
</pre>
 
</pre>
  
=排序与查找=
+
==可以禁用ipv6 ==
==插入排序 ==
 
 
<pre>
 
<pre>
#include <stdio.h>
+
cat >> /etc/modprobe.d/ipv6.conf <<EOF
#define LEN 5
+
alias net-pf-10 off
int a[LEN] = { 10, 5, 2, 4, 7 };
+
alias ipv6 off
void insertion_sort(void)
+
EOF
{
 
int i, j, key;
 
for (j = 1; j < LEN; ++j) {
 
printf("%d, %d, %d, %d, %d\n",
 
      a[0], a[1], a[2], a[3], a[4]);
 
key = a[j];  //key 标记为未排序的第一个元素
 
i = j - 1;
 
                // key  与已排序元素从大到小比较,寻找key应插入的元素 a[i+1]一般就是key 起初的值
 
////采用顺序查找方式找到插入的位置,在查找的同时,将数组中的元素进行后移操作,给插入元素腾出空间 ?
 
 
 
while (i >= 0 && a[i] > key) {
 
a[i+1] = a[i];
 
--i; //跳出while
 
}
 
a[i+1] = key; ////插入到正确位置
 
}
 
printf("%d, %d, %d, %d, %d\n",
 
      a[0], a[1], a[2], a[3], a[4]);
 
}
 
int main(void)
 
{
 
insertion_sort();
 
return 0;
 
}
 
/* 就是key 一直和前面排好的比,找到正确的位置
 
10, 5, 2, 4, 7
 
5, 10, 2, 4, 7
 
2, 5, 10, 4, 7
 
2, 4, 5, 10, 7
 
2, 4, 5, 7, 10 */
 
 
</pre>
 
</pre>
  
 
+
==去除ssh远程DNS认证 ==
===算法的时间复杂度分析===
 
则总的执行时间粗略估计是(n-1)*(c1+c2+c5+m*(c3+c4))。 #怎么来的呢  线性函数  不记得了 要补一下
 
 
 
[https://blog.csdn.net/qq_25775935/article/details/88724130 插入排序算法及C语言实现]
 
 
 
 
 
==11.4 归并排序==
 
递归实现 归并排序
 
 
 
 
 
 
 
 
 
===see also===
 
 
 
 
 
还有下一节 ?
 
 
 
[https://www.bilibili.com/video/av73101599?from=search&seid=6748303640916868853 4-5 通过归并排序算法深入理解递归]
 
 
 
 
 
非递归
 
https://blog.csdn.net/zjy900507/article/details/80530336
 
 
 
=chapter 12 栈与队列=
 
==堆栈==
 
http://docs.linuxtone.org/ebooks/C&CPP/c/ch12s02.html
 
==3. 深度优先搜索 ==
 
未看
 
http://akaedu.github.io/book/ch12s03.html
 
 
 
 
 
=第 13 章 计算机中数的表示=
 
==1. 为什么计算机用二进制计数==
 
 
 
=第 14 章 计算机中数的表示=
 
 
 
[http://c.biancheng.net/cpp/html/437.html c语言基本数据类型short、int、long、char、float、double]
 
 
 
[https://www.cnblogs.com/luofay/p/6070613.html  C语言的基本数据类型 ]
 
 
 
 
 
[https://www.php.cn/csharp-article-443107.html c语言char是什么意思]
 
== 二进制制转十进制==
 
 
<pre>
 
<pre>
在 C 语言中, signed char 类型的范围为 -128~127,每本教科书上也这么写,但是没有哪一本书上(包括老师)也不会给你为什么是 -128~127,这个问题貌似看起来也很简单容易, 以至于不用去思考为什么,不是有一个整型范围的公式吗:  -2^(n-1)~2^(n-1)-1 (n为整型的内存占用位数),所以 int 类型 32 位那么就是 -(2^31) ~ 2^31-1 即 -2147483648~2147483647,但是为什么最小负数绝对值总比最大正数多 1 ,这个问题甚至有的工作几年的程序员都模棱两可,因为没有深入思考过,只知道书上这么写。于是,我不得不深入思考一下这个被许多人忽视的问题。
+
sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
 
+
sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
对于无符号整数,很简单,全部位都表示数值,比如 char 型,8位,用二进制表示为 0000 0000 ~ 1111 1111,1111 1111 最大即为十进制255,所以 unsigned char 的范围为 0~ 255,在这里普及一下 2 进制转十进制的方法, 二进制每一位的数值乘以它的位权(2^(n-1),n为自右向左的位),再相加,可得到十进制数,比如 :1111 1111 = 1*2^7 + 1*2^6 + 1*2^5 + 1*2^4 + 1*2^3 + 1*2^2 + 1*2^1 + 1*2^0 = 255 。
 
  
 +
sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/g" /etc/ssh/sshd_config
  
但是对于有符号整数,二进制的最高位表示正负,不表示数值,最高位为 0 时表示正数,为 1 时表示负数,这样一来,能表示数值的就剩下( n-1 )位了,
+
sed -i "s/^PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
比如 char a = -1;  那么二进制表示就为 1 0000001,1 表示为 0 0000001,所以 signed char 型除去符号位剩下的 7 位最大为 1111 111 = 127,再把符号加上,0 1111111 = 127,1 1111111 = -127,范围应该为 -127~127 ,同理 int 类型也一样,但是问题出来了,教科书上是 -128~127 啊,下面就剖析一下这个惊人的奇葩。 加上反码 看到这里
 
  
 +
systemctl restart sshd
  
再普及一下计算机内部整数存储形式,大家都知道计算机内部是以二进制来存贮数值的,无符号整数会用全部为来存储,有符号的整数,最高位当做符号位 ,其余为表示数值。
 
 
</pre>
 
</pre>
  
=第 17 章=
+
==关闭不要的用户和服务==
==3. 设备==
 
http://akaedu.github.io/book/ch17s03.html
 
 
 
=4. MMU=
 
按照离CPU由近到远的顺序依次是CPU寄存器、Cache、内存、硬盘,越靠近CPU的存储器容量越小但访问速度越快
 
http://akaedu.github.io/book/ch17s04.html
 
 
 
=Memory Hierarchy=
 
http://akaedu.github.io/book/ch17s05.html
 
 
 
=附录 A. 字符编码=
 
20191112
 
字符编码的高位 左边是也
 
 
 
=如何学习c=
 
 
 
== mongoose 开源http库==
 
有空学习这个作为C的入门例子
 
 
 
Mongoose是一个用C编写的网络库。它为客户端和服务器模式实现TCP,UDP,HTTP,WebSocket,CoAP,MQTT的事件驱动的非阻塞API。
 
[https://www.cnblogs.com/gardenofhu/p/6961343.html  mongoose 开源http库 ]
 
  
[https://www.cnblogs.com/lifan3a/articles/7478295.html  Mongoose 利用实现HTTP服务 ]
+
== 安全==
=funciton=
 
==strcmp  ==
 
 
<pre>
 
<pre>
C/C++函数,比较两个字符串
+
关闭 selinux 如果是在内网机器关了也没关系
  
strcmp函数是string compare(字符串比较)的缩写,用于比较两个字符串并根据比较结果返回整数
+
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
 +
setenforce 0
  
设这两个字符串为str1,str2,
+
查看SELinux状态
 +
getenforce
  
若str1==str2,则返回零;
 
  
若str1<str2,则返回负数;
+
#临时关闭防火墙
 +
systemctl stop firewalld
 +
#永久防火墙开机自启动
 +
systemctl disable firewalld
 +
#临时打开防火墙
 +
systemctl start firewalld
 +
#防火墙开机启动
 +
systemctl enable firewalld
 +
#查看防火墙状态
 +
systemctl status firewalld
  
若str1>str2,则返回正数。
 
</pre>
 
[https://baike.baidu.com/item/strcmp/5495571 strcmp]
 
  
https://baike.so.com/doc/61175-64376.html
+
新机器 测试 web 不关闭可能报错
==C library function - remove()==
+
ERR_ADDRESS_UNREACHABLE
<pre>
 
/*
 
* remvoe.c
 
*
 
*  Created on: 2020年11月30日
 
  *      Author: evan
 
*/
 
#include <stdio.h>
 
#include<string.h>
 
  
int main() {
 
int ret;
 
FILE *fp;
 
char filename[] = "file.txt";  // 这个是什么意思  定义一个 数组 ? 是的 
 
 
fp = fopen(filename,"w");
 
 
fprintf(fp,"%s", "THis is tutor \n");
 
fprintf(fp,"%s", "ln2 THis is tutor");
 
fclose(fp);
 
 
//ret = remove(filename);
 
/*
 
cat file.txt
 
THis is tutor*/
 
 
if(ret == 0) {
 
printf("file deleted successfully");
 
}else {
 
printf("Error: unable to delte the file");
 
}
 
return(0);
 
 
}
 
  
 +
fail2ban
  
 
</pre>
 
</pre>
  
== C语言perror函数的作用 ==
+
==设置时区==
 +
如果时间不对 请 看
 +
[[Linux时间同步的那些事儿]]
 
<pre>
 
<pre>
 不可以掉了这个头文件,perror是包含在这个文件里的//编辑本段perror表头文件完善版定义函数
 
  void perror(const char *s); perror ("open_port");
 
函数说明
 
  perror ( )用 来 将 上 一 个 函 数 发 生 错 误 的 原 因 输 出 到 标 准 设备 (stderr) 。参数 s 所指的字符串会先打印出,后面再加上错误原因字符串。此错误原因依照全局变量errno 的值来决定要输出的字符串。   在库函数中有个errno变量,每个errno值对应着以字符串表示的错误类型。当你调用"某些"函数出错时,该函数已经重新设置了errno的值。perror函数只是将你输入的一些信息和现在的errno所对应的错误一起输出。
 
 
void perror(const char *str)
 
 
参数
 
 
    str -- 这是 C 字符串,包含了一个自定义消息,将显示在原本的错误消息之前
 
 
#include <stdio.h>   
 
int main(void)   
 
{   
 
FILE *fp ;   
 
fp = fopen( "/root/noexitfile", "r+" );   
 
if ( NULL == fp )  ?
 
{   
 
perror("/root/noexitfile");   //下面有这个输出
 
}   
 
return 0;   
 
}
 
 
运行结果
 
[root@localhost io]# gcc perror.c   
 
[root@localhost io]# ./a.out   
 
/root/noexitfile: No such file or directory
 
  
 +
yum install ntp
 +
  timedatectl set-ntp true
 
</pre>
 
</pre>
  
 
 
[https://blog.csdn.net/ypist/article/details/7886209  linux下 C语言perror函数的作用]
 
 
https://www.cnblogs.com/yujianfei/p/8973867.html
 
 
https://www.runoob.com/cprogramming/c-function-perror.html
 
 
 
==c语言实现rm命令 or 删除==
 
 
<pre>
 
<pre>
头文件:#include <stdio.h>
+
rm -f /etc/localtime
 
+
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
remove()函数用于删除指定的文件,其原型如下:
 
    int remove(char * filename);
 
 
 
【参数】filename为要删除的文件名,可以为一目录。如果参数filename 为一文件,则调用unlink()处理;若参数filename 为一目录,则调用rmdir()来处理。
 
 
 
【返回值】成功则返回0,失败则返回-1,错误原因存于errno。
 
 
</pre>
 
</pre>
  
[https://blog.csdn.net/teleger/article/details/80537229?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.pc_relevant_is_cache&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.pc_relevant_is_cache  C语言remove()函数:删除文件或目录]
+
==参考==
 
 
[https://blog.csdn.net/piaoliangjinjin/article/details/80707139?utm_medium=distribute.pc_relevant.none-task-blog-title-7&spm=1001.2101.3001.4242  linux下实现rm()函数删除文件或目录]
 
 
 
[https://blog.csdn.net/qq_38074673/article/details/98047329  c语言实现rm命令,删除指定文件或目录]
 
 
 
==C语言access()函数:判断是否具有存取文件的权限==
 
 
 
 
 
[http://c.biancheng.net/cpp/html/303.html C语言access()函数:判断是否具有存取文件的权限]
 
 
 
[https://blog.csdn.net/eager7/article/details/8131169  C语言中access函数]
 
 
 
[https://www.runoob.com/cprogramming/c-arrays.html C 数组]
 
 
 
 
 
=进阶=
 
==十个经典的C开源项目代码==
 
[https://blog.51cto.com/chinalx1/2143904 十个经典的C开源项目代码]
 
 
 
 
 
=2021=
 
  
 +
[https://www.jianshu.com/p/d0ef5bd18610 centos7初始化脚本.bash]
  
[https://www.cnblogs.com/wucongzhou/p/12498740.html#%E4%B8%80%E3%80%81%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E5%B7%A5%E4%BD%9C%E7%9B%AE%E5%BD%95 C语言目录操作]
+
[https://blog.csdn.net/kxwinxp/article/details/78895373 CentOS 7 运维优化]
  
[http://www.freecplus.net C语言技术网]
+
[https://blog.csdn.net/wh211212/article/details/52923673 CentOS 7安装完成后初始化]
  
[https://www.cnblogs.com/qigaohua/p/5838263.html      博客园  C语言中关于对目录的操作 ]
+
[https://blog.51cto.com/wzlinux/2043592 CentOS 7 新装服务器部署流程]
  
=书=
+
[https://www.cnblogs.com/sdhzdtwhm/p/8027928.html CentOS7操作系统初始化]
[https://www.codetd.com/article/2162329 《Linux环境C程序设计(第2版)徐诚》pdf 附下载链接]
 
  
http://www.txtepub.com/105693.html
+
[https://linux.cn/article-5067-1.html 如何使用 fail2ban 防御 SSH 服务器的暴力破解攻击]
  
=see also=
+
[http://www.cnblogs.com/txk1452/p/6361559.html CentOS7 安装ifconfig]
[https://wiki.ubuntu.com.cn/C%E8%AF%AD%E8%A8%80%E7%AE%80%E8%A6%81%E8%AF%AD%E6%B3%95%E6%8C%87%E5%8D%97 C语言简要语法指南]
 
  
https://wiki.ubuntu.com.cn/Compiling_C
+
[http://blog.51cto.com/feihan21/1060365 Linux服务器初始化配置脚本]
  
[https://wiki.ubuntu.com.cn/Gcchowto Gcc-howto]
+
[https://blog.imdst.com/linux-fu-wu-qi-chu-shi-hua-an-quan-jia-gu/ Linux服务器初始化调优及安全加固]
  
=c++=
 
  
[https://zh.wikipedia.org/wiki/C%2B%2B c++ zh.wikipedia.org]
+
[https://www.cnblogs.com/stulzq/p/7610100.html Centos7 初始化硬盘分区、挂载]
  
https://isocpp.org/
+
==kernel==
[[category:c]]
+
[https://blog.csdn.net/lufeisan/article/details/53339991 Linux系统swappiness参数在内存与交换分区之间优化作用]
 +
[[category:linux]][[category:ops]]

2021年4月24日 (六) 07:51的版本

站内相关资源

容器初始化

如果机器多Salt-ssh批量初始化机器

Salt-ssh批量初始化机器

如果机器少

我现在用的shell

#!/bin/bash
#Authon: linuxsa.org 201911
# usage bash  osinit.sh 2>&1 | tee osinit.log  
#http://wiki.linuxchina.net/index.php/Centos7%E5%88%9D%E5%A7%8B%E5%8C%96

#常用开发包 gcc etc 
yum groupinstall "Development Tools" -y 
#常用命令 ifconfig etc
yum install -y   net-tools    yum-utils rsync

yum install epel-release -y
yum install iftop tcpdump  -y

# ins docker 
# step 1: 安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# Step 3: 更新并安装 Docker-CE
yum makecache fast

 yum -y install docker-ce
# Step 4: 开启Docker服务
systemctl enable docker
systemctl start docker


rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

yum install zabbix-agent -y   && systemctl  enable zabbix-agent

#install docker-compose etc 

yum -y install vim wget curl yum-utils bash-completion bash-completion-extras epel-release lrzsz telnet python-pip
#这个看情况
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#mv  docker-compose /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
#pip install docker-compose

#mkdir -p /home/data/docker
mkdir -p  /data/docker

echo '{"graph": "/data/docker"}' >/etc/docker/daemon.json

# cat /etc/docker/daemon.json 
#{"graph": "/home/data/docker"}

systemctl restart docker

#验证docker储存位置
docker system info | grep "Root Dir"

#开机自启动要用的

chmod +x /etc/rc.d/rc.local

setenforce 0
sed -i 's/enforcing/disabled/g' /etc/selinux/config

#firewall
systemctl enable firewalld


#修改源
#CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

#CentOS 8
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
#或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

#3. 运行 yum makecache 生成缓存
yum makecache 

centos7初始化

ssh config

echo "ssh-rsa AAAAB3NzaC you_prk_key root@ops
"  >> /root/.ssh/authorized_keys

sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/g" /etc/ssh/sshd_config

sed -i "s/^PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config

systemctl restart sshd
#service  sshd restart

网络配置

cat  /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE="Ethernet"
BOOTPROTO=static  
IPADDR0=192.168.0.16
NETMASK=255.255.255.0  
GATEWAY0=192.168.0.1 
DNS1=223.5.5.5  
DNS2=114.114.114.114 

DEVICE="eth0"
ONBOOT="yes"

安装常用软件

 yum install python-devel
 yum install vim  wget  net-tools  psmisc links  lsof telnet  zlib-devel curl  tmux  mariadb     -y  # screen

yum groupinstall "Development Tools" -y

CentOS7 安装ifconfig


不知道dig 是哪个软件包 提供的  请用 yum provides  command #绝对路径 

yum  provides /sbin/ifconfig

******
net-tools-1.60-114.el6.x86_64 : Basic networking tools
Repo        : base
匹配来自于:
Filename    : /sbin/ifconfig
*****

由上可见安装的软件为net-tools

ifconfig, netstat, route, and other

[root@centos7 hcmdb]# yum info  net-tools  
已安装的软件包
名称    :net-tools
架构    :x86_64
版本    :2.0
发布    :0.17.20131004git.el7
大小    :917 k
源    :installed
简介    : Basic networking tools
网址    :http://sourceforge.net/projects/net-tools/
协议    : GPLv2+
描述    : The net-tools package contains basic networking tools,
         : including ifconfig, netstat, route, and others.
         : Most of them are obsolete. For replacement check iproute package.

yum -y  install net-tools  vim  wget 
#yum/dnf install net-tools  vim  wget 

centos7精简安装后,使用中发现没有killall命令。
可以通过以下命令解决:

yum install psmisc
 
简单介绍一下 psmisc :

Psmisc软件包包含三个帮助管理/proc目录的程序。
安装下列程序: fuser, killall,pstree和pstree.x11(到pstree的链接)
fuser 显示使用指定文件或者文件系统的进程的PID。
killall 杀死某个名字的进程,它向运行指定命令的所有进程发出信号。
pstree 树型显示当前运行的进程。
pstree.x11 与pstree功能相同,只是在退出前需要确认


常用软件


wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum install  nmap-ncat lsof -y #nc (nmap-ncat)

 lsof -i:1080

yum groupinstall "Development Libraries"

yum groupinstall "Development Tools"

nginx

yum install wget  -y

wget https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm

wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm

yum install nginx   -y

jdk

java.security.InvalidKeyException: Illegal key size or default parameters

new vm 就要加上 unlime

 文件 UnlimitedJCEPolicyJDK7.zip
规制办法 
evan@evankalilatop:~/xk/jdk$ cat jdkpath 
替换 ${jdk_home}/jre/lib/security 下local_policy.jar, US_export_policy.jar

修改文件句柄数

#临时修改,立刻生效
ulimit -n 655350         

#永久修改
echo "* soft nofile 655360" >> /etc/security/limits.conf
echo "* hard nofile 655360" >> /etc/security/limits.conf

使用ulimit 命令、/etc/security/limits.conf、proc 调整系统参数

kernel 优化

#set sysctl 有空把这些意思拿出来
sysctl_config(){
cp /etc/sysctl.conf /et/sysctl.conf.bak
cat > /etc/sysctl.conf << EOF
 net.ipv4.ip_forward = 0
 net.ipv4.conf.default.rp_filter = 1
 net.ipv4.conf.default.accept_source_route = 0
 kernel.sysrq = 0
 kernel.core_uses_pid = 1
 net.ipv4.tcp_syncookies = 1
 kernel.msgmnb = 65536
 kernel.msgmax = 65536
 kernel.shmmax = 68719476736
 kernel.shmall = 4294967296
 net.ipv4.tcp_max_tw_buckets = 6000
 net.ipv4.tcp_sack = 1
 net.ipv4.tcp_window_scaling = 1
 net.ipv4.tcp_rmem = 4096 87380 4194304
 net.ipv4.tcp_wmem = 4096 16384 4194304
 net.core.wmem_default = 8388608
 net.core.rmem_default = 8388608
 net.core.rmem_max = 16777216
 net.core.wmem_max = 16777216
 net.core.netdev_max_backlog = 262144
 net.core.somaxconn = 262144
 net.ipv4.tcp_max_orphans = 3276800
 net.ipv4.tcp_max_syn_backlog = 262144
 net.ipv4.tcp_timestamps = 0
 net.ipv4.tcp_synack_retries = 1
 net.ipv4.tcp_syn_retries = 1
 net.ipv4.tcp_tw_recycle = 1
 net.ipv4.tcp_tw_reuse = 1
 net.ipv4.tcp_mem = 94500000 915000000 927000000
 net.ipv4.tcp_fin_timeout = 1
 net.ipv4.tcp_keepalive_time = 1200
 net.ipv4.ip_local_port_range = 1024 65535
EOF
/sbin/sysctl -p
echo "sysctl set OK!!"
}


使用PAM模块限制资源:
# vi /etc/pam.d/login
session required pam_limits.so 

可以禁用ipv6

cat >> /etc/modprobe.d/ipv6.conf <<EOF
alias net-pf-10 off
alias ipv6 off
EOF

去除ssh远程DNS认证

sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config

sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/g" /etc/ssh/sshd_config

sed -i "s/^PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config

systemctl restart sshd

关闭不要的用户和服务

安全

关闭 selinux 如果是在内网机器关了也没关系 

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0

查看SELinux状态
getenforce


#临时关闭防火墙
systemctl stop firewalld
#永久防火墙开机自启动
systemctl disable firewalld
#临时打开防火墙
systemctl start firewalld
#防火墙开机启动
systemctl enable firewalld
#查看防火墙状态
systemctl status firewalld


新机器 测试 web  不关闭可能报错
ERR_ADDRESS_UNREACHABLE


fail2ban

设置时区

如果时间不对 请 看 

Linux时间同步的那些事儿


 yum install ntp 
  timedatectl set-ntp true
rm -f /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

参考

centos7初始化脚本.bash

CentOS 7 运维优化

CentOS 7安装完成后初始化

CentOS 7 新装服务器部署流程

CentOS7操作系统初始化

如何使用 fail2ban 防御 SSH 服务器的暴力破解攻击

CentOS7 安装ifconfig

Linux服务器初始化配置脚本

Linux服务器初始化调优及安全加固


Centos7 初始化硬盘分区、挂载

kernel

Linux系统swappiness参数在内存与交换分区之间优化作用