技术备忘3


技术备忘3_第1张图片



shell单引号与变量


[root@test] a=55 [root@test] echo $a 55 [root@test] echo '$a' $a [root@test] echo ''$a'' #注意此处是两个单引不是一个双引 55

总结: 在单引号中引用变量,需要这样来写(单引号括起来双引号内的变量.) :   '"${a}"'

原文地址

date星期求取

<span style="font-family:Microsoft YaHei">date +%Y-%m-%d -d '-7 days ago' 求哪天(例如: 七天后.)
date -d "2013-07-12" +%u  求哪一天是星期几 .</span>

月份的最后一个星期六

<span style="font-family:Microsoft YaHei">shell>cal 10 2013 | awk 'NF>6{a=$7} END{print a}' 
26</span>

调整mysql最大连接数

<span style="font-family:Microsoft YaHei">set GLOBAL max_connections=10000;</span>

月份哪些号是周六和周日

<span style="font-family:Microsoft YaHei">cal -m 10 2013|cut -c 15-|tail -n +3|tr " " "\n"|grep -v "^$"|sort -n</span>
感谢贵儿呀.... "-c" so nice....

批量删除进程

<span style="font-family:Microsoft YaHei">ps -ef|grep "curl.sh"|grep -v grep |cut -c 9-15|xargs kill -9</span>

manual内容重定向之后vim查看会乱码

eg:

<span style="font-family:Microsoft YaHei">shell>man 3 dhcpctl >dhcpctl_man.txt
shell>vim dhcpctl_man.txt      ///乱码 各种“^H”
shell>cat dhcpctl_man.txt       ///用cat没有乱码</span>

。。。

啥原因类?与vim,cat等有关?不过这个问题解不解决的了,不是很重要。。。看manual手册本来就不需要这么弄,只是没有用SecureCRT等工具远程连接而是在纯字符界面操作的时候,要将manual手册里面的一些提示代码弄出来。。。不是很方便。。。

did it

<span style="font-family:Microsoft YaHei">man 3 dhcpctl |col -b >dhcpctl.txt</span>
col - filter reverse line feeds from input
-b     Do not output any backspaces, printing only the last character written to each column position.

这样就没有乱码了^.^

systemtap

Linux下如何知道文件被哪个进程写
1. 我的inodewatch.stp在不同的目录下
/usr/share/doc/systemtap-client-1.8/examples/io/inodewatch.stp
不过内容一致,应该是不影响的吧~

内核版本:2.6.32-279.14.1.el6.x86_64
我运行“rpm -qf /usr/bin/stap”得到的结果是:
systemtap-client-1.8-7.el6.x86_64
systemtap-devel-1.8-7.el6.x86_64

2. 然后根据博客用法,我在boot分区随便建一个文件,并写入内容……
然后调用stap去找到哪个进程在写该文件!报错了……

<span style="font-family:Microsoft YaHei">semantic error: while resolving probe point: identifier 'kernel' at /usr/share/systemtap/tapset/vfs.stp:820:19
        source: probe vfs.write = kernel.function("vfs_write")
                                  ^

semantic error: missing x86_64 kernel/module debuginfo under '/lib/modules/2.6.32-279.14.1.el6.x86_64/build'
semantic error: while resolving probe point: identifier 'vfs' at /usr/share/doc/systemtap-client-1.8/examples/io/inodewatch.stp:3:7
        source: probe vfs.write, vfs.read
                      ^

semantic error: no match
semantic error: while resolving probe point: identifier 'kernel' at /usr/share/systemtap/tapset/vfs.stp:752:18
        source: probe vfs.read = kernel.function("vfs_read")
                                 ^

semantic error: while resolving probe point: identifier 'vfs' at /usr/share/doc/systemtap-client-1.8/examples/io/inodewatch.stp:3:18
        source: probe vfs.write, vfs.read
                                 ^

Pass 2: analysis failed.  Try again with another '--vp 01' option.
Missing separate debuginfos, use: debuginfo-install kernel-2.6.32-279.14.1.el6.x86_64</span>

正在http://sourceware.org/systemtap/ 继续学习中……
求指导: [email protected]. 或者直接回复,万分感谢~~

[Reply]

Yu Feng Reply:

系统的符号信息没安装好。

----------------------------------------

系统的符号信息这个概念不是很懂……一下安装了 “yum install -y kernel*”

...

<span style="font-family:Microsoft YaHei">Updating   : kernel-firmware-2.6.32-358.11.1.el6.noarch 
Installing : kernel-debug-2.6.32-358.11.1.el6.x86_64
Installing : kernel-2.6.32-358.11.1.el6.x86_64
Updating   : kernel-headers-2.6.32-358.11.1.el6.x86_64
Installing : kernel-debug-devel-2.6.32-358.11.1.el6.x86_64
Updating   : bfa-firmware-3.0.3.1-1.el6.noarch
Installing : kernel-devel-2.6.32-358.11.1.el6.x86_64
Installing : kernel-doc-2.6.32-358.11.1.el6.noarch
Cleanup    : kernel-firmware-2.6.32-279.14.1.el6.noarch
Cleanup    : kernel-headers-2.6.32-279.14.1.el6.x86_64
Cleanup    : bfa-firmware-3.0.0.0-1.el6.noarch</span>

...

报错还是同样的!

另外。。。按照报错最后的提示。。。用了debuginfo-install(这个工具是yum-utils包安装的...)

<span style="font-family:Microsoft YaHei">Nice[root@taolr:/boot]# debuginfo-install kernel-2.6.32-279.14.1.el6.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
Checking for new repos for mirrors
Could not find debuginfo for main pkg: kernel-2.6.32-279.14.1.el6.x86_64
No debuginfo packages available to install
Nice[root@taolr:/boot]# debuginfo-install kernel-*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
Checking for new repos for mirrors
Could not find debuginfo for main pkg: kernel-devel-2.6.32-358.11.1.el6.x86_64
Could not find debuginfo for main pkg: kernel-2.6.32-279.14.1.el6.x86_64
Could not find debuginfo for main pkg: kernel-2.6.32-220.el6.x86_64
Could not find debuginfo for main pkg: kernel-debug-devel-2.6.32-358.11.1.el6.x86_64
Could not find debuginfo for main pkg: kernel-headers-2.6.32-358.11.1.el6.x86_64
Could not find debuginfo for main pkg: kernel-debug-2.6.32-358.11.1.el6.x86_64
Could not find debuginfo for main pkg: kernel-firmware-2.6.32-358.11.1.el6.noarch
Could not find debuginfo for main pkg: kernel-doc-2.6.32-358.11.1.el6.noarch
Could not find debuginfo for main pkg: kernel-devel-2.6.32-279.14.1.el6.x86_64
Could not find debuginfo for main pkg: kernel-2.6.32-358.11.1.el6.x86_64
No debuginfo packages available to install</span>
。。。

。。。

直接去下载rpm包 ”kernel-2.6.32-279.14.1.el6.x86_64.rpm “
然后”rpm -ivh“安装,报各种错”conflicts with xxx“
。。。

这里面估计是内核方面的东西需要调整,整不明白呀……个人觉得”linux下如何知道文件被哪个进程写“这个技术很需要掌握和常用……上帝保佑……

。。。没整明白,搁下好久了。。。先放到这儿,哪会儿闲了,再继续整。。。

make a change.

fuser

用fuser加文件名.就可以list出进程ID,然后ps查看一下该进程,也可以解决这种问题!

lamp很闹人

…前面部分略

php..

 ./configure --with-apxs2=/usr/local/apache2/bin/apxs --disable-ipv6 --with-libxml-dir=/usr --with-pcre-regex=/usr/local --with-zlib=/usr --with-bz2=/usr --enable-calendar --with-curl=/usr  --with-pcre-dir=/usr/local --enable-ftp --with-openssl-dir=/usr --with-gd=/usr/local  --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-zlib-dir=/usr/local --with-xpm-dir=/usr  --with-freetype-dir=/usr/local --enable-gd-native-ttf --enable-gd-jis-conv --with-mhash=/usr/local  --enable-mbstring --with-mcrypt=/usr/local --with-mysql=/usr/local/mysql  --with-mysql-sock=/var/run/mysqld/mysql5.socket --with-mysqli=/usr/local/mysql/bin/mysql_config --with-snmp=/usr/ --enable-sockets --enable-zip --enable-maintainer-zts  && make && make install


哎…………LAMP的脚本,偶必须从头到尾弄一下!

mysql查看连接数状态

命令: show processlist; 
如果是root帐号,你能看到所有用户的当前连接。如果是其它普通帐号,只能看到自己占用的连接。 
show processlist;只列出前100条,如果想全列出请使用show full processlist; 
mysql> show processlist;

 

命令: show status;

命令:show status like '%下面变量%';

Aborted_clients 由于客户没有正确关闭连接已经死掉,已经放弃的连接数量。 
Aborted_connects 尝试已经失败的MySQL服务器的连接的次数。 
Connections 试图连接MySQL服务器的次数。 
Created_tmp_tables 当执行语句时,已经被创造了的隐含临时表的数量。 
Delayed_insert_threads 正在使用的延迟插入处理器线程的数量。 
Delayed_writes 用INSERT DELAYED写入的行数。 
Delayed_errors 用INSERT DELAYED写入的发生某些错误(可能重复键值)的行数。 
Flush_commands 执行FLUSH命令的次数。 
Handler_delete 请求从一张表中删除行的次数。 
Handler_read_first 请求读入表中第一行的次数。 
Handler_read_key 请求数字基于键读行。 
Handler_read_next 请求读入基于一个键的一行的次数。 
Handler_read_rnd 请求读入基于一个固定位置的一行的次数。 
Handler_update 请求更新表中一行的次数。 
Handler_write 请求向表中插入一行的次数。 
Key_blocks_used 用于关键字缓存的块的数量。 
Key_read_requests 请求从缓存读入一个键值的次数。 
Key_reads 从磁盘物理读入一个键值的次数。 
Key_write_requests 请求将一个关键字块写入缓存次数。 
Key_writes 将一个键值块物理写入磁盘的次数。 
Max_used_connections 同时使用的连接的最大数目。 
Not_flushed_key_blocks 在键缓存中已经改变但是还没被清空到磁盘上的键块。 
Not_flushed_delayed_rows 在INSERT DELAY队列中等待写入的行的数量。 
Open_tables 打开表的数量。 
Open_files 打开文件的数量。 
Open_streams 打开流的数量(主要用于日志记载) 
Opened_tables 已经打开的表的数量。 
Questions 发往服务器的查询的数量。 
Slow_queries 要花超过long_query_time时间的查询数量。 
Threads_connected 当前打开的连接的数量。 
Threads_running 不在睡眠的线程数量。 
Uptime 服务器工作了多少秒。

原文地址

打开mysql查询缓存

从 MySQL4开始,出现了QueryCache查询缓存,

如果使用了QueryCache,当查询接收到一个和之前同样的查询,

服务器将会从查询缓存种检索结果,而不是再次分析和执行上次的查询。

这样就大大提高了性能,节省时间,非常有用。

打开查询缓存,是通过几个步骤来设置的,例如:虽然你设置Mysql允许查询缓存,但

是如果你设置的查询缓存大小为了0,这和没有允许没什么区别。

所以必须是几个步骤的设置才能真正打开查询缓存这个功能。

下面我用 mysql6.0 最为演示最常用的设置查询缓存

第一: query_cache_type 使用查询缓存的方式

一般,我们会把 query_cache_type 设置为 ON,默认情况下应该是ON

mysql> select @@query_cache_type;
+--------------------+
| @@query_cache_type |
+--------------------+
| ON |
+--------------------+
这样 当我们执行 select id,name from tableName; 这样就会用到查询缓存。

在 query_cache_type 打开的情况下,如果你不想使用缓存,需要指明
select sql_no_cache id,name from tableName;

当然也可以禁用查询缓存: mysql> set session query_cache_type=off;
这里我们不讨论这个,我们演示常用的设置。

第二: 系统变量 have_query_cache 设置查询缓存是否可用

mysql> show variables like 'have_query_cache';

+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| have_query_cache | YES |
+------------------+-------+
上面的显示,表示设置查询缓存是可用的。

第三: 系统变量 query_cache_size

表示查询缓存大小,也就是分配内存大小给查询缓存,如果你分配大小为0,

那么 第一步 和 第二步 起不到作用,还是没有任何效果。

mysql> select @@global.query_cache_size;

+---------------------------+
| @@global.query_cache_size |
+---------------------------+
| 16777216 |
+---------------------------+
上面是 mysql6.0设置默认的,之前的版本好像默认是0的,那么就要自己设置下。

设置set @@global.query_cache_size=1000000; 这里是设置1M左右,900多K。

再次查看下 select @@global.query_cache_size;

+---------------------------+
| @@global.query_cache_size |
+---------------------------+
| 999424 |
+---------------------------+
显示我们设置新的大小,表示设置成功。

第四: query_cache_limit 控制缓存查询结果的最大值

例如: 如果查询结果很大, 也缓存????这个明显是不可能的。

MySql 可以设置一个最大的缓存值,当你查询缓存数结果数据超过这个值就不会
进行缓存。缺省为1M,也就是超过了1M查询结果就不会缓存。

mysql> select @@global.query_cache_limit;

+----------------------------+
| @@global.query_cache_limit |
+----------------------------+
| 1048576 |
+----------------------------+

这个是默认的数值,如果需要修改,就像设置缓存大小一样设置,使用set
重新指定大小。

好了,通过4个步骤就可以 打开了查询缓存,具体值的大小和查询的方式 这个因不同
的情况来指定了。

原文地址


更改 SAR 时间输出格式 AM/PM

默认状态 SAR 以中文进行输出

export LANG=en_US 执行后, 输出效果如下

06:00:01 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
06:10:01 PM     all      0.26      0.00      0.09      0.00      0.00     99.65
06:20:01 PM     all      0.28      0.00      0.09      0.00      0.00     99.63
06:30:01 PM     all      0.25      0.00      0.09      0.00      0.00     99.65

但时间变成 AM, PM 格式了

export LC_TIME="POSIX" 执行后, 输出会自动取消 AM/PM 格式, 默认变回 24 小时格式制

23:20:01    CPU     %user     %nice   %system   %iowait    %steal     %idle
23:20:01    all      0.26      0.00      0.09      0.00      0.00     99.65
23:30:01    all      0.27      0.00      0.10      0.00      0.00     99.63
23:40:01    all      0.25      0.00      0.10      0.00      0.00     99.65
23:50:01    all      0.26      0.00      0.10      0.00      0.00     99.65
Average:    all      0.26      0.00      0.09      0.00      0.00     99.65

原文地址

。。。。。。

mysql中sql的正则匹配

mysql>select a1 from table1 where a1regexp  '*.(测试).*';

mysql>select a1 from table1 where a1notregexp'*.(测试).*';


为 Python Shell 加入自动补全功能

在你的 home 目录中创建一个 .pythonrc 文件,内容如下:

.pythonrc

import rlcompleter, readline
readline.parse_and_bind('tab:complete')


设置 PYTHONSTARTUP

.pythonrc      //~/.bash_profile

export PYTHONSTARTUP=~/.pythonrc

现在你可以试试了:

.pythonrc

shell>python

>>>import sys

>>>sys.<TAB><TAB>

PYTHONSTARTUP,更多可参考: https://github.com/sontek/dotfiles/blob/master/_pythonrc.py


原文地址

...

linux文件权限匹配

文件权限的匹配是从属主开始,匹配之后就不再向下匹配,如果一个文件权限是070,有个用户是这个文件的属主也是文件所在组的,但是该用户对该文件没有权限(除root外,当然删除是可以的

linux踢终端用户

系统root用户可强制踢制其它登录用户,首先以root登录以便查看全部的在线用户信息,可用 w 或者 who 命令查看用户所在的终端。 

强制踢人命令格式:pkill -kill -t pts 
踢出tty1用户的命令为: pkill -kill -t tty1

curl在crontab中不听话

需要加上 --silent选项才行!

参考1


隐藏history记录(空格)

shell> ls   //注意,在命令前加一个 空格


MAC 装Mysql失败

mysql.server start

Starting MySQL

. ERROR! The server quit without updating PID file (/usr/local/var/mysql/xxx-MacBook-Air.local.pid)

sudo chown -R _mysql /usr/local/var/mysql


SSH LOGIN WITHOUT PASSWORD

You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.

First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:

a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):

a@A:~> ssh b@B mkdir -p .ssh
b@B's password: 

Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password: 

From now on you can log into B as b from A as a without password:

a@A:~> ssh b@B

A note from one of our readers: Depending on your version of SSH you might also have to do the following changes:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640


CI框架(PHP)nginx配置

server {
        listen       80;
        listen [::]:80 ipv6only=on;
        server_name  www.example.com;
 
        root   /data/www/www.example.com;
        index index.php  index.html index.htm;
 
        location / {
                # 这里使用try_files进行url重写,不用rewrite了。
                try_files $uri $uri/ /index.php?$query_string;
        }
 
        location ~ \.php($|/) {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param   PATH_INFO $fastcgi_path_info;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
 
        location ~ /\.ht {
                deny  all;
        }
}


如何清空Mac的DNS缓存

sudo discoveryutil mdnsactivedirectory yes

How to Flush DNS Cache in OS X Yosemite with discoveryutil


url中GBK编码的问题

encodeURIComponent和decodeURIComponent等只能针对UTF-8的编码解码

使用decodeURIComponent 解码GBK的url出现URI malformed错误

JQuery 备忘

appendTo

$("#target2").appendTo($("#right-well"));


gitlab和github下fork后如何同步源的新更新

当然,那是完全不用命令行的办法,其实我还是更推荐命令行,流程如下:

  1. 首先要先确定一下是否建立了主repo的远程源:

    git remote -v
    
  2. 如果里面只能看到你自己的两个源(fetch 和 push),那就需要添加主repo的源:

    git remote add upstream URL
    git remote -v
    

    然后你就能看到upstream了。

  3. 如果想与主repo合并:

    git fetch upstream
    git merge upstream/master


文件描述符

“文件描述符”一直没有很好地理解它,不确定这段话是否完全准确,但是能很好地帮助我理解,暂时先这样,会翻翻“Linux内核详解”相关描述好好读读!

操作系统对计算机进行了抽象,将所有输入输出设备抽象为文件。内核在进行文件I/O操作时,通过文件描述符进行管理,而文件描述符类似于应用程序与系统内核之间的凭证。应用程序如果需要进行I/O调用,需要先打开文件描述符,然后再根据文件描述符去实现文件的数据读写。而非阻塞I/O与阻塞I/O的区别在于阻塞I/O完成整个获取数据的过程,而非阻塞I/O则不带数据直接返回,要获取数据,还需要通过文件描述符再次读取。

备注:《深入浅出node.js》 第三章 “异步I/O实现现状” P51页


你可能感兴趣的:(技术备忘3)