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

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
 
 
第1行: 第1行:
  
 +
[[Salt-ssh批量初始化机器]]
 +
[https://debian-handbook.info/browse/zh-CN/stable/sect.how-to-migrate.html Debian 管理员手册]
 +
=os install=
 +
有时候会出现 select  and install software  等等几个小时的情况 应该是不要选择mirrors就好了 安装后再自己加
 +
= os init=
 +
Gentoo Linux 手册 非常有学习的价值
  
 +
[[容器初始化]]
 +
== change sources ==
 +
==if docker==
 +
[[利用Dockerfile修改容器中的apt源(debian源)]]
 +
===10源===
 +
<pre>
  
+
deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
good
+
deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib
http://akaedu.github.io/book/
+
deb http://mirrors.aliyun.com/debian-security buster/updates main
 
+
deb-src http://mirrors.aliyun.com/debian-security buster/updates main
 
+
deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
[https://zhuanlan.zhihu.com/p/90971489 C语言编程学习必备的一些网站,干货收藏!]
+
deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
 
+
deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
[https://www.bilibili.com/video/BV17s411N78s/?spm_id_from=333.788.videocard.0 带你学C带你飞》]
+
deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
 
 
=2021学习C APUE=
 
http://www.apuebook.com/
 
 
 
[https://www.zhihu.com/topic/19705459/hot UNIX环境高级编程(书籍)笔记什么都 有呀 ]
 
 
 
[https://www.zhihu.com/question/19939011 《UNIX环境高级编程》这本书怎么看?怎么学习]
 
 
 
 
 
 
 
==看法  ==
 
第二章和第六章可以跳跳,回头看
 
 
 
7.中文版翻译有瑕疵,但是整体还是不错,不至于对阅读产生影响(信号量那章有细节问题,但是信号量那张和csapp第八章几乎重复)
 
 
 
首先,不要抱着一口气把这本书学完的心态去看。      尝试根据自己的兴趣,选择一个规模适当的开源项目,去阅读它的源代码。(例如我选择的就是一个小型的http服务器--Mongoose)当在某一方面发现自己有很多问题时,很希望去弄清楚时,这时候就可以去翻开手中的APUE,带着问题去阅读。这时候学习的效率必然比盲目地去看书更高,而且遗忘率也会降低。但是,仅仅读完是不够的。      很多时候,你看书的时候,会感觉自己看懂了,但是没过多久,又会发现自己忘了。或者,有时候你根本没看懂,而只是囫囵吞枣地看过去。所以,看完后,最好的方法就是写博客。尝试按照自己的理解以及逻辑,去将你学到的知识系统地阐述出来。这样,就算你以后忘了,再去翻翻博文,也能很快就捡起来。
 
 
 
十个最值得阅读学习的C开源项目代码
 
 
 
    Webbench
 
    Tinyhttpd
 
    cJSON
 
    CMockery
 
    Libev
 
    Memcached
 
    Lua
 
    SQLite
 
    UNIX v6
 
    NETBSD
 
 
 
建议先看 >> Unix/Linux编程实践教程
 
 
 
https://book.douban.com/subject/1219329/
 
 
 
http://item.kongfz.com/book/32040616.html?push_type=2&min_price=57.00&utm_source=101004009001
 
 
 
https://detail.tmall.com/item.htm?spm=a1z10.1-b.w9858442-8055933095.4.fH3HiL&id=19729431809
 
 
 
[https://github.com/woai3c/recommended-books 常用计算机书的下载]
 
 
 
[https://blog.csdn.net/qwe6620692/article/details/88107248  学习C语言,如何看懂及掌握一个程序!]
 
 
 
[https://blog.51cto.com/chinalx1/2143904 十个经典的C开源项目代码]
 
 
 
[https://developer.51cto.com/art/201903/593703.htm 初学玩转C语言,这17个小项目收下不谢]
 
 
 
https://zhuanlan.zhihu.com/p/83185476
 
 
 
== tinyhttpd C 语言实现最简单的 HTTP 服务器 学习 ==
 
 
 
[https://www.shuzhiduo.com/A/ZOJPY9Ge5v/ tinyhttpd ------ C 语言实现最简单的 HTTP 服务器]
 
 
 
https://github.com/nengm/Tinyhttpd
 
 
 
[https://blog.csdn.net/baiwfg2/article/details/45582723  tinyhttpd源码详解]
 
 
 
[https://blog.csdn.net/konghhhhh/article/details/103752962  tinyhttp整理(一)]
 
 
 
[https://blog.csdn.net/weixin_30387663/article/details/99664160  tinyhttp源码阅读(注释)]
 
 
 
[https://juejin.cn/post/6870760453619122183  Tinyhttp源码分析及知识点总结 ]
 
 
 
[https://www.bilibili.com/video/BV1hy4y1C71M/?spm_id_from=333.788.videocard.1 b站 C/C++ tinyHttp服务器小项目及源码讲解1]
 
 
 
[https://blog.csdn.net/wwxy1995/article/details/99362666  tinyhttpd深入解析与源码剖析]
 
 
 
[https://blog.csdn.net/qq_40677350/article/details/90201758  Tinyhttpd-master 源码学习笔记1]
 
 
 
[https://blog.csdn.net/yzhang6_10/article/details/51534409  Tinyhttp源码分析]
 
 
 
[https://github.com/EZLippi/Tinyhttpd Tinyhttpd非官方镜像,Fork自sourceForge,仅供学习]
 
 
 
 
 
 
 
 
 
[https://www.jianshu.com/p/18cfd6019296 tinyhttp源码分析]
 
 
 
我把一些核心代码和相应的注释贴在这里,如果你感兴趣全部,可以移步我的github。
 
https://github.com/zhaozhengcoder/rebuild-the-wheel/tree/master/tinyhttpd
 
 
 
 
 
[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 代码完全讲解]
 
 
 
==Mongoose-基于C的Web服务器代码学习 ==
 
  
[https://www.jianshu.com/p/745c03a8864a Mongoose-基于C的Web服务器 介绍和使用]
 
 
 
[https://blog.csdn.net/hnzwx888/article/details/84971205  Web服务器----mongoose]
 
 
https://github.com/cesanta/mongoose
 
 
[https://www.cnblogs.com/skynet/archive/2010/07/24/1784110.html  Mongoose源码剖析:外篇之web服务器 ]
 
 
[https://blog.csdn.net/lixiaogang_theanswer/article/details/102753370  Mongoose-6.14源码剖析之基础篇]
 
 
== 我的笔记 ==
 
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]
+
===9 源===
 
 
 
 
[https://wenwen.sogou.com/z/q871193299.htm?ch=fromnewwenwen.pc char 其数值表示 范围的计算]
 
 
 
[https://www.bilibili.com/video/BV1Gt4y1D73z?from=search&seid=13506202580160943636 b站 C语言数据类型及数值范围]
 
 
 
===原码 补码 反码 ===
 
 
<pre>
 
<pre>
1.原码
 
最高位表示符号位。剩下的位数,是这个数的绝对值的二进制
 
 
就比方说 一个完整的int型变量在内存中占的是4个字节,32位的编译器中 那么这时候他的二进制表示是00000000 00000000 00000000 00000000
 
 
所以
 
 
10的原码就是00000000 00000000 00000000 00001010
 
 
那么负数的原码就是例如
 
 
-10的原码10000000 00000000 00000000 00001010
 
 
符号位是第一位 0为正数 1为负数
 
 
2.反码
 
    正数的反码就是其原码.
 
 
    负数的反码就是在其原码的基础之上 符号位不变,其他位取反.
 
   
 
3.补码
 
 
    正数的补码就是其原码.
 
  
    负数的补码就是在其反码的基础之上+1
+
echo 'deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib
   
+
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib
 +
deb http://mirrors.aliyun.com/debian-security stretch/updates main
 +
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
 +
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
 +
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
 +
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
 +
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib ' >sources.list
 
</pre>
 
</pre>
  
[https://www.cnblogs.com/wangxiaoqi/p/6419676.html  C语言中的原码、反码和补码 ]
+
== ssh config==
 
 
[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>
  
 +
openssh
  
 +
apt-get install openssh-client openssh-server
 +
这个要先安装 不然自启动会不成功
  
start  st 开始执行程序,在main函数的第一条语句前面停下来
+
如何激活服务并在启动时启用或禁用服务(即系统启动时自动启动服务)
step      s  下一条语句,如果该语句为函数调用,则进入函数执行其中的第一条语句
+
# systemctl is-active ssh.service
next    n  执行下一条语句,如果该语句为函数调用,不会进入函数内部执行(即不会一步步地调试函数内部语句)
+
systemctl enable ssh.service
 +
# systemctl disable ssh.service
  
  
  
 +
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
 +
sed -i "s/^#PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
  
 +
systemctl restart sshd
 +
#service  sshd restart
  
 +
补充
 +
服务端
 +
chown -R 0700  ~/.ssh
 +
chown -R 0644  ~/.ssh/authorized_keys
  
 
+
客户端改一下
使用例子  结合他看C代码 爽到不行了
+
chmod 600 id_rsa
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>
  
/*                                                                                                                                                                                         
+
#alias
20答案是 Tuesday 因为列数定了是10                                                                                                                                                           
+
cp /etc/profile /etc/profile_bak
21days[2] === days[2][10]                                                                                                                                                                   
+
echo "alias ll='ls $LS_OPTIONS -l'" >>/etc/profile  &&  source /etc/profile
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>
 
==eg ==
 
=== 石头剪刀布===
 
<pre>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <time.h>
 
  
int main(void)
 
{
 
char gesture[3][10] = { "scissor", "stone", "cloth" };
 
int man, computer, result, ret;
 
  
srand(time(NULL));
+
useradd -d /data/evan  -s /bin/bash -m  evan
while (1) {
+
数m表示如果该目录不存在,则创建该目录
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;
 
}
 
  
 +
apt install net-tools procps  rsync wget  w3m    vim  build-essential dnsutils tmux  curl sudo lsb-release  iotop software-properties-common  -y  # 说明 dig dnsutils  firewalld  screen 暂时不要
  
/*
+
#全面的开发工具
0、1、2三个整数分别是剪刀石头布在程序中的内部表示,用户也要求输入0、1或2,然后和计算机随机生成的0、1或2比胜负。这个程序的主体是一个死循环,需要按Ctrl-C退出程序。以往我们写的程序都只有打印输出,在这个程序中我们第一次碰到处理用户输入的情况。在这里只是简单解释一下,以后再细讲。scanf("%d", &man)这个调用的功能是等待用户输入一个整数并回车,这个整数会被scanf函数保存在man这个整型变量里。如果用户输入合法(输入的确实是整数而不是字符串),则scanf函数返回1,表示成功读入一个数据。但即使用户输入的是整数,我们还需要进一步检查是不是在0~2的范围内,写程序时对用户输入要格外小心,用户有可能输入任何数据,他才不管游戏规则是什么。
+
sudo apt  install git golang build-essential gcc g++ gdb libboost-dev make automake autogen autoconf cscope global cmake cmake-gui astyle clang-format clang llvm lldb libsqlite3-dev sqlite3 bison flex ruby-dev linux-headers-`uname -r`
  
和printf类似,scanf也可以用%c、%f、%s等转换说明。如果在传给scanf的第一个参数中用%d、%f或%c表示读入一个整数、浮点数或字符,则第二个参数的形式应该是&运算符加一个相应类型的变量名,表示读进来的数存到这个变量中;如果在第一个参数中用%s读入一个字符串,则第二个参数应该是数组名,数组名前面不加&,因为数组类型做右值时自动转换成指针类型,而scanf后面这个参数要的就是指针类型,在第 10 章 gdb有scanf读入字符串的例子。&运算符的作用也是得到一个指针类型,这个运算符以后再详细解释。
 
  
留给读者的思考问题是:(man - computer + 4) % 3 - 1这个神奇的表达式是如何比较出0、1、2这三个数字在“剪刀石头布”意义上的大小的
+
#ps 说明
*/
+
apt install procps
  
</pre>
+
mariadb-client
  
[https://wenku.baidu.com/view/55e520da5022aaea998f0f5e.html 石头剪刀布_C语言]
+
安装Fail2Ban
 +
</pre>
  
https://blog.csdn.net/guoqingchun/article/details/8104197
+
[https://www.debian.cn/archives/2880 Debian 安装 fail2ban 方式SSH爆破攻击]
  
  
===Linux下C语言获取目录中的文件列表 ===
+
[[Debian配置iptables]]
<pre>
 
/*
 
* dir.c
 
*
 
Linux下C语言获取目录中的文件列表  https://www.cnblogs.com/dgwblog/p/12158373.html
 
http://c.biancheng.net/cpp/html/1548.html  怎样使用C语言列出某个目录下的文件?
 
*  Created on: 2020年11月2日
 
*      Author: evan
 
*/
 
#include <sys/types.h>
 
#include <dirent.h>
 
#include <unistd.h>
 
#include <stdio.h>
 
int main(){
 
DIR *dir;
 
struct  dirent *ptr;
 
dir = opendir("/home/evan/t1/");
 
while((ptr = readdir(dir)) != NULL)
 
printf("d_name:%s\n",ptr->d_name);
 
closedir(dir);
 
return 0;
 
}
 
  
 
+
=时间同步=
/* 结果
 
*
 
d_name:.
 
d_name:..
 
d_name:1.py
 
d_name:22.py
 
 
 
*/
 
 
 
 
 
</pre>
 
 
 
=排序与查找=
 
==插入排序 ==
 
 
<pre>
 
<pre>
#include <stdio.h>
+
UTC时区切换到CST 时区
#define LEN 5
 
int a[LEN] = { 10, 5, 2, 4, 7 };
 
void insertion_sort(void)
 
{
 
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];
+
# 设置亚洲时区  tzselect 有时不准
--i; //跳出while
+
timedatectl set-timezone Asia/Shanghai
}
+
# 启用NTP同步 #关闭是 false
a[i+1] = key; ////插入到正确位置
+
timedatectl set-ntp yes
}
 
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>
 
  
  
===算法的时间复杂度分析===
 
则总的执行时间粗略估计是(n-1)*(c1+c2+c5+m*(c3+c4))。 #怎么来的呢  线性函数  不记得了 要补一下
 
  
[https://blog.csdn.net/qq_25775935/article/details/88724130 插入排序算法及C语言实现]
+
echo "export TZ='Asia/Shanghai'"  >> /etc/profile 
 +
cat /etc/profile |grep TZ 
 +
source /etc/profile
  
 +
date -R  #时区查看
 +
date
 +
Sat Aug 19 17:03:17 CST 2017
  
==11.4 归并排序==
 
递归实现 归并排序
 
  
 +
校正日期和时间  linux256
  
 +
cp /usr/share/zoneinfo/Asia/ShangHai  /etc/localtime    #时区为亚洲/上海
 +
# 网络校时
 +
apt-get install ntpdate
 +
ntpdate 210.72.145.44        # 中国国家时间服务器: 210.72.145.44
  
 +
# 手动校时
 +
sudo date -s 11/13/2019                #2019年11月13日
 +
sudo date -s 10:05:30                  #10点05分30秒
  
===see also===
+
</pre>
 
 
 
 
还有下一节 ?
 
 
 
[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>
 
在 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 ,这个问题甚至有的工作几年的程序员都模棱两可,因为没有深入思考过,只知道书上这么写。于是,我不得不深入思考一下这个被许多人忽视的问题。
 
  
对于无符号整数,很简单,全部位都表示数值,比如 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 。
+
=security=
 +
==ufw==
  
 +
==firewalld==
 +
这个放弃了
  
但是对于有符号整数,二进制的最高位表示正负,不表示数值,最高位为 0 时表示正数,为 1 时表示负数,这样一来,能表示数值的就剩下( n-1 )位了,
+
详情可见 [[Centos7 firewalld防火墙基础]]
比如 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 啊,下面就剖析一下这个惊人的奇葩。 加上反码 看到这里
 
  
 +
[https://computingforgeeks.com/how-to-install-and-configure-firewalld-on-debian/ How To Install and Configure Firewalld on Debian 10]
  
再普及一下计算机内部整数存储形式,大家都知道计算机内部是以二进制来存贮数值的,无符号整数会用全部为来存储,有符号的整数,最高位当做符号位 ,其余为表示数值。
+
[https://ywnz.com/linuxaq/5495.html 在Debian 10(Buster)上安装和配置Firewalld]
</pre>
 
  
=第 17 章=
 
==3. 设备==
 
http://akaedu.github.io/book/ch17s03.html
 
  
=4. MMU=  
+
= 优化optimize=
按照离CPU由近到远的顺序依次是CPU寄存器、Cache、内存、硬盘,越靠近CPU的存储器容量越小但访问速度越快
 
http://akaedu.github.io/book/ch17s04.html
 
  
=Memory Hierarchy=
 
http://akaedu.github.io/book/ch17s05.html
 
  
=附录 A. 字符编码=
+
[https://github.com/mostamazing/mostamazing/issues/28 linux 里ulimit永久生效设置(debian9 64]
20191112
 
  字符编码的高位 左边是也
 
  
=如何学习c=
+
=9 update to 10=
 +
  sudo apt dist-upgrade -y #在之前改成 10的源
  
== mongoose 开源http库==
+
在QCLOUD上升级失败了  可以试一下他们自己的源
有空学习这个作为C的入门例子
+
https://mirrors.cloud.tencent.com/debian/dists/
  
Mongoose是一个用C编写的网络库。它为客户端和服务器模式实现TCP,UDP,HTTP,WebSocket,CoAP,MQTT的事件驱动的非阻塞API。
+
https://cloud.tencent.com/developer/article/1473368
[https://www.cnblogs.com/gardenofhu/p/6961343.html  mongoose 开源http库 ]
 
  
[https://www.cnblogs.com/lifan3a/articles/7478295.html  Mongoose 利用实现HTTP服务 ]
+
=故障=
=funciton=
+
==报错1 ==  
==strcmp  ==
 
 
<pre>
 
<pre>
C/C++函数,比较两个字符串
+
Reading package lists...
 
+
E: Release file for http://mirrors.ustc.edu.cn/debian/dists/stretch-updates/InRelease is expired (invalid since 69d 5h 56min 7s). Updates for this repository will not be applied.
strcmp函数是string compare(字符串比较)的缩写,用于比较两个字符串并根据比较结果返回整数
+
E: Release file for http://mirrors.ustc.edu.cn/debian/dists/stretch-backports/InRelease is expired (invalid since 69d 5h 56min 7s). Updates for this repository will not be applied.
 
+
E: Release file for http://mirrors.ustc.edu.cn/debian-security/dists/stretch/updates/InRelease is expired (invalid since 66d 14h 56min 48s). Updates for this repository will not be applied.
设这两个字符串为str1,str2,
+
ERROR: Service 'php-worker' failed to build: The command '/bin/sh -c apt-get  update' returned a non-zero code: 100
 
 
若str1==str2,则返回零;
 
 
 
若str1<str2,则返回负数;
 
 
 
若str1>str2,则返回正数。
 
 
</pre>
 
</pre>
[https://baike.baidu.com/item/strcmp/5495571 strcmp]
 
  
https://baike.so.com/doc/61175-64376.html
 
==C library function - remove()==
 
<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);
 
 
 
}
 
 
 
 
 
</pre>
 
 
 
== C语言perror函数的作用 ==
 
 
<pre>
 
<pre>
 不可以掉了这个头文件,perror是包含在这个文件里的//编辑本段perror表头文件完善版定义函数
+
###########################################################################
  void perror(const char *s); perror ("open_port");
+
# Crontab
函数说明
+
###########################################################################
  perror ( )用 来 将 上 一 个 函 数 发 生 错 误 的 原 因 输 出 到 标 准 设备 (stderr) 。参数 s 所指的字符串会先打印出,后面再加上错误原因字符串。此错误原因依照全局变量errno 的值来决定要输出的字符串。   在库函数中有个errno变量,每个errno值对应着以字符串表示的错误类型。当你调用"某些"函数出错时,该函数已经重新设置了errno的值。perror函数只是将你输入的一些信息和现在的errno所对应的错误一起输出。
+
RUN rm -f /etc/apt/sources.list
 
+
RUN rm -f /etc/apt/sources.list.d/buster.list
void perror(const char *str)
+
COPY  sources.list /etc/apt/
 +
RUN apt -o Acquire::Check-Valid-Until=false update
  
参数
+
RUN  apt-get  update 
 +
RUN  apt-get clean
 +
RUN  apt-get install -y apt-transport-https
 +
RUN  apt install -y cron vim
 +
RUN ["service","cron","start"]
  
    str -- 这是 C 字符串,包含了一个自定义消息,将显示在原本的错误消息之前
 
  
#include <stdio.h>   
+
cat php-worker/sources.list
int main(void)   
 
{   
 
FILE *fp ;   
 
fp = fopen( "/root/noexitfile", "r+" );   
 
if ( NULL == fp )  ?
 
{   
 
perror("/root/noexitfile");   //下面有这个输出
 
}   
 
return 0;   
 
}
 
  
运行结果
+
deb http://deb.debian.org/debian stretch main
[root@localhost io]# gcc perror.c   
 
[root@localhost io]# ./a.out   
 
/root/noexitfile: No such file or directory
 
  
 
</pre>
 
</pre>
  
 +
==报错2 ==
 +
Error message “sudo: unable to resolve host (none)”
  
 +
That /etc/hosts has an entry for localhost. It should have something like:
  
[https://blog.csdn.net/ypist/article/details/7886209 linux下 C语言perror函数的作用]
+
  127.0.0.1    localhost.localdomain localhost
 
+
127.0.1.1   you-hostname
https://www.cnblogs.com/yujianfei/p/8973867.html
 
 
 
https://www.runoob.com/cprogramming/c-function-perror.html
 
 
 
 
 
==c语言实现rm命令 or 删除==
 
<pre>
 
头文件:#include <stdio.h>
 
 
 
remove()函数用于删除指定的文件,其原型如下:
 
    int remove(char * filename);
 
 
 
【参数】filename为要删除的文件名,可以为一目录。如果参数filename 为一文件,则调用unlink()处理;若参数filename 为一目录,则调用rmdir()来处理。
 
 
 
【返回值】成功则返回0,失败则返回-1,错误原因存于errno。
 
</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://blog.chaos.run/dreams/ubuntu-server-starting-settings/index.html Debian服务器的初始化配置-Google Authenticator]
  
[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://www.debian.cn/archives/2880  Debian 安装 fail2ban 方式SSH爆破攻击]
  
[http://www.freecplus.net C语言技术网]
+
[https://blog.51cto.com/wzlinux/2043586 Ubuntu 新装服务器部署流程]
  
[https://www.cnblogs.com/qigaohua/p/5838263.html      博客园  C语言中关于对目录的操作 ]
+
[https://www.howtoing.com/install-java-in-debian-and-ubuntu 如何在Debian和Ubuntu系统中安装Java 9]
  
=书=
+
[http://www.ruanyifeng.com/blog/2014/03/server_setup.html Linux服务器的初步配置流程]
[https://www.codetd.com/article/2162329 《Linux环境C程序设计(第2版)徐诚》pdf 附下载链接]
 
  
http://www.txtepub.com/105693.html
+
[http://spenserj.com/blog/2013/07/15/securing-a-linux-server/ Securing a Linux Server]
  
=see also=
+
[http://blog.51cto.com/feihan21/1060365 Linux服务器初始化配置脚本]
[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
+
[https://blog.imdst.com/linux-fu-wu-qi-chu-shi-hua-an-quan-jia-gu/ Linux服务器初始化调优及安全加固]
  
[https://wiki.ubuntu.com.cn/Gcchowto Gcc-howto]
+
[https://linux.cn/article-5067-1.html 如何使用 fail2ban 防御 SSH 服务器的暴力破解攻击]
  
=c++=
+
[https://blog.csdn.net/developerinit/article/details/73065229?utm_source=blogxgwz7 Debian的一些常用命令]
  
[https://zh.wikipedia.org/wiki/C%2B%2B c++ zh.wikipedia.org]
 
  
https://isocpp.org/
+
[https://www.cnblogs.com/yoyotl/p/8151409.html Debian 8 设置时区和时间配置]
[[category:c]]
+
[[category:ops]]  [[category:debian]]

2021年4月25日 (日) 06:19的版本

Salt-ssh批量初始化机器 Debian 管理员手册

os install

有时候会出现 select  and install software  等等几个小时的情况 应该是不要选择mirrors就好了 安装后再自己加

os init

Gentoo Linux 手册 非常有学习的价值

容器初始化

change sources

if docker

利用Dockerfile修改容器中的apt源(debian源)

10源


deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb http://mirrors.aliyun.com/debian-security buster/updates main
deb-src http://mirrors.aliyun.com/debian-security buster/updates main
deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib

9 源


echo 'deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib ' >sources.list

ssh config


openssh

apt-get install openssh-client openssh-server
这个要先安装 不然自启动会不成功

如何激活服务并在启动时启用或禁用服务(即系统启动时自动启动服务)
# systemctl is-active ssh.service
systemctl enable ssh.service
# systemctl disable ssh.service



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
sed -i "s/^#PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config

systemctl restart sshd
#service  sshd restart

补充
服务端
chown -R 0700  ~/.ssh
chown -R 0644  ~/.ssh/authorized_keys

客户端改一下
chmod 600 id_rsa

常用软件


#alias
cp /etc/profile  /etc/profile_bak
echo "alias ll='ls $LS_OPTIONS -l'" >>/etc/profile  &&   source /etc/profile 


useradd -d /data/evan  -s /bin/bash -m  evan
数m表示如果该目录不存在,则创建该目录


apt install net-tools procps  rsync wget   w3m    vim  build-essential dnsutils tmux  curl sudo lsb-release  iotop software-properties-common  -y   # 说明 dig dnsutils   firewalld  screen 暂时不要 

#全面的开发工具
sudo apt  install git golang build-essential gcc g++ gdb libboost-dev make automake autogen autoconf cscope global cmake cmake-gui astyle clang-format clang llvm lldb libsqlite3-dev sqlite3 bison flex ruby-dev linux-headers-`uname -r`


#ps 说明
apt install procps

mariadb-client

安装Fail2Ban
 

Debian 安装 fail2ban 方式SSH爆破攻击


Debian配置iptables

时间同步

UTC时区切换到CST 时区

#用这个啦 
# 设置亚洲时区  tzselect 有时不准
timedatectl set-timezone Asia/Shanghai
# 启用NTP同步 #关闭是 false 
timedatectl set-ntp yes



 echo "export TZ='Asia/Shanghai'"  >> /etc/profile  
 cat /etc/profile |grep TZ  
source /etc/profile

date -R  #时区查看 
 date 
Sat Aug 19 17:03:17 CST 2017


校正日期和时间  linux256

cp /usr/share/zoneinfo/Asia/ShangHai  /etc/localtime     #时区为亚洲/上海
# 网络校时
apt-get install ntpdate
ntpdate 210.72.145.44        # 中国国家时间服务器: 210.72.145.44

# 手动校时
sudo date -s 11/13/2019                #2019年11月13日
sudo date -s 10:05:30                  #10点05分30秒

security

ufw

firewalld

这个放弃了

详情可见 Centos7 firewalld防火墙基础

How To Install and Configure Firewalld on Debian 10

在Debian 10(Buster)上安装和配置Firewalld


优化optimize

linux 里ulimit永久生效设置(debian9 64

9 update to 10

 sudo apt dist-upgrade -y #在之前改成 10的源
在QCLOUD上升级失败了   可以试一下他们自己的源

https://mirrors.cloud.tencent.com/debian/dists/

https://cloud.tencent.com/developer/article/1473368

故障

报错1

Reading package lists...
E: Release file for http://mirrors.ustc.edu.cn/debian/dists/stretch-updates/InRelease is expired (invalid since 69d 5h 56min 7s). Updates for this repository will not be applied.
E: Release file for http://mirrors.ustc.edu.cn/debian/dists/stretch-backports/InRelease is expired (invalid since 69d 5h 56min 7s). Updates for this repository will not be applied.
E: Release file for http://mirrors.ustc.edu.cn/debian-security/dists/stretch/updates/InRelease is expired (invalid since 66d 14h 56min 48s). Updates for this repository will not be applied.
ERROR: Service 'php-worker' failed to build: The command '/bin/sh -c apt-get  update' returned a non-zero code: 100


处理

###########################################################################
# Crontab
###########################################################################
RUN rm -f /etc/apt/sources.list 
RUN rm -f /etc/apt/sources.list.d/buster.list 
COPY  sources.list /etc/apt/
RUN apt -o Acquire::Check-Valid-Until=false update

RUN  apt-get  update  
RUN  apt-get clean 
RUN  apt-get install -y apt-transport-https
RUN  apt install -y cron vim 
RUN ["service","cron","start"]


cat php-worker/sources.list

deb http://deb.debian.org/debian stretch main

报错2

Error message “sudo: unable to resolve host (none)”

That /etc/hosts has an entry for localhost. It should have something like:

127.0.0.1    localhost.localdomain localhost
127.0.1.1    you-hostname

参考

Debian服务器的初始化配置-Google Authenticator

Debian 安装 fail2ban 方式SSH爆破攻击

Ubuntu 新装服务器部署流程

如何在Debian和Ubuntu系统中安装Java 9

Linux服务器的初步配置流程

Securing a Linux Server

Linux服务器初始化配置脚本

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

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

Debian的一些常用命令


Debian 8 设置时区和时间配置