风中的 FAQ-1

1.脑裂是什么?该怎么解决?

脑裂是由于集群之间通信故障,导致集群中出现了多个Master,向多个Master写入时,出现了数据不同步的情况。
一般采用2个办法:
1)采用第三方仲裁
可以是一个锁服务,或者选举机制等,来保证集群内只有一个Master
2)故障组件能够释放掉共享资源
客户端的路由,如果使用vip,则故障节点需要能够释放掉vip;
如果使用proxy,需要考虑proxy自身的高可用
参考:http://blog.chinaunix.net/uid-20726500-id-5473292.html

2.cpu的用户态与内核态

内核态: CPU可以访问内存所有数据, 包括外围设备, 例如硬盘, 网卡. CPU也可以将自己从一个程序切换到另一个程序
用户态: 只能受限的访问内存, 且不允许访问外围设备. 占用CPU的能力被剥夺, CPU资源可以被其他程序获取
为什么要有用户态和内核态
由于需要限制不同的程序之间的访问能力, 防止他们获取别的程序的内存数据, 或者获取外围设备的数据, 并发送到网络, CPU划分出两个权限等级 -- 用户态 和 内核态

3.JDK版本不对报错

Unsupported major.minor version 52.0/51.0 error
编写CI编译时经常发生Java代码在本地ok,在CI环境上报上述错误的情况,这是由于本地开发环境与CI编译环境JDK版本不同导致的。
更换JDK版本即可,如在centos上:
yum -y install java-1.8.0-openjdk*
安装后注意配置JDK对应版本的相关环境变量

4.mvn出包命令

切入项目目录:
mvn -U clean install -P allatori -Dmaven.test.skip=true

命令 说明
clean 清除原来打包文件
install 编译 打包 上传公司jar包仓库
-P allatori 代码混淆
-Dmaven.test.skip=true 跳过源码中测试内容
5.docker push镜像

docker仓库一般会设置认证,禁止非仓库授权者随意控制仓库
1)登录
docker login aaa.bbb.com(远程仓库网址)
Username: xxx
Password:***
Login Succeeded
2)给镜像打标签
docker tag 111222333(镜像id) aaa.bbb.com/lib/mysql:5.7(镜像标签)
3)push 镜像到仓库
docker push aaa.bbb.com/lib/mysql:5.7

6.go语言基础类型范围

一些数据结构算法题,为了保证不浪费内存、或数字很大时需要通过范围考虑使用类型:

类型 长度 默认值 范围
bool 1 false true、false
byte 1 0
rune 4 0 Unicode Code Point, int32
int, uint 4或8 0 32 或 64 位
int8, uint8 1 0 -128 ~ 127, 0 ~ 255
int16, uint16 2 0 -32768 ~ 32767, 0 ~ 65535
int32, uint32 4 0 -2147483648~2147483647, 0~4294967295
int64, uint64 8 0 -9223372036854775808~9223372036854775807,0~18446744073709551615
float32 4 0.0
float64 8 0.0
uintptr 4或8 足以存储指针的 uint32 或 uint64 整数
array 值类型
struct 值类型
string "" UTF-8 字符串
slice nil 引⽤用类型
map nil 引⽤用类型
channel nil 引⽤用类型
interface nil 接⼝
function nil 函数
7.存储卷在宿主机上的目录

创建了存储卷之后,k8s的pod启动时可以将这些存储卷挂载到容器上,完成容器资源的外部持久化。
但是这些存储卷存放在哪里了呢?对应宿主机的哪个路径呢?
如下是mysql的两个挂载目录(/var/lib/mysql,/etc/mysql/conf,d)对应的存储卷:
如果存储卷使用的是nfs
df -h|grep nfs 即可在宿主机上列出对应的路径,切入到对应路径复制文件即可。

20180913135612.png

8.no space left后添加磁盘

当磁盘不够用时,物理添加了一块100G的磁盘:
fdisk -l
显示所有磁盘disk:

image.png

能够看到这块磁盘,但是这块磁盘并没有分区、格式化不能够使用。
1)把磁盘分区
fdisk /dev/vdb

[root@iZ25hv9nfzgZ /]# fdisk /dev/vdb 
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb162e2a0.
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-524287999, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-524287999, default 524287999): 
Using default value 524287999
Partition 1 of type Linux and of size 250 GiB is set
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

2)格式化为ext4格式
mkfs.ext4 /dev/vdb

[root@iZ25hv9nfzgZ /]# mkfs.ext4 /dev/vdb
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
16384000 inodes, 65536000 blocks
3276800 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

3)磁盘分区格式化后可以使用了,挂载到使用目录(这里是/home)即可。
mount /dev/vdb /home
4)挂载记录写入fstab文件
echo '/dev/vdb /mydata ext4 defaults 0 0' >> /etc/fstab
5)查看
parted /dev/vdb print list
其中Disk Flags下面的表格为对应磁盘的具体分区

image.png

9.安装docker-compose

docker-compose用于在一台宿主机上快速部署一组docker服务。
1)
yum -y install epel-release
2)安装python-pip包
yum -y install python-pip
3)对安装好的pip进行升级
pip install --upgrade pip
查看
pip -V
4)安装docker-compose
pip --default-timeout=200 install -U docker-compose
查看
docker-compose -version

image.png

10.syslog日志标准格式

syslog格式:<PRI>HEADER MESSAGE
syslog的消息长度:不超过1024。
syslog格式举例:<15>Jul 10 12:00:00 192.168.1.1 SyslogGen MESSAGE

格式说明:
PRI
即Priority(优先级),有效值范围为0 - 191。不能有空格、数字前也不能补0。
合法的形式如:<15>。

PRI值包含两部分信息:Facility和Level。
    Facility值用于判断哪个程序产生了日志信息。
    Level值用于判断严重等级。

计算机方法:
    PRI = Facility * 8 + Level。
    Facility = PRI / 8;
    Level = PRI % 8;

Facility可选值为:
    0  kernel messages
    1  user-level messages
    2  mail system
    3  system daemons
    4  security/authorization messages
    5  messages generated internally by syslogd
    6  line printer subsystem
    7  network news subsystem
    8  UUCP subsystem
    9  clock daemon
    10 security/authorization messages
    11 FTP daemon
    12 NTP subsystem
    13 log audit
    14 log alert
    15 clock daemon
    16 local use 0 (local0)
    17 local use 1 (local1)
    18 local use 2 (local2)
    19 local use 3 (local3)
    20 local use 4 (local4)
    21 local use 5 (local5)
    22 local use 6 (local6)
    23 local use 7 (local7)

Level可选值为:
    0  Emergency:     system is unusable
    1  Alert:         action must be taken immediately
    2  Critical:      critical conditions
    3  Error:         error conditions
    4  Warning:       warning conditions
    5  Notice:        normal but significant condition
    6  Informational: informational messages
    7  Debug:         debug-level messages

HEADER
HEAD包含两部分信息:TIMESTAMP和HOSTNAME。
TIMESTAMP为时间值,格式为:Mmm dd hh:mm:ss。表示月日时分秒。
HOSTNAME为主机IP地址或主机名。

注意:TIMESTAMP和HOSTNAME后都必须跟一个空格。

MESSAGE
MESSAGE包含两部分信息:TAG和CONTENT。
TAG为产生消息的程序或进程名称。为长度不超过32的字母数字字符串。
CONTENT为信息的详细内容。

注意:TAG后的任何一个非字母数字字符都会表示TAG结束且CONTENT开始。
      一般TAG结束的字符为左大括号([)或分号(;)或空格。
11.yum安装nodejs

配置好基本yum源、dns后

# 4.x版本
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
# 5.x版本
curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -
# 6.x版本
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -

yum -y install nodejs

node -v
npm -v
12.centos7 yum安装nginx
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

yum -y install nginx
修改配置:
vim /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

#一个端口 下 开启多个项目
server {
  listen 80;
  server_name 10.155.200.7;
  location /aaa
  {
      alias /home/test_nginx/aaa;
      index index.html index.php index.htm;
  }
  location /bbb
  {
      alias /home/test_nginx/bbb;
      index index.html index.php index.htm;
  }
}

# 开启第二个端口
server {
  listen 8080;
  server_name 10.155.200.7;
  location /aaa
  {
      alias /home/test_nginx/aaa;
      index index.html index.php index.htm;
  }
  location /bbb
  {
      alias /home/test_nginx/bbb;
      index index.html index.php index.htm;
  }
}


}

配置详解:

#运行用户
user nobody;
#启动进程,通常设置成和cpu的数量相等
worker_processes  1;

#全局错误日志及PID文件
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

#工作模式及连接数上限
events {
    #epoll是多路复用IO(I/O Multiplexing)中的一种方式,
    #仅用于linux2.6以上内核,可以大大提高nginx的性能
    use   epoll; 

    #单个后台worker process进程的最大并发链接数    
    worker_connections  1024;

    # 并发总数是 worker_processes 和 worker_connections 的乘积
    # 即 max_clients = worker_processes * worker_connections
    # 在设置了反向代理的情况下,max_clients = worker_processes * worker_connections / 4  为什么
    # 为什么上面反向代理要除以4,应该说是一个经验值
    # 根据以上条件,正常情况下的Nginx Server可以应付的最大连接数为:4 * 8000 = 32000
    # worker_connections 值的设置跟物理内存大小有关
    # 因为并发受IO约束,max_clients的值须小于系统可以打开的最大文件数
    # 而系统可以打开的最大文件数和内存大小成正比,一般1GB内存的机器上可以打开的文件数大约是10万左右
    # 我们来看看360M内存的VPS可以打开的文件句柄数是多少:
    # $ cat /proc/sys/fs/file-max
    # 输出 34336
    # 32000 < 34336,即并发连接总数小于系统可以打开的文件句柄总数,这样就在操作系统可以承受的范围之内
    # 所以,worker_connections 的值需根据 worker_processes 进程数目和系统可以打开的最大文件总数进行适当地进行设置
    # 使得并发总数小于操作系统可以打开的最大文件数目
    # 其实质也就是根据主机的物理CPU和内存进行配置
    # 当然,理论上的并发总数可能会和实际有所偏差,因为主机还有其他的工作进程需要消耗系统资源。
    # ulimit -SHn 65535

}


http {
    #设定mime类型,类型由mime.type文件定义
    include    mime.types;
    default_type  application/octet-stream;
    #设定日志格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
    #对于普通应用,必须设为 on,
    #如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
    #以平衡磁盘与网络I/O处理速度,降低系统的uptime.
    sendfile     on;
    #tcp_nopush     on;

    #连接超时时间
    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay     on;

    #开启gzip压缩
    gzip  on;
    gzip_disable "MSIE [1-6].";

    #设定请求缓冲
    client_header_buffer_size    128k;
    large_client_header_buffers  4 128k;


    #设定虚拟主机配置
    server {
        #侦听80端口
        listen    80;
        #定义使用 www.nginx.cn访问
        server_name  www.nginx.cn;

        #定义服务器的默认网站根目录位置
        root html;

        #设定本虚拟主机的访问日志
        access_log  logs/nginx.access.log  main;

        #默认请求
        location / {
            
            #定义首页索引文件的名称
            index index.php index.html index.htm;   

        }

        # 定义错误提示页面
        error_page   500 502 503 504 /50x.html;
        location = /50x.html {
        }

        #静态文件,nginx自己处理
        location ~ ^/(images|javascript|js|css|flash|media|static)/ {
            
            #过期30天,静态文件不怎么更新,过期可以设大一点,
            #如果频繁更新,则可以设置得小一点。
            expires 30d;
        }

        #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
        location ~ .php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        #禁止访问 .htxxx 文件
            location ~ /.ht {
            deny all;
        }

    }
}
13.解决gem install sass、compass 没有资源问题

yum -y install gcc compass安装需要gcc
yum -y install ruby ruby-devel
查看gem源gem source list


ping rubygems.org 发现ping不通,我们不能使用默认的gem源
删除原gem源
gem source --remove https://rubygems.org/
添加新gem源(注意网址,原网址后缀为org)
gem source -a http://gems.ruby-china.com
安装sass、compass
gem install sass compass

14. npm install报错tar.unpack unzip error

image.png

npm设置为淘宝源
npm config set registry https://registry.npm.taobao.org
测试npm源
npm config get registry
清除缓存
npm cache clean
重新执行npm install
输出debug日志
npm install -verbose

15. smbclient安装使用

安装
yum -y install samba-client
语法
smbclient [网络资源][密码][-EhLN][-B<IP地址>][-d<排错层级>][-i<范围>][-I<IP地址>][-l<记录文件>] [-M<NetBIOS名称>][-n<NetBIOS名称>][-O<连接槽选项>][-p<TCP连接端口>][-R<名称解析顺序>][-s<目录>][-t<服务器字码>][-T<tar选项>][-U<用户名称>][-W<工作群组>]
参数说明:

[网络资源] [网络资源]的格式为//服务器名称/资源分享名称。
[密码] 输入存取网络资源所需的密码。
-B<IP地址> 传送广播数据包时所用的IP地址。
-d<排错层级> 指定记录文件所记载事件的详细程度。
-E 将信息送到标准错误输出设备。
-h 显示帮助。
-i<范围> 设置NetBIOS名称范围。
-I<IP地址> 指定服务器的IP地址。
-l<记录文件> 指定记录文件的名称。
-L 显示服务器端所分享出来的所有资源。
-M<NetBIOS名称> 可利用WinPopup协议,将信息送给选项中所指定的主机。
-n<NetBIOS名称> 指定用户端所要使用的NetBIOS名称。
-N 不用询问密码。
-O<连接槽选项> 设置用户端TCP连接槽的选项。
-p<TCP连接端口> 指定服务器端TCP连接端口编号。
-R<名称解析顺序> 设置NetBIOS名称解析的顺序。
-s<目录> 指定smb.conf所在的目录。
-t<服务器字码> 设置用何种字符码来解析服务器端的文件名称。
-T<tar选项> 备份服务器端分享的全部文件,并打包成tar格式的文件。
-U<用户名称> 指定用户名称。
-W<工作群组> 指定工作群组名称。

场景例子:
下载文件
smbclient //IP/自己部门 -c "get \\自己部门下文件路径" -U $smb_user%$smb_passwd -W 工作组名称
上传文件
smbclient //IP/自己部门 -c "put \\自己部门下文件路径" -U $smb_user%$smb_passwd -W 工作组名称
创建文件夹
smbclient //IP/自己部门 -c "mkdir \\自己部门下文件路径" -U $smb_user%$smb_passwd -W 工作组名称

16.standard_init_linux.go:178: exec user process caused “no such file or directory”

宿主机centos,docker内系统alpine,做镜像,启动后,docker logs 发现报错:
standard_init_linux.go:178: exec user process caused “no such file or directory”
1.编码问题,cat -v xxx.sh 查看发现存在windows乱码,vim :set ff=unix修改编码(或下载dos2uinx,find ./ -type f | xargs -i dos2unix {})
2.sharp bang问题,脚本首行寻找二进制文件找不到

17.fluentd内置插件record_transformer Filter Plugin

格式

<filter foo.bar>
  @type record_transformer
  enable_ruby
  <record>
    avg ${record["total"] / record["count"]}
  </record>
</filter>

record标签内的例子:

jsonized_record ${record.to_json}
avg ${record["total"] / record["count"]}
formatted_time ${time.strftime('%Y-%m-%dT%H:%M:%S%z')}
escaped_tag ${tag.gsub('.', '-')}
last_tag ${tag_parts.last}
foo_${record["key"]} bar_${record["value"]}
nested_value ${record["payload"]["key"]}
18.tr命令

换行符改为空格
tr '\n' ' '
asd 改为 abc
tr 'asd' 'abc'
统一改为大写
tr [a-z] [A-Z]
统一改为小写
tr [A-Z] [a-z]
把数字0-9换为a-j
tr [0-9] [a-j]
删除换行符 制表符
tr -d '\n'
tr -d '\t'
删除字符asd
tr -d 'asd'
删除空行
tr -s '\n'
删除windows文件造成的^M字符
tr -d '\r'

19.linux 给history添加时间

echo "HISTFILESIZE=2000" >> /etc/bashrc && echo "HISTSIZE=2000" >> /etc/bashrc && echo 'HISTTIMEFORMAT="%Y%m%d %T "'>> /etc/bashrc && export HISTTIMEFORMAT
重新登录生效
之前的记录都为当前时间,之后的记录会是正常时间。

20.fluentd在线正则表达式测试网站

正则表达式测试:http://fluentular.herokuapp.com
时间表达式规则文档:https://docs.ruby-lang.org/en/2.2.0/Time.html#method-i-strptime

21.安装虚拟机

直接使用VMware的ISO镜像安装它的操作系统,再使用客户端控制创建虚拟机。
VMware ESXI 6.5安装教程

22.ISODATE

名词解释:

格林尼治标准时间(GMT,旧译“格林威治平均时间”或“[格林威治标准时间]是指位于伦敦郊区的皇家[格林尼治天文台]被定义在通过那里的经线。

协调世界时(UTC) 英文:Coordinated Universal Time ,别称:世界统一时间,世界标准时间国际协调时间, 协调世界时,又称世界统一时间,世界标准时间,国际协调时间,简称UTC。它从英文“Coordinated Universal Time”/法文“Temps Universel Cordonné”而来。

GMT(Greenwish Mean Time 格林威治平时),这是UTC的民间名称。GMT=UTC。

ISODATE

格式 YYYY-MM-DDTHH:mm:ss.sssZ
示例 2019-01-09T05:01:13.000Z 2019-01-09T05:01:13.000+08:00

模型 说明
YYYY is the decimal digits of the year 0000 to 9999 in the Gregorian calendar.
- "-" (hyphen) appears literally twice in the string.
MM is the month of the year from 01 (January) to 12 (December).
DD is the day of the month from 01 to 31.
T 时间元素起始标志,"T" appears literally in the string, to indicate the beginning of the time element.
HH is the number of complete hours that have passed since midnight as two decimal digits from 00 to 24.
: ":" (colon) appears literally twice in the string.
mm is the number of complete minutes since the start of the hour as two decimal digits from 00 to 59.
ss is the number of complete seconds since the start of the minute as two decimal digits from 00 to 59.
. "." (dot) appears literally in the string.
sss is the number of complete milliseconds since the start of the second as three decimal digits.
Z 时区偏移,“Z”表示(UTC)或时间表达式+08:00等,is the time zone offset specified as "Z" (for UTC) or either "+" or "-" followed by a time expression HH:mm
23.fluentd 日志丢失、日志去重

https://blog.csdn.net/jj_tyro/article/details/79607502

24.制作yum repo文件

安装createrepo
yum install createrepo -y
制作repodate文件夹
createrepo -pdo /var/cache/yum/local /var/cache/yum/local/

25.kubelet已经集成了cadvisor用于监控主机上的容器,可以查看相关监控记录

通过访问:http://<host_ip>:4194

image.png

docker update

当容器启动时忘记添加重启策略时
docker update --restart=always 9ca2ab8d9a58
docker update文档

26.elasticsearch导出导入数据

安装elasticsearch-dump

yum -y install git
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs
git clone https://github.com/taskrabbit/elasticsearch-dump.git
cd elasticsearch-dump
npm install elasticdump -g

把原始索引的mapping结构和数据导出
elasticdump --input=http://192.168.103.99:9200/ --output=/home/backup_es/cmdb_dump-mapping.json --all=true --type=mapping
elasticdump --input=http://192.168.103.99:9200/ --output=/home/backup_es/cmdb_dump.json --all=true --type=data

mapping结构和数据导入新的cluster节点
elasticdump --input=/home/backup_es/cmdb_dump-mapping.json --output=http://10.155.203.182:9200/ --bulk=true
elasticdump --input=/home/backup_es/cmdb_dump.json --output=http://10.155.203.182:9200/ --bulk=true

27.linux 进程文件夹

ll /proc/PID
cwd符号链接的是进程运行目录;
exe符号连接就是执行程序的绝对路径;
cmdline就是程序运行时输入的命令行命令;
environ记录了进程运行时的环境变量;
fd目录下是进程打开或使用的文件的符号连接。

28.url和uri区别
image.png

“URI可以分为URL,URN或同时具备locators 和names特性的一个东西。URN作用就好像一个人的名字,URL就像一个人的地址。换句话说:URN确定了东西的身份,URL提供了找到它的方式。”

29.linux上查看文件stat命令

stat命令能够查看到一个文件的访问时间、修改时间、状态修改时间等,但不能获取文件的创建时间。

image.png

image.png

image.png

参考文章:https://blog.csdn.net/yexiangcsdn/article/details/81012732

30.linux上查看文件的创建时间

如果文件系统是ext4类型时,可以查看到文件的创建时间,1.通过stat命令或ls -i filename命令查看到文件的inode号,2.找到文件所在的分区或VG df -T,3.通过debugfs -R 'stat <xxx>' /dev/xxxx

[root@mylnx06 resource]# debugfs -R 'stat <13>' /dev/sdb1
debugfs 1.42.9 (28-Dec-2013)
Inode: 13   Type: regular    Mode:  0644   Flags: 0x80000
Generation: 3202520017    Version: 0x00000000:00000001
User:     0   Group:     0   Size: 0
File ACL: 0    Directory ACL: 0
Links: 0   Blockcount: 0
Fragment:  Address: 0    Number: 0    Size: 0
 ctime: 0x5c75e766:924da674 -- Wed Feb 27 09:27:02 2019
 atime: 0x5c75e757:dfe24bb0 -- Wed Feb 27 09:26:47 2019
 mtime: 0x5c75e72b:c6a80080 -- Wed Feb 27 09:26:03 2019
crtime: 0x5c75e72b:c6a80080 -- Wed Feb 27 09:26:03 2019
dtime: 0x5c75e766 -- Wed Feb 27 09:27:02 2019
Size of extra inode fields: 28
EXTENTS:
31.docker的overlay2文件夹下面文件很大

使用命令docker system df -v 查看镜像、容器、挂载卷的大小

[root@localhost docker]# docker system df -v
Images space usage:

REPOSITORY                                              TAG                 IMAGE ID            CREATED             SIZE                SHARED SIZE         UNIQUE SIZE         CONTAINERS
registry.cn-hangzhou.aliyuncs.com/xuxiang/centos        aegis_smoke         3ca8c493ec25        12 months ago       614.8 MB            0 B                 614.8 MB            1
registry.cn-hangzhou.aliyuncs.com/xuxiang/sas           sql2                1659fbec2cc6        14 months ago       3.18 GB             2.869 GB            311 MB              2
registry.cn-hangzhou.aliyuncs.com/xuxiang/sas           sql                 3aa054ca03e1        14 months ago       2.869 GB            2.869 GB            0 B                 1
registry.cn-hangzhou.aliyuncs.com/xuxiang/kali_yundun   latest              294e6391833a        20 months ago       2.924 GB            0 B                 2.924 GB            6
docker.io/dijedodol/simple-socks5-server                latest              91218fcc1a71        2 years ago         115.9 MB            0 B                 115.9 MB            0
cgminer_testv1.3                                        latest              1de49022432d        2 years ago         421.8 MB            0 B                 421.8 MB            0
redis_testv1.3                                          latest              450d963b34cb        2 years ago         182.9 MB            0 B                 182.9 MB            2
registry.cn-hangzhou.aliyuncs.com/xuxiang/dvwa          latest              119d37316de7        2 years ago         534.9 MB            0 B                 534.9 MB            3

Containers space usage:

CONTAINER ID        IMAGE                                                   COMMAND                  LOCAL VOLUMES       SIZE                CREATED             STATUS              NAMES
84dd949fa45f        registry.cn-hangzhou.aliyuncs.com/xuxiang/kali_yundun   "/start.sh"              0                   14.6 GB             13 days ago         Up 13 days          zuozhu_de_gongjiji_92_cs3
48e0b72a51b7        registry.cn-hangzhou.aliyuncs.com/xuxiang/kali_yundun   "/start.sh"              0                   13.1 GB             13 days ago         Up 13 days          zuozhu_de_gongjiji_91_cs3
a7eab0f2e449        registry.cn-hangzhou.aliyuncs.com/xuxiang/sas:sql2      "/start.sh"              0                   1.08 MB             13 days ago         Up 13 days          zuozhu_de_baji_91_cs3
2b8e374ced54        registry.cn-hangzhou.aliyuncs.com/xuxiang/dvwa          "/run.sh"                2                   646 kB              13 days ago         Up 13 days          dvwa_cs3test
cd4e6d9fce41        registry.cn-hangzhou.aliyuncs.com/xuxiang/kali_yundun   "/start.sh"              0                   50.5 MB             13 days ago         Up 13 days          inner_kali_yundun_cs3test
f5e664e1ac80        registry.cn-hangzhou.aliyuncs.com/xuxiang/sas:sql       "/start.sh"              0                   95.6 MB             13 days ago         Up 13 days          sas_cs3test
a76ea60d57ef        registry.cn-hangzhou.aliyuncs.com/xuxiang/kali_yundun   "/start.sh"              0                   50.5 MB             13 days ago         Up 13 days          aegis_kali_yunduncs3test
6412d873190f        registry.cn-hangzhou.aliyuncs.com/xuxiang/kali_yundun   "/start.sh"              0                   50.5 MB             13 days ago         Up 13 days          kali_yundun_cs3test
575a39797686        3ca8c493ec25                                            "/home/start.sh"         0                   189 MB              2 months ago        Up 3 weeks          aegis_ym_64
67d51df47ad2        450d963b34cb                                            "docker-entrypoint..."   1                   192 B               2 months ago        Up 3 weeks          redis_ym_63
34d997610cb2        registry.cn-hangzhou.aliyuncs.com/xuxiang/kali_yundun   "/start.sh"              0                   449 MB              2 months ago        Up 3 weeks          kali_ym_61
ef21bf1e3d75        registry.cn-hangzhou.aliyuncs.com/xuxiang/sas:sql2      "/start.sh"              0                   3.74 MB             2 months ago        Up 3 weeks          sas_ym_62
31eb8824942d        registry.cn-hangzhou.aliyuncs.com/xuxiang/dvwa          "/run.sh"                2                   1.73 MB             2 months ago        Up 3 weeks          dvwa_ym_61
f7c3a14fddd6        119d37316de7                                            "/run.sh"                2                   29 GB               3 months ago        Up 3 weeks          smoke_jl
b7e93401d8c9        450d963b34cb                                            "docker-entrypoint..."   1                   526 B               3 months ago        Up 3 weeks          redis_jl

Local Volumes space usage:

VOLUME NAME                                                        LINKS               SIZE
0d86d4d00339dd7138e1f1d5f8551c0f78cf317ae20a61476881fcb8fe3f3e58   1                   0 B
4a76ad7814cc60581d29334084f2c7594c7d53043318d0649323282d6a58a672   1                   5.109 kB
6de6125472af2d56af9e6638107551181b0f4cd28fec7e682e9132d1f0517740   1                   0 B
b2b936534a991f79d531fbb8c214ba55175c51aacf6e7009f11aadda31d9267f   1                   30.43 MB
675e69ea48445a089db7a4dcf0cf381da2bd7272661a7c448c23bb2abb0f4310   1                   5.109 kB
0ae662cea0e22f1078761c92d4402238a86a5fc6b3a0b50c126b45b5fdaa866b   1                   30.43 MB
5f55cb5eb1a10046d2ce4d60d1efe839a1049afd5c14e540e0e93f512919df72   1                   30.43 MB
9bd5dfd2d38df43483a8ab289392804d35a6c996ffb70402b65b6d6de5712b52   1                   5.109 kB

找到占用磁盘较大的资源,然后清除掉即可。

32.shell 正则表达式,提取匹配内容
str='master 7ecbf3f [origin/master: ahead 8, behind 1] local'
#方法一
grep -Po '\[\K[^]]+' <<<$str ,这种方法可以提取多个,下面2种方法提取的是第一个[到最后一个]之前的字符。
#方法二
sed 's/[^[]\+\[//;s/].*//' <<<$str
#方法三
awk -F'[][]' '{print $2}' <<<$str
33.yum报错error: cannot open Packages database in /var/lib/rpm

配完dns更换完yum源后,使用yum clean all && yum makecache时如下错误。

rpmdb: Thread/process 11197/140701458409216 failed: Thread died in Berkeley DB library
error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 - (-30974)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:

解决办法:
rm -rf /var/lib/rpm/__db*

34.spark sql 字符替换

在写spark sql时,输出的一个字段包含了字符串,导致整体结构出错。


image.png

于是使用字符替换函数,将双引号替换为单引号

regexp_replace(postdata, '"', '\''),

sql中单引号与双引号转义如下:

mysql> SELECT 'hello', '"hello"', '""hello""', 'hel''lo', '\'hello';
+-------+---------+-----------+--------+--------+
| hello | "hello" | ""hello"" | hel'lo | 'hello |
+-------+---------+-----------+--------+--------+
 
mysql> SELECT "hello", "'hello'", "''hello''", "hel""lo", "\"hello";
+-------+---------+-----------+--------+--------+
| hello | 'hello' | ''hello'' | hel"lo | "hello |
+-------+---------+-----------+--------+--------+
 
mysql> SELECT 'This\nIs\nFour\nLines';
+--------------------+
| This
Is
Four
Lines |
+--------------------+
 
mysql> SELECT 'disappearing\ backslash';
+------------------------+
| disappearing backslash |
+------------------------+
35.远程git仓库git merge错误如何回退

方法一:

  • 1.从合入错误merge之前的commit拉出一个branch如tmp分支。
  • 2.删掉merge错了的分支。
  • 3.从tmp分支再拉一个原名称的分支。

方法二:本地命令行中

  • 1.git log 查找需要回滚到的commit号
  • 2.git reset --hard <commitId> 进行回退
  • 3.git push -f 推送到远程仓库
36.类似jenkins,ci过程中更新分支代码进行编译的git处理。
  • 1.确定仓库地址之前,首先需要当前工作目录是否是一个Git仓库
root@localhost> git rev-parse --is-inside-work-tree
true
  • 2.确认当前工作目录的仓库地址
root@localhost> git config --list|grep -F "remote.origin.url"`
remote.origin.url=ssh://git@gitlab.xxx/chentairan/git-learn.git
  • 3.​ 如果需要直接设置仓库地址
root@localhost> git config remote.origin.url ssh://git@gitlab.xxx/chentairan/git-learn.git
  • 4.获取指定远程分支
chentairan@localhost ~/t/git-learn> git fetch ssh://git@gitlab.xxx/chentairan/git-learn.git $BRANCH_NAME:refs/remotes/origin/$BRANCH_NAME
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From ssh://gitlab.xxx/chentairan/git-learn
 * [new branch]      dev        -> origin/dev
  • 5.获取分支的Commit ID
chentairan@localhost ~/t/git-learn> git rev-parse --verify refs/remotes/origin/$BRANCH_NAME
9e100c01201678286db5d266b8d342b0dd8a8e0d
  • 6.检出提交
chentairan@localhost ~/t/git-learn> git checkout -f 9e100c01201678286db5d266b8d342b0dd8a8e0d
  • 7.去掉多余文件
chentairan@localhost ~/t/git-learn> git clean -fdx

jenkins上截取的完整git处理:

 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@gitlab01.dtdream.com:SEC/DTCSC.git # timeout=10
Fetching upstream changes from git@gitlab01.dtdream.com:SEC/DTCSC.git
 > git --version # timeout=10
 > git fetch --tags --progress git@gitlab01.dtdream.com:SEC/DTCSC.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/release^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/release^{commit} # timeout=10
Checking out Revision da5bd1dec2add3657730a5f0b6b0be0a55c22715 (refs/remotes/origin/release)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f da5bd1dec2add3657730a5f0b6b0be0a55c22715
Commit message: "Merge branch 'release-1029' into 'release'"
 > git rev-list da5bd1dec2add3657730a5f0b6b0be0a55c22715 # timeout=10

参考:https://www.bbsmax.com/A/Gkz14Bw2dR/

37.添加开机启动脚本

方法一:通过rc.local添加

result=$(grep ipvsadm /etc/rc.d/rc.local)
if [ -z "$result" ]; then
    echo "ipvsadm" >> /etc/rc.d/rc.local
    echo "echo ${V_MIN_FREE_KBYTES} > /proc/sys/vm/min_free_kbytes" >> /etc/rc.d/rc.local
fi
chmod +x /etc/rc.d/rc.local

方法二:通过定时任务添加

# 移除 /etc/crontab中的 recover脚本
sed -i '/recover\.sh/d' /etc/crontab
# 添加recover脚本
echo "@reboot root /bin/bash -c '${p_recover}/recover.sh &>>/var/log/recover.log &'" >> /etc/crontab
38.shell test命令

参考:https://www.runoob.com/linux/linux-shell-test.html
test -x 文件名测试文件是否存在并具有可执行权限,返回0、1

39.shell ulimit命令

参考:https://www.runoob.com/linux/linux-comm-ulimit.html
ulimit为shell内建指令,可用来控制shell执行程序的资源

40.shell set、env、export
42.windows下goland中的terminal使用git bash作为命令行工具。

image.png

Shell path中添加:"F:\software\Git\bin\sh.exe" -login -i

41.报错github error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

https://www.jianshu.com/p/0cfa98c5a27f
git 客户端版本过低,其使用的TLSV1和TLSV1.1 这个涉及到到所有的github.com的链接,在2018年2月22日以后将禁用。直接去git客户端官网:https://git-scm.com/downloads下载最新版本(当前是2.16.2),覆盖安装即可。

43.压力测试工具ab

如(yum -y install httpd-tools

[root@vic html]# ab --help
ab: wrong number of arguments
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make
    -t timelimit    Seconds to max. wait for responses
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header for POSTing, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes
                    are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -h              Display usage information (this message)
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)

示例:
ab -c 10 -n 100 http://www.myvick.cn/index.php 并发10个请求,共100个请求。

44.压力测试工具wrk
[root@localhost /]# wrk -t2 -c10 -d15 --latency http://www.baidu.com
Running 15s test @ http://www.baidu.com
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    35.64ms    1.31ms  48.59ms   79.38%
    Req/Sec   138.40     13.52   151.00     89.00%
  Latency Distribution
     50%   35.50ms
     75%   36.13ms
     90%   37.09ms
     99%   40.33ms
  4151 requests in 15.05s, 60.83MB read
  Socket errors: connect 0, read 29, write 0, timeout 0
Requests/sec:    275.72
Transfer/sec:      4.04MB
1)语法中的参数
-t:需要模拟的线程数
-c:需要模拟的连接数
-d:测试的持续时间
--timeout:超时的时间
--latency:显示延迟统计

2)结果显示的指标
Latency:响应时间
Req/Sec:每个线程每秒钟的完成的请求数
Avg:平均
Max:最大
Stdev:标准差
45.16进制字符串 到 字符串转换

https://www.cnblogs.com/fqfanqi/p/7900758.html

46.Alpine Linux升级

Alpine Linux

Small. Simple. Secure.Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.

Alpine Linux 是一个社区开发的面向安全应用的轻量级Linux发行版。 Alpine 的意思是“高山的”,它采用了musl libc和busybox以减小系统的体积和运行时资源消耗,同时还提供了自己的包管理工具apk。

### 适用环境

由于其小巧、安全、简单以及功能完备的特点,被广泛应用于众多Docker容器中。我司目前使用的基础镜像均是基于该系统,[dockerhub](https://hub.docker.com/_/alpine)上有提供各种语言的基础镜像.如:`node:8-alpine`、`python:3.6-alpine`,同时也可以基于alpine镜像制作符合自己需求的基础镜像。

echo -e "https://mirrors.ustc.edu.cn/alpine/latest-stable/main\nhttps://mirrors.ustc.edu.cn/alpine/latest-stable/community" > /etc/apk/repositories
apk upgrade

47.升级openssh版本

yum install -y gcc openssl-devel pam-devel zlib zlib-devel
https://www.jianshu.com/p/220f7fd908b0

48.GO安装后报错

windows上安装go1.12.5.windows-amd64.msi后,执行命令:go version,报错如下:

cmd/go: unsupported GOOS/GOARCH pair windows /amd64

解决方法:
系统环境变量中的环境变量OS、PROCESSOR_ARCHITECTURE没有和GOARCH、GOOS对应上,修改后正常。

49.haproxy.cfg添加监控页面
frontend  secure     #自定义一个frontend,也可以放在listen或者backend中
        bind *:9999   #监听的ip端口号
        stats enable    #开关
        stats  uri  /admin?admin  #访问的uri   ip:8888/admin?admin
        stats auth admin:admin    #认证用户名和密码
        stats hide-version        #隐藏HAProxy的版本号
        stats admin if TRUE       #管理界面,如果认证成功了,可通过webui管理节点
        stats  refresh  5s   #统计页面自动刷新时间

将此配置粘贴到配置文件中,并重启即可。

50.mac 使用brew升级go版本

brew upgrade go

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,670评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,928评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,926评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,238评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,112评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,138评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,545评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,232评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,496评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,596评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,369评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,226评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,600评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,906评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,185评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,516评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,721评论 2 335

推荐阅读更多精彩内容