1. 压测工具
    1. https://github.com/rakyll/hey
  2. 域名支持
    1. 非www跳转www
  3. 文件系统优化
    1. 关闭 accesstime
      1. done
    2. 修改ulimit
      1. done ulimt -n 65535
  4. nginx
    1. rsync 主动同步同时解决 data目录单点问题
      1. https://rsync.samba.org/
      2. https://rsync.samba.org/how-rsync-works.html
      3. https://xdays.me/rsync%E6%96%87%E4%BB%B6%E5%90%8C%E6%AD%A5%E6%9C%8D%E5%8A%A1.html
    2. 图片反向代理缓存
      1. http://phl.iteye.com/blog/2256356
      2. http://labs.frickle.com/nginx_ngx_cache_purge/
    3. 进程数
  5.  php
    1. 升级php7
      1. 这个还是必须的:性能提升非常大
      2. https://blog.csdn.net/xiao_zhui/article/details/72556781
    2. php7性能优化
      1. http://www.laruence.com/2015/12/04/3086.html
      2. 开启opcache
        1. 软连发布需要特别注意:
          1. 建议参考:https://github.com/meolu/walle-web/issues/109
            1. opcache.validate_timestamps = 0,即关闭 opcache 文件更新检查;发布代码,高级任务里,发布完成后执行 curl 调用 web(php-fpm) 下的php, opcache_reset(); 不要使用 文件session、文件缓存之类的。
            2. php cli的opcache和 fpm的是分离的。
      3. 开启hugepage
      4. [root@good work]# sysctl vm.nr_hugepages=512[root@good work]# cat /proc/meminfo | grep Huge[root@good work]#
    3. laravel 性能优化
      1. https://segmentfault.com/a/1190000011569012
    4. 进程数目
  6.  缓存
    1. 优化核心入口缓存 效率提升2/3
    2. redis缓存链接数优化 多次变一次
    3. apc缓存
    4. 走本地redis
  7. 服务器升级cpu
  8. 日志保留时间 和 磁盘监控
  9. 机器端口策略
  10.  其他
    1. 邮件发送服务申请公共账号
  11. 数据库安全

 

#查看当前挂载了的磁盘
[root@good ~]# fdisk -l
磁盘 /dev/vda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0008d73a

设备 Boot Start End Blocks Id System
/dev/vda1 * 2048 83884031 41940992 83 Linux

继续阅读

当我们在 shell 的 bash 里操作多行内容的字符串,我们往往会想到 普通的字符串处理办法 例如:

string="Hello linux"
echo $string

其实 bash 提供了一个非常好的解决办法,就是 “Multi-line”
变量的基本使用
e.g. 包含变量

cat > myfile.txt <<EOF
this file has $variable $names $inside
EOF


# 注入文档到 myfile.txt
cat myfile.txt
#输入:
#this file has

variable="ONE"
names="TWO"
inside="expanded variables"

cat > myfile.txt <<EOF
this file has $variable $names $inside
EOF


#print out the content of myfile.txt
cat myfile.txt
#输入:
#this file has ONE TWO expanded variables

无变量

cat > myfile.txt <<"EOF"
this file has $variable $dollar $name $inside
EOF

cat myfile.txt
#得到
#this file has $variable $dollar $name $inside

#PS:引用符号 "EOF" 决定是否需要输入变量

无变量 – 例子 2

cat > myfile.txt <<EOF
this file has $variable \$dollar \$name \$inside
EOF


cat myfile.txt
# 得到
# this file has $variable $dollar $name $inside

#转义 dollar "$" 符号,bash将取消变量的解析

将一个多行文本赋值到变量里面
例1:

read -d '' stringvar <<-"_EOF_"

all the leading dollars in the $variable $name are $retained

_EOF_
# 输入变量
echo $stringvar;
# all the leading dollars in the $variable $name are $retained

例2:

read -d '' help <<- "_EOF_"
  usage: up [--level <n>| -n <levels>][--help][--version]

  Report bugs to:
  up home page:
_EOF_

例3:

VARIABLE1="<?xml version="1.0" encoding='UTF-8'?>
<report>
  <img src="a-vs-b.jpg"/>
  <caption>Thus is a future post on Multi Line Strings in bash
  <date>1511</date>-<date>1512</date>.</caption>
</report>"

例4:

VARIABLE2=$(cat <<EOF
<?xml version="1.0" encoding='UTF-8'?>
<report>
  <img src="a-vs-b.jpg"/>
  <caption>Thus is a future post on Multi Line Strings in bash
  <date>1511</date>-<date>1512</date>.</caption>
</report>
EOF
)

例5:

VARABLE3=`cat <<EOF
<?xml version="1.0" encoding='UTF-8'?>
<report>
  <img src="a-vs-b.jpg"/>
  <caption>Thus is a future post on Multi Line Strings in bash
  <date>1511</date>-<date>1512</date>.</caption>
</report>
EOF`

例6 (直接写入文件):

cat > heredocfile.txt <<_EOF_
I am line 1
I am line 2
I'm the last line
_EOF_

# 测试
cat heredocfile.txt
# I am line 1
# I am line 2
# I'm the last line

# and then, change your echo statement to include the '-e' option
# which will turn on escape sequence processing:
echo -e $USAGE >&2

例7:

sudo cat > /aaaa.txt <<_EOF_
I am line 1
I am line 2
I'm the last line
_EOF_

# sudo and >>: permission denied

例8:

# create
sudo tee /aaa.txt << EOF
  echo "Hello World 20314"
EOF

例9(可向文本文件追加):

# Append to Sudo
sudo tee -a  /aaa.txt << EOF
 echo "This Line is appended"
EOF

例如10:

sudo sh -c "cat > /aaa.txt" <<"EOT"
this text gets saved as sudo - $10 - ten dollars ...
EOT

cat /aaa.txt
#this text gets saved as sudo - $10 - ten dollars ...

例11:

cat << "EOF" | sudo tee /aaa.txt
let's count
$one
two
$three
four

EOF

cat /aaa.txt
#let's count
#$one
#two
#$three
#four

关于 tee
> tee –help
Usage: tee [OPTION]… [FILE]…
Copy standard input to each FILE, and also to standard output.

-a, –append append to the given FILEs, do not overwrite
-i, –ignore-interrupts ignore interrupt signals
–help display this help and exit
–version output version information and exit

If a FILE is -, copy again to standard output.

Report tee bugs to bug-coreutils@gnu.org
GNU coreutils home page:
General help using GNU software:
For complete documentation, run: info coreutils ‘tee invocation’

参考:
1. Heredoc Quoting – Credit to Ignacio Vazquez-Abrams: http://serverfault.com/questions/399428/how-do-you-escape-characters-in-heredoc
2. eredoc Quoting – Credit to Dennis Williamson: http://stackoverflow.com/questions/3731513/how-do-you-type-a-tab-in-a-bash-here-document
3. http://serverfault.com/questions/72476/clean-way-to-write-complex-multi-line-string-to-a-variable
4. http://arstechnica.com/civis/viewtopic.php?p=21091503
5. http://superuser.com/questions/201829/sudo-permission-denied
6. http://stackoverflow.com/questions/4937792/using-variables-inside-a-bash-heredoc
7. http://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work
8. http://www.unix.com/shell-programming-scripting/187477-variables-heredoc.html

来源:http://www.woola.net/detail/2016-09-05-bash-multi-line-text.html

Encrypting Your File

tar and gzip the file, then encrypt it using des3 and a secret key.
tar cvzf – mysql_dump.sql | openssl des3 -salt -k #YOUR PASSWORD# | dd of=encrypted_mysql_dump
That simple!

Decrypting Your File

dd if=encrypted_mysql_dump |openssl des3 -d -k #YOUR PASSWORD# |tar xvzf –

ls -ial   #获取文件节点
find . -maxdepth 1 -type f -inum 748010  -delete   #通过节点删除

1. 每个文件有唯一的索引号
2. ls -i 可获得索引号
3. find命令重命名:
find . -inum 索引号 -exec mv {} newname \;
-exec后为shell命令,{}代表当前文件名,\;表示shell命令结束
4. 批量重命名:
ls -i | awk ‘{printf(“find . -inum %s -exec mv {} %03d.txt \;\n”,$1,++i)}’ | sh
awk的printf命令与C语言类似,$1表示已空格分隔的第一个参数,++i变量未初始化,默认为0