前言
经常跑到服务器上做一些事情, 命令多了, 总是忘了, 把自己常用的一些总结出来.
添加用户
adduser desmond // 添加新用户
passwd desmond // 修改用户密码
iptables 打开端口
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
防火墙
查询状态
service iptables status
停止
service iptables stop
打开
service iptables start
重启
service iptables restart
永久关闭
chkconfig iptables off
永久打开
chkconfig iptables on
修改文件所属人
sudo chown -R root:root dir
解压
tar 指定目录
tar -zxvf server.tar.gz -C server
tar 解压重命名
tar -zxvf server.tar.gz -C server --strip-components 1
mysql
grant all on *.* to 'root'@'127.0.0.1' identified by '***';
flush privileges;
nginx
# 禁止访问隐藏文件
location ~ /. {
deny all;
}
ssh
下载文件
scp username@servername:/path/filename /tmp/local_destination
上传文件
scp /path/local_filename username@servername:/path
目录
scp -r
git
# 忽略已经跟踪的文件
git rm --cache file.txt
add file.txt to .gitignore
# 本地忽略已经跟踪的文件
git update-index --assume-unchanged .cproject
# 忽略文件夹
git ls-files -z lib/ | xargs -0 git update-index --assume-unchanged
--assume-unchanged 把文件标记为 "没有变更"
--no-assume-unchanged 清除 assumed-unchanged 位
创建软连接
ln -s /suroce /dis
性能检测
yum install valgrind
valgrind --leak-check=full ./qserver
1、memcheck:检查程序中的内存问题,如泄漏、越界、非法指针等。
2、callgrind:检测程序代码的运行时间和调用过程,以及分析程序性能。
3、cachegrind:分析CPU的cache命中率、丢失率,用于进行代码优化。
4、helgrind:用于检查多线程程序的竞态条件。
5、massif:堆栈分析器,指示程序中使用了多少堆内存等信息。
6、lackey:
7、nulgrind:
这几个工具的使用是通过命令:valgrand --tool=name 程序名来分别调用的,当不指定tool参数时默认是 --tool=memcheck
//内存泄漏检测
valgrind --leak-check=full --show-reachable=yes --track-origins=yes ./qserver
//关系图生成 cache剖析器 Graphviz ; gprof2dot.py放在/usr/bin下
valgrind --tool=callgrind ./qserver
gprof2dot.py -f callgrind callgrind.out.8444 |dot -T png -o report.png
链接静态库:这种方式是最为常用的方式,后面会有详细的介绍。
方式:在代码link过程中添加参数 –lprofiler
For example:gcc […] -o helloworld –lprofiler
运行程序:env CPUPROFILE=./helloworld.prof ./helloworld
pprof --pdf programe programe.prof > p.pdf
自己总结出来的分析内存泄露问题
valgrind --log-file=valgrind.log --tool=memcheck --leak-check=full --trace-children=yes --show-reachable=no --show-possibly-lost=no ./ften -d
possible lost 太多了, 特别是在使用各种库的时候, 所以我们只要关心完全确定丢失的就好
screen
screen -dmS montrobor
screen -ls
screen -r id
ctrl + a, 然后d
编码转换
enca -x utf-8 *
打印系统日志
sudo demsg
tcmalloc生成日志
pprof --pdf ./ften --base=../ften.0001.heap ../ften.0104.heap > ften.pdf
欢迎大家订阅雀观代码, 我将给你讲述, 中小企业程序员, 淘金路上的故事.
