创业者

创业者不一定是CEO(首席执行官),创业者可以是一个产品经理,创业者可以是一个程序员,创业者可以是一个设计师,创业者可以是一个产品经理,只要你拥有这个创业的梦想

python3天数转日期

!/usr/bin/env python3
– coding:utf-8 –
import time
import os
import sys
print()
input_num_value = int(input(“请输入转换的天数:”))
time_convert_value = input_num_value * 24 * 60 * 60 #天转秒
time_cur_value = time.time() #当前日期的秒
time_convert_mes = time_cur_value + time_convert_value #求秒+当前秒=和秒
time_day = time.gmtime(time_convert_mes) #转换日期
time_day_format = time.strftime(“%Y-%m-%d %H:%M:%S”,time.gmtime(time_convert_mes))
print()
print(‘天数转换后的年月日: {}’.format(time_day_format))
print()

FastDFS文件同步机制简介

   FastDFS文件同步采用binlog异步复制方式。storage server使用binlog文件记录文件上传、删除等操作,根据binlog进行文件同步。binlog中只记录文件ID和操作,不记录文件内容。下面给出几行binlog文件内容示例:

1572660675 C M00/00/00/oYYBAF285cOIHiVCAACI-7zX1qUAAAAVgAACC8AAIkT490.txt

1572660827 c M00/00/00/oYYBAF285luIK8jCAAAJeheau6AAAAAVgABI-cAAAmS021.xml

1572660911 D M00/00/00/oYYBAF285cOIHiVCAACI-7zX1qUAAAAVgAACC8AAIkT490.txt

1572660967 d M00/00/00/oYYBAF285luIK8jCAAAJeheau6AAAAAVgABI-cAAAmS021.xml

  从上面可以看到,binlog文件有三列,依次为时间戳、操作类型和文件ID(不带group名称)。

  文件操作类型采用单个字母编码,其中源头操作用大写字母表示,被同步的操作为对应的小写字母。文件操作字母含义如下:

    C :上传文件(upload)

    D:删除文件(delete)

    A:追加文件(append)

    M:部分文件更新(modify)

    U:整个文件更新(set metadata)

    T:截断文件(truncate)

    L:创建符号链接(文件去重功能,相同内容只保存一份)

  同组内的storage server之间是对等的,文件上传、删除等操作可以在任意一台storage server上进行。文件同步只在同组内的storage server之间进行,采用push方式,即源头服务器同步给本组的其他存储服务器。对于同组的其他storage server,一台storage server分别启动一个线程进行文件同步。

  文件同步采用增量方式,记录已同步的位置到mark文件中。mark文件存放路径为 $base_path/data/sync/。mark文件内容示例:

binlog_index=3

binlog_offset=382

need_sync_old=1

sync_old_done=1

until_timestamp=1571976211

scan_row_count=2033425

sync_row_count=2033417

  采用binlog的异步复制方式,必然存在同步延迟的问题,比如mysql的主从数据同步。下一篇文章将介绍FastDFS是如何解决文件异步复制带来的延迟问题,敬请期待。

  最后留给大家一个问题,为什么binlog记录的文件操作类型有大小写的两套呢(如C和c、D和d等)?

awk数字过滤

netstat -lntp|awk {'print $4'}|awk -F ':' '{if ($NF~/^[0-9]$/) print $NF}'|sort|uniq 
netstat -lntp|awk '{print $4}'|awk -F ':' '/[0-9]/{print $NF}'|sort|uniq
netstat -lntp|awk {'print $4'}|awk -F ':' '{print $NF}'|egrep "^[0-9]$"|sort|uniq

结果:

22
3306

为什么执行这句无任何显示

netstat -lntp|awk {‘print $4’}|awk -F ‘:’ ‘/^[0-9]*$/{print $1}’|sort|uniq

但在txt文本又能生效

[root@oldboy scripts]# cat test.txt 
(only
Local
22
a3306
22
3306
4473f
56789
[root@oldboy scripts]#  cat test.txt|awk -F ':' '/[0-9]/{print $1}'|sort|uniq 
22
3306
4473f
56789
a3306
[root@oldboy scripts]#  cat test.txt|awk -F ':' '/^[0-9]$/{print $1}'|sort|uniq 
[root@oldboy scripts]# cat test.txt|awk -F ':' '/^[0-9]*$/{print $1}'|sort|uniq
22
3306
56789

总结:

  • netstat 不需要多次匹配
  • cat 需要多次匹配
  • netstat 是一行处理 cat 是多行处理

Linux的net.ipv4.tcp_timestamps参数

Q1

在家里无法打开公司的网站,经过各种测试,利用ping、dig域名,然后curl,都正常。但是网站依然无法打开。最后,采用抓包的方式,从包中看到syn-ack没有返回,然后就百度。

经过查找net.ipv4.tcp_timestamps=1,启用了时间戳。

原理如下:
tcp三次握手问题,当有一个用户的时间戳大于这个链接发出的syn中的时间戳,服务器上就会忽略掉这个syn,不返会syn-ack消息。用户表现无法正常完成tcp3次握手,从而不能打开web页面。在业务闲时,如果用户nat的端口没有被使用过时,就可以正常打开;业务忙时,nat端口重复使用的频率高,很难分到没有被使用的端口,从而产生这种问题。

解决:

net.ipv4.tcp_timestamps = 0

然后syctlp -p生效即可。

Q2

由于乱序,当发送rst包到对端的时候,连接还是establish的rst后,链接就会断开, 后来使得net.ipv4.tcp_timestamps = 0,问题解决。

mysql 案例

create table student (
id int(4) not null,
name char(20) not null,
age tinyint(2) not null,
dept varchar(16) not null
);

create database sns; use sns; set names gbk; create table `subject_comment_manager` ( `subject_comment_manager_id` bigint(12) not null auto_increment comment ‘主键’, `subject_type` tinyint(2) not null comment ‘素材类型’, `subject_primary_key` varchar(255) not null comment ‘素材主键’, `subject_title` varchar(255) not null comment ‘素材名称’, `edit_user_nick` varchar(64) not null comment ‘修改人’, `edit_user_time` timestamp null default null comment ‘修改时间’, `edit_comment` varchar(255) default null comment ‘修改的理由’, `state` tinyint(1) not null default ‘1’ comment ‘0 代表关闭,1 代表正常’, primary key (`subject_comment_manager_id`), key `IDX_PRIMARYKEY` (`subject_title`(32)), #括号内的32表示对前32个字符做前缀索引。 key `IDX_SUBJECT_TITLE` (`subject_title`(32)), key `index_nick_type` (`edit_user_nick`(32),`subject_type`) #联合索引,此行为新加的,用于给大家讲解的,实际表语句内没有此行。 ) engine=innodb auto_increment=1 default charset=utf8;

=====================联表查询====================
create table student(
Sno int(10) not null comment ‘学号’,
Sname varchar(16) not null comment ‘姓名’,
Ssex char(6) not null comment ‘性别’,
Sage tinyint(2) not null default ‘0’ comment ‘学生年龄’,
Sdept varchar(16) default null comment ‘学生所在系别’,
primary key (Sno),
key index_Sname(Sname)
) engine=innodb auto_increment=1 default charset=utf8;

create table course(
Cno int(10) not null comment ‘课程号’,
Cname varchar(64) not null comment ‘课程名’,
Ccredit tinyint(2) not null comment ‘学分’,
primary key (Cno)
) engine=innodb auto_increment=1 default charset=utf8;

create table SC(
SCid int(12) not null auto_increment comment ‘主键’,
Cno int(10) not null comment ‘课程号’,
Sno int(10) not null comment ‘学号’,
Grade tinyint(2) not null comment ‘学生成绩’,
primary key (SCid)
) engine=innodb default charset=utf8;

随便插入学生数据

insert into student values(0001,’hognzhi’,’male’,30,’jisuanji’),(0002,’wammg’,’male’,30,’jisuanji’) ,(0003,’oldboy’,’male’,28,’wuliu’) ,(0004,’ts’,’male’,29,’jisuanji’) ,(0005,’oldgirl’,’female’,30,’jisuanji’) ,(0006,’yuany’,’female’,22,’nurse’);

insert into course values(1001,’Linuxyunwei’,3),(1002,’Linuxyunwei’,5),(1003,’Linuxyunwei’,4),(1004,’Linuxyunwei’,4),(1001,’Linuxyunwei’,3);

insert into SC(Sno,Cno,Grade) values(0001,1001,4);
insert into SC(Sno,Cno,Grade) values(0001,1002,3);
insert into SC(Sno,Cno,Grade) values(0001,1003,1);
insert into SC(Sno,Cno,Grade) values(0001,1003,6);

insert into SC(Sno,Cno,Grade) values(0002,1001,3);
insert into SC(Sno,Cno,Grade) values(0002,1002,2);
insert into SC(Sno,Cno,Grade) values(0002,1003,2);
insert into SC(Sno,Cno,Grade) values(0002,1003,8);

insert into SC(Sno,Cno,Grade) values(0003,1001,4);
insert into SC(Sno,Cno,Grade) values(0003,1002,4);
insert into SC(Sno,Cno,Grade) values(0003,1003,2);
insert into SC(Sno,Cno,Grade) values(0003,1003,8);

insert into SC(Sno,Cno,Grade) values(0004,1001,1);
insert into SC(Sno,Cno,Grade) values(0004,1002,1);
insert into SC(Sno,Cno,Grade) values(0004,1003,2);
insert into SC(Sno,Cno,Grade) values(0004,1003,3);

insert into SC(Sno,Cno,Grade) values(0005,1001,5);
insert into SC(Sno,Cno,Grade) values(0005,1002,3);
insert into SC(Sno,Cno,Grade) values(0005,1003,2);
insert into SC(Sno,Cno,Grade) values(0005,1003,9);

联表查询
select student.Sno,student.Sname,course.Cname,SC.Grade from student, course, SC where student.Sno=SC.Sno and course.Cno=SC.Cno;
select student.Sno,student.Sname,course.Cname,SC.Grade from student, course, SC where student.Sno=SC.Sno and course.Cno=SC.Cno order by Sno;
在where后面建索引

explain 查询select 查询语句执行计划
就是查询这个语句,能不能走索引?

use oldboy;
drop table test;
create table test(
id int(4) not null auto_increment,
name char(20) not null,
primary key (id)
);

insert into test values(1,’oldboy’),(2,’oldgir’),(3,’inca’),(4,’zuma’),(5,’kaka’);

select * from test where name=’oldboy’;

explain select * from test where name=’oldboy’;

explain select * from test where name=’oldboy’\G;

create index index_name on test(name);

建索引和没有建索引的区别
mysql> explain select * from test where name=’oldboy’\G
* 1. row *
id: 1
select_type: SIMPLE
table: test
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 5
Extra: Using where
1 row in set (0.00 sec)

mysql> create index index_name on test(name);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> explain select * from test where name=’oldboy’\G
* 1. row *
id: 1
select_type: SIMPLE
table: test
type: ref
possible_keys: index_name
key: index_name
key_len: 60
ref: const
rows: 1
Extra: Using where; Using index
1 row in set (0.00 sec)

学习故障

排查故障,是上天给你难得的提升机会且珍惜。

1、一般解决故障,先看故障日志;

2、解决不了,再g>b,搜索关键字,尽量唯一;

3、知识点学习,查看软件帮助或者官方手册;

4、看不懂英文,先找中文再来尝试看英文;

centos 6 更新Yum源

国外centos6的镜像停止维护,阿里云源作为新源修复为新的可用地址方法
1、备份原有源mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2、下载阿里云源wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo 或

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo

3、替换为阿里云新源地址

sed -i -e ‘s/centos\/\$releasever/centos-vault\/6.10/g’ /etc/yum.repos.d/CentOS-Base.repo

epel源修复:第一步:备份原有源
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup

mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup

2、下载阿里云源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

3、替换为阿里云新源地址
sed -i -e ‘s/com\/epel/com\/epel-archive/g’ /etc/yum.repos.d/epel.repo


命令汇总:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo

sed -i -e ‘s/centos\/\$releasever/centos-vault\/6.10/g’ /etc/yum.repos.d/CentOS-Base.repo

mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

sed -i -e ‘s/com\/epel/com\/epel-archive/g’ /etc/yum.repos.d/epel.repo


参考文章

https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b117DQxFM

https://developer.aliyun.com/mirror/epel?spm=a2c6h.13651102.0.0.60381b11jAhAqL

https://help.aliyun.com/document_detail/193569.htmlhttps://developer.aliyun.com/article/779734?spm=a2c6h.14164896.0.0.1dc92e6eqpFBjk

官方源、镜像源汇总

(一)、企业站

搜狐:http://mirrors.sohu.com/

网易:http://mirrors.163.com/

阿里云:http://mirrors.aliyun.com/

腾讯:http://android-mirror.bugly.qq.com:8080/(仅针对APP开发的软件,限流,不推荐) 淘宝:http://npm.taobao.org/

(二)、教育站

上海交通大学:http://ftp.sjtu.edu.cn/html/resources.xml(部分移动运营商出口状况不佳,无法访问)

华中科技大学:http://mirror.hust.edu.cn/(当前已用容量估计:4.83T)

清华大学:http://mirrors.tuna.tsinghua.edu.cn/(当前已用容量估计:9.8T)

北京理工大学:http://mirror.bit.edu.cn/web/

兰州大学:http://mirror.lzu.edu.cn/ 中国科技大学:

http://mirrors.ustc.edu.cn/(当前已用容量估计:21.32T)

大连东软信息学院:http://mirrors.neusoft.edu.cn/(当前已用容量估计:2.5T)

东北大学:http://mirror.neu.edu.cn/

大连理工大学:http://mirror.dlut.edu.cn/

哈尔滨工业大学:http://run.hit.edu.cn/html/(部分联通运营商出口状况不佳,无法访问) 北京交通大学:http://mirror.bjtu.edu.cn/cn/

天津大学:http://mirror.tju.edu.cn(无法访问,ping超时) 中国地质大学:http://mirrors.cug.edu.cn/(当前已用容量估计:2.3T)

浙江大学:http://mirrors.zju.edu.cn/

厦门大学:http://mirrors.xmu.edu.cn/

中山大学:http://mirror.sysu.edu.cn/

重庆大学:http://mirrors.cqu.edu.cn/(当前已用容量估计:3.93T)

北京化工大学:http://ubuntu.buct.edu.cn/(Android SDK镜像仅供校内使用,当前已用容量估计:1.72T)

南阳理工学院:http://mirror.nyist.edu.cn/

中国科学院:http://www.opencas.org/mirrors/

电子科技大学:http://ubuntu.uestc.edu.cn/(无法访问,ping超时)

电子科技大学星辰工作室:http://mirrors.stuhome.net/(当前已用容量估计:1.08T)

西北农林科技大学:http://mirrors.nwsuaf.edu.cn/(只做CentOS镜像,当前已用容量估计:140GB)

浙江大学:http://mirrors.zju.edu.cn/

台湾淡江大学: http://ftp.tku.edu.tw/Linux/

软件版

(一)、操作系统类 

1.Ubuntu阿里云:http://mirrors.aliyun.com/ubuntu-releases/

网易:http://mirrors.163.com/ubuntu-releases/

搜狐:http://mirrors.sohu.com/ubuntu-releases/(搜狐在12年之后似乎不同步了)

首都在线科技股份有限公司:http://mirrors.yun-idc.com/ubuntu-releases/

2.CentOS网易:http://mirrors.163.com/centos/

搜狐:http://mirrors.sohu.com/centos/

阿里云:http://mirrors.aliyun.com/centos/