检测网站

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash
WEBSITE=(baidu.com www.qq.com www.163.com https://www.google.com.hk)
export http_proxy=http://127.0.0.1:8118
export https_proxy=http://127.0.0.1:8118
DATE=`date '+%Y-%m-%d %H:%M:%S'`
#echo $DATE
for ((i=0;i<"${#WEBSITE[*]}";i++))
do
  CODE=`curl -A "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0" -o /dev/null -s --connect-timeout 5 --max-time 5 --referer "www.baidu.com" -w %{http_code} ${WEBSITE[$i]}`
  if [ $CODE -ne "200" ];then
	echo "TIME: $DATE \nISSUE: ${WEBSITE[$i]} is down \n"CODE: " $CODE"
  fi
done
1
2
3
4
5
6
7
8
#!/bin/bash
for i in {1..255}
do
  CODE=`curl -o /dev/null -s --connect-timeout 1 --max-time 1 -w %{http_code} http://192.168.9.$i`;
  if [ $CODE -ne "000" ];then
    echo $CODE+"//"+$i
  fi
done
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#!/bin/bash
export http_proxy=http://127.0.0.1:8118
export https_proxy=http://127.0.0.1:8118
wget -t 2 -T 5 --spider http://google.com &> /dev/null

if [ $? -eq 0 ];then
	echo "check is OK"
else
	echo "check is FAILED"
fi

zsh

查看

1
cat /etc/shells

安装

1
2
sudo yum install -y zsh
wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh

配置

1
2
3
4
#改为zsh
chsh -s /bin/zsh
#恢复bash
chsh -s /bin/bash root

换肤

1
2
vi ~/.zshrc
ZSH_THEME="robbyrussell"

语法高亮

1
2
3
4
5
6
cd ~/.oh-my-zsh/custom/plugins
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git
vi ~/.zshrc
plugins=(
git zsh-syntax-highlighting
)

vi

1
vi ~/.vimrc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
" 语法高亮
syntax on

" 显示行号
set nu

" 侦测文件类型
filetype on

" 制表符为4 
set tabstop=4 

" 统一缩进为4 
set softtabstop=4 
set shiftwidth=4 

" 不要用空格代替制表符  
set noexpandtab 

" 不要换行  
set nowrap

systemd设置PATH

1
2
# systemd无法获取/etc/profile中设置的PATH变量,使用Environment参数在/lib/systemd/system/nginx.service文件中传入
Environment="PATH=/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/cni/bin"
1
2
3
4
5
6
7
sudo mkdir -p /etc/systemd/system/docker.service.d/
#sudo vi /etc/systemd/system/docker.service.d/docker.conf
cat > /etc/systemd/system/docker.service.d/docker.conf <<EOF
[Service]
#Environment="HTTP_PROXY=http://10.0.2.2:8118" "HTTPS_PROXY=http://10.0.2.2:8118" "NO_PROXY=localhost,127.0.0.1"
Environment="PATH=/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/cni/bin"
EOF

sudo设置PATH

1
vi /etc/sudoers
1
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

nginx日志

1
2
3
4
5
6
7
#!/bin/bash
LOGS_PATH=/data/nginx/logs
NGINX_PID=/data/nginx/logs/nginx.pid
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${YESTERDAY}.log
mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error_${YESTERDAY}.log
kill -USR1 `cat $NGINX_PID`

useradd

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 查询用户
id www
# 增加组
groupadd www
# 增加用户
useradd www -g www -s /sbin/nologin -M
# 改密码
echo "vagrant:vagrant" | sudo chpasswd
# 增加docker组
sudo groupadd docker
# 将vagrant用户增加到docker组
sudo usermod -aG docker vagrant
sudo groupadd usbmux --system;
sudo adduser --system --no-create-home usbmux;
sudo usermod -a -G usbmux usbmux;
sudo useradd -M -s /sbin/nologin nginx
sudo usermod -a -G docker vagrant
sudo usermod -a -G docker root
sudo groupadd mysql
sudo useradd -r -g mysql 
groupadd postgres
useradd -G postgres postgres
passwd postgres
# lastb查询登录失败记录
sudo lastb|awk '{print $1}' |sort |uniq -c |sort -n -k 1 |tail

kill

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#从容关闭
kill -s QUIT `cat /data/nginx/logs/nginx.pid`
#表示重新加载配置。此操作不会中断用户的访问请求,因此可以通过此信号平滑重启Nginx
kill -HUP `cat /data/nginx/logs/nginx.pid`
#用于Nginx的日志切换,也就是重新打开一个日志文件
kill -USR1 `cat /data/nginx/logs/nginx.pid`
#用于平滑升级可执行程序
kill -USR2 `cat /data/nginx/logs/nginx.pid`
#从容关闭worker进程
kill -WINCH `cat /data/nginx/logs/nginx.pid`
#快速关闭
kill -TERM `cat /data/nginx/logs/nginx.pid`
#快速关闭
kill -INT `cat /data/nginx/logs/nginx.pid`
#强制关闭
kill -9 `cat /data/nginx/logs/nginx.pid`

sshd改端口

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
journalctl -xe
1月 14 22:40:23 li1456-21 systemd[1]: sshd.service failed.
1月 14 22:41:05 li1456-21 systemd[1]: sshd.service holdoff time over, scheduling restart.
1月 14 22:41:05 li1456-21 systemd[1]: Stopped OpenSSH server daemon.
-- Subject: Unit sshd.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit sshd.service has finished shutting down.
1月 14 22:41:05 li1456-21 systemd[1]: Starting OpenSSH server daemon...
-- Subject: Unit sshd.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit sshd.service has begun starting up.
1月 14 22:41:06 li1456-21 sshd[25801]: error: Bind to port 10086 on 0.0.0.0 failed: Permission denied.
1月 14 22:41:06 li1456-21 sshd[25801]: error: Bind to port 10086 on :: failed: Permission denied.
1月 14 22:41:06 li1456-21 sshd[25801]: fatal: Cannot bind any address.
1月 14 22:41:06 li1456-21 systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a
1月 14 22:41:06 li1456-21 systemd[1]: Failed to start OpenSSH server daemon.
-- Subject: Unit sshd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit sshd.service has failed.
-- 
-- The result is failed.
1月 14 22:41:06 li1456-21 systemd[1]: Unit sshd.service entered failed state.
1月 14 22:41:06 li1456-21 systemd[1]: sshd.service failed.
1月 14 22:41:21 li1456-21 polkitd[20483]: Registered Authentication Agent for unix-process:25803:116458458 (system bus name :1.5311 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedes
1月 14 22:41:21 li1456-21 systemd[1]: Stopped OpenSSH server daemon.
-- Subject: Unit sshd.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit sshd.service has finished shutting down.
1月 14 22:41:21 li1456-21 systemd[1]: Starting OpenSSH server daemon...
-- Subject: Unit sshd.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit sshd.service has begun starting up.
1月 14 22:41:21 li1456-21 sshd[25809]: error: Bind to port 10086 on 0.0.0.0 failed: Permission denied.
1月 14 22:41:21 li1456-21 sshd[25809]: error: Bind to port 10086 on :: failed: Permission denied.
1月 14 22:41:21 li1456-21 sshd[25809]: fatal: Cannot bind any address.
1月 14 22:41:21 li1456-21 systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a
1月 14 22:41:21 li1456-21 systemd[1]: Failed to start OpenSSH server daemon.
-- Subject: Unit sshd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit sshd.service has failed.
-- 
-- The result is failed.
1月 14 22:41:21 li1456-21 systemd[1]: Unit sshd.service entered failed state.
1月 14 22:41:21 li1456-21 systemd[1]: sshd.service failed.
1月 14 22:41:21 li1456-21 polkitd[20483]: Unregistered Authentication Agent for unix-process:25803:116458458 (system bus name :1.5311, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale e

[1]  + 25817 suspended  journalctl -xe
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
yum provides semanage
policycoreutils-python-2.5-29.el7.x86_64 : SELinux policy core python utilities
Repo        : base
Matched from:
Filename    : /usr/sbin/semanage

vi /etc/ssh/sshd_config
#Port	22
Port	10086

yum -y install policycoreutils-python.x86_64
semanage port -l |grep ssh
semanage port -a -t ssh_port_t -p tcp 10086
#semanage port -a -t postgresql_port_t -p tcp 5432
firewall-cmd --zone=public --add-port=10086/tcp --permanent
firewall-cmd --reload

curl

1
2
3
4
# 忽略证书
curl --insecure https://192.168.33.100:8443
curl -k https://192.168.33.100:8443
wget --no-check-certificate https://192.168.33.100:8443

cat

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
touch /tmp/hell.sh
cat > /tmp/hell.sh <<EOF
echo "hello";
EOF
chmod +x /tmp/hell.sh
/tmp/hell.sh

touch /tmp/test.txt
tee /tmp/test.txt <<EOF
hehe,helloworld
EOF
cat /tmp/test.txt

tee -a /tmp/test.txt <<EOF
helloworld2
EOF
cat /tmp/test.txt

其他

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# 物理cpu个数
# cpu_num=`cat /proc/cpuinfo | grep 'physical id'|sort|uniq|wc -l`
cpu_num=`cat /proc/cpuinfo|grep 'processor'|sort|uniq|wc -l`
echo "cpu num:$cpu_num"

memory_total=`free -h |grep 'Mem'|awk '{print $2}'`
memory_free=`free -m|grep 'Mem'|awk '{print $4}'`
echo  "memory total:${memory_total}"
echo  "memory free:${memory_free}M"

disk_size=`df -h / | awk '{print $2}'|grep -E '[0-9]'`
echo "disk size:$disk_size"

linux_bit=`uname -i`
if (($linux_bit=='x86_64'));then
    system_bit=64
else
    system_bit=32
fi
echo "system bit:$system_bit"

process=`ps aux|wc -l`
let process--#实际运行进程数
echo "process:$process"

# 已安装软件包数量
software_num=`dpkg -l |wc -l`
#software_num=`yum list installed |wc -l`
echo "software num:$software_num"

# ip的获取
ip=`ifconfig| grep -A 1 'eth0'|grep 'inet'|awk -F ':' '{print $2}'|awk '{print $1}'`
echo "ip:$ip" 
ip4=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
ip6=$(/sbin/ip -o -6 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
ip addr show |grep "inet " |grep -v 127.0.0. |head -1|cut -d" " -f6|cut -d/ -f1
hostname -I
ip route get 8.8.8.8 | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}'
ip route | grep src | sed -n '/src/{s/.*src *\([^ ]*\).*/\1/p;q}'