日常积累

来源:互联网 发布:md文件js 编辑:程序博客网 时间:2024/05/21 13:50
1. 如何对mysql数据库已存在表进行修改


2. 查看mysql 数据库引擎


3. defunct进程
   ps -aux | grep defunct 表示的是僵尸进程
   
4. 检测进程打开的文件句柄数: lsof -p pid


5. sg_test 是 server 还是 client


6. 对于每一个Login, 是新启动CgiLogin进程, 还是一个CgiLogin进程处理所有的Login, 预测一个CgiLogin处理所有Login 
   FastCgi采用的是进程池框架,不是每一个链接来了之后fork
   
7. 共享内存如何处理数据的同步


8. int ftruncate(int fd,off_t length); 改变文件大小


9.  int munmap(void *start,size_t length); 解除内存映射


10. int msync ( void * addr, size_t len, int flags) 来同步磁盘文件内容与共享内存区中的内容


10. getconf PAGE_SIZE 获得系统当前页大小


11. 抽奖之后,结果怎么显示在信息中的    
客户端Flash直接用socket借口向TcpServer发送中奖数据, 然后TcpServer广播发送数据给所有的用户


12. lighttpd 和 fastcgi的关系, 是不是lighttpd关闭后, php-cgi就关闭, 还是多个lighttpd 可以共用一样的php-cgi ?


13. url编码格式 acsii编码


14. libcurl的使用


15. Socket Tcp选项: NO_DELAY有什么作用


16. 非阻塞socket EINTR EAGAIN的错误处理


17. 为什么socket要有自己的缓冲区
-. 系统缓冲区已满, 保存未发送的数据


18. core 文件生成 
在/etc/profile 或者 ~/.bash_profile  加 ulimit -c unlimited  
echo "1" > /proc/sys/kernel/core_uses_pid  生成带pid的core




19. mysql 删除主键:
alter table tb drop primary key;
添加联合主键:
alter table tb add primary key(date, platform);
添加列:
alter table tb add platform tinyint default 0;
添加列的默认值
alter table tb alter column platform set default 1;
列重命名
alter table test change name name_new varchar(20);
修改长度
alter table user modify column user_stat1 varchar(2048);


20. html页面自动刷新
<meta http-equiv="refresh" content="60;url=newPage">     #60秒刷新一次


21. js页面刷新
<script language="JavaScript">
function myrefresh(){
window.location.reload();
}
setTimeout('myrefresh()',3 * 60* 1000); 
</script>


22. 信号掩码:
sigprocmask  屏蔽信号
sigsuspend   等待信号,否则一直挂起
sigismember  检测信号是否是未处理的


23. Mysql Cpu占用过高
mysqladmin -u root -p1234  processlist status; 


24. 线程信号处理:
pthread_mask 屏蔽信号
pthread_sigwait 相当于sigaction


25. shell时间转换:
date -d "20140806 10:36:28" +%s   #能把20140806 10:36:28 转换成整形


26. mysql查询时间比较:
unix_timestamp('$Date')  unix_timestamp('$Date')+24*3600


27. shell 把整形转换成可显示时间转换  
date -d@11111111


28. mysql建表语句
CREATE TABLE `table_dnu_gate_stat`(
`date` char(10) NOT NULL,
`platform` tinyint(4) NOT NULL default '0',
`dnu` int(11) default NULL,
`d1`  varchar(8000) default NULL,
`d2`  varchar(8000) default NULL,
`d3`  varchar(8000) default NULL,
`d4`  varchar(8000) default NULL,
`d5`  varchar(8000) default NULL,
`d6`  varchar(8000) default NULL,
`d7`  varchar(8000) default NULL,
PRIMARY KEY  (`date`,`platform`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


29. Mysql备份表结构:
mysqldump --opt -d sanguo -uroot -p1234 > kongzhan.sql


30. Mysql导入数据
mysql -uroot -p1234 sanguo_kz < kongzhan.sql
mysql -uroot < boomman_game_x.sql
mysql -uroot < boomman_user_x.sql




31. Mysql杀死查询
mysqladmin -uroot -p1234 kill   


32. Scp命令:
scp -P36000 root@10.142.9.26:/data/release/sanguo/cgi/CgiLogin  .


33. 修改Mysql授权信息:
grant select,update,insert,delete on *.* to root@10.207.147.198 identified by "1234";


34. Sed替换命令:
sed -e 's/10.221.56.142/127.0.0.1/g' *.xml 


sed -i "s/10.207.147.198/127.0.0.1/g" `grep '10.221.56.142' -rl ./`


35. perl 对hash的value 进行排序
foreach my $key ( sort { $hash{$a} <=> $hash{$b} } keys %hash)


36. mysql的binlog安全删除 
purge binlog to 'mysql-bin.001151'; 删除binlog, purge会更新mysql-bin.index中的条目, mysql-bin.index的作用是加快查找binlog文件的速度


37. 修改mysql表的默认值
alter table表名alter column字段名drop default; (若本身存在默认值,则先删除)
alter table 表名 alter column 字段名 set default 默认值;(若本身不存在则可以直接设定)
alter table pms_pay add 


38. 时间操作:
struct tm * localtime(const time_t * timer); // 将日历时间转换为本地时间


39. 字符串操作
Json::ToString(equipment).c_str()


40. lighttpd 配置多域名适配
HTTP["host"] =~ "^mobile.*\.com$"   匹配 mobile.app123.com , mobileios.app123.com


41. 一个目录下各个子目录的大小
du -h --max-depth=1


42. 数组元素匹配
map { if($gate_id eq $_) { $flag = 1;} } @boss_gate_array


43. 清楚mysql binlog日志:
PURGE MASTER LOGS BEFORE '20150209 00:00:00';


44. TTC 错误码
2021 是更改了 db.conf, 后缓存中的表结构发生变了, 后会出现这个问题。  不用修护,client api意识到这个问题后,会自动修护
2039 超出值定义范围,一般也没啥问题


45. 解决/bin/bash^M: bad interpreter
vi , set fileformat=unix


46. 查看可执行文件 符号列表
readelf -s -W CgiLogin

47. 修改stat_main_index.pl的时候一定要切记, 测试的时候用当天的时间
stat_main_index.pl一定要记得修改执行权限


48. cocos new -pGAction  -de: -lcpp


49. perl 查找子串
my $result = index($channel, "1Local");

50. perl 默认计算都是浮点型, 取整函数 int 


51. ssh自动登陆 免密码,用户名
1. 创建公钥 
ssh-keygen -t rsa 
2. 复制 id_pub.rsa 到远程机上
scp id_rsa.pub root@10.10.2.54:/root/.ssh/authorized_keys
chmod 600 authorized_keys
~/.ssh/authorized_keys 如果执行权限不为 600, 就会scp 无密码拷贝不成功 (貌似Centos7.0以上系统没有这个问题了)
3. 解决本地登陆用户与远程登陆用户不一致 
  vi ~/.ssh/config 
  Host 10.10.2.84
  user denny 

52. jsoncpp, string 转 Json::Value
Json::Reader reader; Json::Value data;
reader.parse(userBasic.extra, data);
---------------------------------
Json::Value user_stat;
Json::FromString(user_stat, user.user_stat);


53. Json, value 转 string
Json::FastWriter write;
user.user_stat = write.write(user_stat);

54. perl 用 DBI, 做 update, delete, insert, alter 处理
my $sql = “alter table user add index socre_index(score)”;
$dbh->do( $sql);
if ( $dbh->err() ) 
{
die “$DBI::errstr\n”;
}
$dbh->commit();

55. Mysql 增加索引
alter table score add index socre_index(score);
alter table score drop index socre_index;

56. JDK路径配置
JAVA_HOME:  C:\JDK\
PATH后增加: %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
CLASSPATH: .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar


57. c++11 
C++ 11 编译
要加上 -std=c++0x
g++ -std=c++0x -o func func.cpp   # -std=c++0x 一定要放在 -o 之前, 否则编译不过


58. std::function, std::bind
能够很好的解决回调函数, 调用类的成员函数


59. usleep 只阻塞当前线程,并不会阻塞其他线程


60. 无锁队列是没有事件同步通知机制, 如果没有数据的啦,就出于忙等状态


61. uint64_t 是在 /usr/include/stdint.h 中定义的, C99标准


62. 动态库添加 
vi /etc/ld.so.conf 
增加动态库路径, 后运行 ldconfig 


63. 网络字节序:就是大端字节序。规定不同系统间通信一律采用网络字节序
但是对于自有系统来说,其实很少有这个问题
只要客户端,服务器端都是自己定义的,那么字节序就不成问题, 但是可能如果Android采用的是大端的字节序, 那么如果不做字节转换的就应该解析出错

64. lvm 动态增加减少磁盘大小
增加: 先修改lvm,再增加文件系统
lvextend -L +10G /dev/testvg/testlv 
resize2fs -f /dev/testvg/testlv 30G
减少:先减少文件系统,再减少lvm
http://blog.itpub.net/32980/viewspace-1123851/
1.umount filesystem
2.e2fsck filesystem
3.resize2fs filesystem
4.lvredure
5. mount


65. 增加默认网关
route add default gw 10.10.2.1   #能ping通网关,但ping不同外网, 很有可能是没有设置默认网关


66. 修改共享内存大小:
sysctl -a | grep shm
echo 3355443200 > /proc/sys/kernel/shmmax
sysctl -p 


67. mysql 修改root 密码
方案一 
mysql> use mysql; 
mysql> update user set password=password('root') where user='root' and host='localhost'; 
update user set password=password('tgame') and host='%' where user='tgame'; 
update user set host='%' where user='tgame'; 
update user set host='10.145.11.190' where user='tgame'; 
mysql> update user set password=password('tgame') where user='tgame' and host='%'; 
update user set host='127.0.0.1' and password=password('root') where user='root';
flush privileges;
方案二:
grant all privileges on *.*  to tgame@l0.145.11.190 identified by "tgame";
grant all privileges on *.*  to fgame@127.0.0.1 identified by "root";
grant all privileges on *.*  to tgame@localhost identified by "tgamedb";
grant all privileges on *.*  to tgame@localhost identified by "tgamedb";


grant all privileges on *.*  to tgame@localhost identified by "";


grant all privileges on *.*  to root@127.0.0.1 identified by "root";


grant all privileges on *.*  to ddz@127.0.0.1 identified by "password";


grant all privileges on *.* to root@localhost;


grant all privileges on *.* to root@10.10.2.92;


grant all privileges on *.* to root@10.144.94.39 ;


GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;  
grant all    on *.* to root@127.0.0.1;
grant select on *.* to root@127.0.0.1;
flush privileges;


68. show innodb status; 查看数据库情况


69. linux查看一个进程的运行时间
ps axo pid,ppid,comm,pmem,lstart | grep MPSvr
ps axo pid,ppid,comm,pmem,lstart | grep MainSvr


71. redis-cli 使用
keys * 
zrange zone1_1 0 -1 withscores


72. 清空redis
flushdb


73. mysql 去掉空格 ltrim, rtrim, 取子串 left(a,20) ,长度 length


74. vi 显示控制字符 set list, set nolist 


75. ftp命令:
ls, cd, mkdir, delete, get|mget, put|mput 

76. protoc 命令
protoc -I=. --cpp_out=. float.proto


77. lua 堆栈打印
print(debug.traceback())


78. lua引用外部文件
package.path = package.path .. ";./?.lua"
local test2  = require("test2")


79. protobuf 生成中间文件
protoc --descriptor_set_out ClientSvrMsg.pb ClientSvrMsg.proto


80. lua获取当前路径
print(os.getenv("PWD"))

81. redis, incr可以全局唯一增长一个值,watch做事务处理


82. redis 哈希结构 
Redis
支持5种类型 string list set zset dict
string 
set a "123"
get a  
/*
"1"
*/


list
lpush my_list aaa
lpush my_list bbb
lpush my_list ccc
lrange my_list 0 10 
/*
1) "c"
2) "b"
3) "a"
*/


哈希
HMSET user:1 username root password 123456 level 1
HGETALL user:1
hget account 10005


/*
1) "username"
2) "root"
3) "password"
4) "123456"
5) "level"
6) "1"
*/


set
sadd my_set qqq
sadd my_set www
sadd my_set eee
smembers my_set
/*
1) "eee"
2) "qqq"
3) "www"
*/


zset
zadd my_zset 1 aaa
zadd my_zset 2 bbb
zadd my_zset 3 ccc
zadd my_zset 4 ddd
zrange my_zset 0 10 withscores
/*
1) "aaa"
2) "1"
3) "bbb"
4) "2"
5) "ccc"
6) "3"
7) "ddd"
8) "4"
*/


84. 杀死相关进程
pgrep skynet | xargs kill -9


85. linux 最大文件描述符
cat /proc/sys/fs/file-max
cat /etc/security/limits.conf


86. 删除目录下svn数据
find . -type d -name ".svn" | xargs rm -rf


87. valgrind 使用
valgrind --tool=memcheck --leak-check=full ./test


88. profile使用
在编译skynet时, 加上 -lprofiler
env CPUPROFILE=./center.prof ../skynet/skynet  conf/config.center 
pprof -text ../skynet/skynet  center.prof 
但这里有个问题就是,skynet要自己正常关闭,也就是调用skynet.abort, 用Crtl+C, kill 都没有用


89. cpu信息查看命令:
物理cpu个数:
cat /proc/cpuinfo |grep "physical id"|sort |uniq
逻辑Cpu个数:
cat /proc/cpuinfo |grep "processor"
Cpu核数:
cat /proc/cpuinfo |grep "cores"
Cpu主频:
cat /proc/cpuinfo |grep MHz|uniq 
Cpu型号:
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
Cpu详细信息:
cat /proc/cpuinfo


90. redis-cli 访问远程主机
redis-cli -h 10.10.128.49 -p 6379
redis-cli -h 10.10.137.129 -p 6379
redis-cli -h 


云存储2
10.10.150.239:6379
10.10.183.142:6379


redis-cli -h 10.10.150.239 -p 6379


mysql -uroot -p61baozi@lianxiang -h10.10.139.35 -P3306


92. gdb 带参数调试:
gdb skynet
set args conf/config


95: mysql 远程连接
mysql -uweb -p61Statistical@Games_ -h119.29.26.122 
mysql -uweb -h119.29.26.122 -P3307 -p61Statistical@Games_


96:redis获取全部配置
CONFIG GET *


97. linux时区修改 
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
或者
export TZ='Asia/Shanghai'


98. linux 修改整个目录时间
find  .  -name '*'  -exec touch {} \;


99. tar 显示一个 tar.gz 里面文件的内容
tar tf game.tar


100. leetcode


101. mysql忘了密码的处理方式:
my.cnf 中 [mysqld] 下添加 skip-grant-tables


102. redis 查看参数


103. awk  sed 混用
grep shopId *.log | awk -F" " {'print $6'} | awk -F "," {'print $3'} | awk -F ":" {'print $2'} | sed  "s/}//g" |  awk '{ if ($1==6) {sum += 1}} END {print sum}'


104. 命令行vi查看 
开启: set -o vi
关闭: set +o vi


105. rpm包安装
rpm -ivh a.rpm


106. 查看glibc的版本
strings /lib64/libc.so.6 |grep GLIBC_


107. glibc 升级:
/lib64/libc.so.6 -> libc-2.12.so
rm -rf /lib64/libc.so.6  
LD_PRELOAD=/lib64/libc-2.15.so
ldconfig


108. git命令相关
查看文件的修改时刻
git log -p 3rd/lua/lapi.c  
git blame 3rd/lua/lapi.c
git show c7b5015e
git log  c7b5015e..


109. redis 绑定 127.0.0.1


110. vi正文本替换字段
:%s/vivian/sky/g
:%s/10.105.86.119/10.105.98.107/g


111. vi 列模式删除
Ctrl + V 切换到列模式


112. the_silver_searcher 
the_silver_searcher  ag  


113. 腾讯挂载盘:
mkfs -t ext4 -c /dev/vdb 
mount /dev/vdb /data
usermod -d /data/fgame fgame


114. mariadb 
yum install mariadb-server -y
systemctl start mariadb.service
systemctl enable mariadb.service


115. 切换shell
cat /etc/shells
chsh -s /bin/zsh


116 dmesg addr2line 查找coredump 位置
dmesg | grep segment
addr2line -e main 080483fd


117 关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
irewall-cmd --state #查看默认防火墙状态


118 sudo 遇到 command not found 的情况
sudo -E env "PATH=$PATH" ll -l


119  CentOs7.2 修改hostname
hostnamectl set-hostname  master


120 CentOs7 关闭防火墙
systemctl stop firewalld.service #停止firewall 
systemctl disable firewalld.service #禁止firewall开机启动 


121  *.so 动态库文件找不到
在 /etc/ld.so.conf 增加路径, 并运行 ldconfig /etc/ld.so.conf 让加载成功


122  
git 首先添加 ssh-key


123  pptp client 
pptpsetup --create ddzvpn --server 182.150.21.69 --username dev61 --password #cT$Sv*YtSFXxxJs


124 CentOs 替换 yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache


125 mongodb操作
创建数据库
use dn
db.dn.insert({"name":"test"})


mongodb 查找语句
db.testdb.find({"test_key": {$gt : 0}}).sort({test_key:1}).skip(1).limit(1).count()


多sort
db.testdb.find({"test_key": {$gt : 0}}).sort({test_key:1,test_key2:-1}).skip(1).limit(2)




删除数据库
use dn
db.dropDatabase()
db.collection.drop()


db.col.insert({title: 'MongoDB 教程', 
    description: 'MongoDB 是一个 Nosql 数据库',
    by: '菜鸟教程',
    url: 'http://www.runoob.com',
    tags: ['mongodb', 'database', 'NoSQL'],
    likes: 100
})


db.test.insert({
   "_id":ObjectId("52ffc33cd85242f436000001"),
   "contact": "987654321",
   "dob": "01-01-1991",
   "name": "Tom Benzamin",
   "address": [
      {
         "building": "22 A, Indiana Apt",
         "pincode": 123456,
         "city": "Los Angeles",
         "state": "California"
      },
      {
         "building": "170 A, Acropolis Apt",
         "pincode": 456789,
         "city": "Chicago",
         "state": "Illinois"
      }]
}) 


126. mongodb 启动
./mongod -f mongodb.conf
  
127. svn 可执行权限修改
svn propset svn:executable on *.sh 


128. go get 代理
git config --global http.proxy "192.168.0.118:1080"


129. logrotate 日志分离工具


130. 把当前时间转换成时间戳
date +%s


131. beego 由于权限问题 极易引起 invalid argument, 但是具体哪里引起的权限问题却并不可知


132. mysql 自增字段设置初始值 
alter table pms_pay auto_increment = 101000;


133. mysql创建用户:
CREATE USER  'roott'@'localhost' IDENTIFIED BY 'Password!#DD'; 
grant all privileges on *.*  to roott@localhost identified by "Password";
flush privileges;


134. redis 配置需要研究下


135. php laravel 启动 
 php artisan serve


136. mysql update 
update pms_users set username='admin' , password='21232f297a57a5a743894a0e4a801fc3'  where userid = '1461312703628858832';


137. redis 增长指定值 
incrby max_id 10000    10000
incrby max_id 10       10010 


138. tar.xz 后缀解压 
tar xvJf  ***.tar.xz 


139. mongodb 查询语句
db.room_record.find({game_type:'DN_GAME', ts : {$lt:1502640000,  $gt:1502553600}})



















原创粉丝点击