centos7设置第二个ip

cd /etc/sysconfig/network-scripts/

vi ifcfg-ens33:0

NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.2.2
NETMASK=255.255.255.0
2017/7/22 posted in  OPS

Linux系统常用管理命令

2017/2/21 posted in  OPS

grep和find命令使用报告

2016/10/5 posted in  OPS

wireshark在mac远程抓包

wireshark下载:https://www.wireshark.org/download.html

在需要被抓包的机器上安装wireshark

yum install -y wireshark

在mac的命令行中使用命令启动wireshark

ssh root@epoll 'dumpcap -i ens33 -w - -f "not port 22"' | wireshark -k -i -

操作效果如下

也可以直接从wireshark中启动

2016/7/10 posted in  OPS TCP/IP mac

swoole项目service模板

2016/7/5 posted in  PHP OPS

gogs作为系统服务

[Unit]
Description=Gogs
After=syslog.target
After=network.target

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=simple
User=git
Group=git
WorkingDirectory=/home/git/gogs
ExecStart=/home/git/gogs/gogs web
Restart=always
Environment=USER=git HOME=/home/git

[Install]
WantedBy=multi-user.target

加载这个service和启动gogs

systemctl daemon-reload
systemctl start gogs
2014/7/12 posted in  OPS GIT

三分钟上手shell语言

if语句

if [ "$arg1" = "$arg2" ] && [ "$arg1" != "$arg3" ]
then 
    echo "arg1和arg2相等,arg1和arg3不相等"
    exit 3
elif [ $arg1 = $arg2 ] && [ $arg1 = $arg3 ]
then
    echo "arg1, arg2, arg3均相等"
    exit 0
else
    echo "arg1, arg2, arg3都不相等"
    exit 4 
fi

for 循环语句

for i in $(seq 1 10);
do
    echo $i
done
arr=`seq 1 10`

for i in $arr
do
    echo $i
done

while语句

# 初始化变量值为0
a=0
while [ $a -lt 10 ]
do
    echo $a
    a=`expr $a + 1`
done

case语句

# 初始化变量a
a=4
case "$a" in
"1")
    echo "a等于1"
    ;;
"2" | "3")
    echo "a等于2或3"
    ;;
*)
    echo "a不等于1,2或3"
    ;;
esac

将一个命令的输出保存到变量

使用$(一个命令)就可以获取这个命令的输出了,然后可以把这个输出赋值给一个变量
比如把当前目录的文件保存到变量中

arr=$(ls)

操作效果如下

整数运算操作

使用双小括号的语法:$((运算内容)),返回运算后的结果,支持+, -, *, /, %, **, +=, -=, *=, /=, 自增,自减,进制转换等操作

i=1
b=$((i+1))
c=$((i=i+1))
d=$((i++))
e=$((++i))

echo $b # 2
echo $c # 2
echo $d # 2
echo $e # 4

处理换行

echo "aaa:bbb:ccc:ddd" | tr ":" "\n" | sed '/ccc/a\Chanpter 1'

一些注意的点

变量声明时不需要加$符号,但是使用时需要加,=左右不能存在空格

sed可做文件内容的字符串替换

awk可做文件内容输出的格式化

shell的操作符分数字和字符串,注意使用对应的操作符,文件也有对应的操作符,参考:http://www.tutorialspoint.com/unix/unix-basic-operators.htm

查看linux发行版: cat /etc/*release

查看进程树

pstree -p 进程的id
ps aft

参考资料

  1. https://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output/
  2. https://stackoverflow.com/questions/49110/how-do-i-write-a-for-loop-in-bash
  3. https://stackoverflow.com/questions/2359270/using-if-elif-fi-in-shell-scripts
  4. https://stackoverflow.com/questions/37985926/unix-shell-script-while-loop
  5. http://www.tutorialspoint.com/unix/unix-basic-operators.htm
  6. https://stackoverflow.com/questions/5562253/switch-case-with-fallthrough
2013/7/6 posted in  OPS 三分钟系列