相關代碼javascript
curl -o /dev/null -s -w "%{http_code}" baidu.com -k/--insecure 容許不使用證書到SSL站點 -H/--header 自定義頭信息傳遞給服務器 -I/--head 只顯示請求頭信息 -w/--write-out [format] 什麼輸出完成後 -s/--silent 靜默模式。不輸出任何東西 -o/--output 把輸出寫到該文件中
參考: http://blog.csdn.net/Hello_Hwc/article/details/40017833php
. 匹配任何單個字符 * 前面出現0個或者多個 ^ 以..開始 $ 以..結束
china : 匹配此行中任意位置有china字符的行 ^china : 匹配此以china開關的行 china$ : 匹配以china結尾的行 ^china$ : 匹配僅有china五個字符的行 [Cc]hina : 匹配含有China或china的行 Ch.na : 匹配包含Ch兩字母而且其後緊跟一個任意字符以後又有na兩個字符的行 Ch.*na : 匹配一行中含Ch字符,而且其後跟0個或者多個字符,再繼續跟na兩字符
? : 匹配前面正則表達式的零個或一個擴展 + : 匹配前面正則表達式的一個或多個擴展 {n,m}: 前面出現1個或2個或3個 | : 匹配|符號前或後的正則表達式 ( ) : 匹配方括號括起來的正則表達式羣
-n, --line-number -i, --ignore-case 不區分大小寫 -r, --recursive 按照目錄 -o, --only-matching 只顯示匹配行中匹配正則表達式的那部分 -v, --invert-match 排除 -c, --count 統計url出現次數 grep -nr grep -oP
192.168.100.100 ifconfig|grep -oP "([0-9]{1,3}\.){3}[0-9]{1,3}"
cat >>tmp.txt<<EOF iher-_@qq.com hello EOF cat tmp.txt|grep -oP "[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z]+)+"
$ cat >file.txt<<EOF wtmp begins Mon Feb 24 14:26:08 2014 192.168.0.1 162.12.0.123 "123" 123""123 njuhwc@163.com njuhwc@gmil.com 123 www.baidu.com tieba.baidu.com www.google.com www.baidu.com/search/index EOF grep -cn ".*baidu.com.*" file.txt 3
yum install bash-com* -y 我在dokcer命令tab能夠補全了
參考: https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/configmap.mdcss
log-format-upstream: '{ "time": "$time_iso8601", "remote_addr": "$proxy_protocol_addr", "x-forward-for": "$proxy_add_x_forwarded_for", "request_id": "$request_id", "remote_user": "$remote_user", "bytes_sent": $bytes_sent, "request_time": $request_time, "status": $status, "vhost": "$host", "request_proto": "$server_protocol", "path": "$uri", "request_query": "$args", "request_length": $request_length, "duration": $request_time, "method": "$request_method", "http_referrer": "$http_referer", "http_user_agent": "$http_user_agent" }'
nohup /bin/su - elk -c "/usr/local/elasticsearch/bin/elasticsearch" > /data/es/es-start.log 2>&1 & nohup /bin/su - elk -c "/usr/local/kibana/bin/kibana" > /data/es/kibana-start.log 2>&1 & nohup "/usr/local/logstash/bin/logstash -f /data/es/conf/logstash/logstash.conf" > /data/es/logstash-start.log 2>&1 & - logstash /data/home/user00/logstash/bin/logstash -f /data/home/user00/logstash/conf/index.conf -l /data/home/user00/logstash/logs/logstash.log & /usr/local/logstash/bin/logstash -f logstash.yaml --config.reload.automatic curl -XDELETE http://192.168.100.204:9200/.monitoring-kibana-6-2017.10.23 健康: http://192.168.100.204:9200/_cat/health?v 節點: http://192.168.100.204:9200/_cat/nodes?v 查看index: http://192.168.100.204:9200/_cat/indices?v
vim /etc/udev/rules.d/70-persistent-net.rules vim /etc/sysconfig/network-scripts/ifcfg-eth0
yum install -y sshfs 掛載 sshfs -o allow_other,transform_symlinks root@192.168.14.133:/data /data 卸載 fusermount -u /data
參考: https://www.91yun.co/archives/8731html
我在logging模塊裏看到的這個註釋 #--------------------------------------------------------------------------- # Configuration classes and functions #---------------------------------------------------------------------------
原由是有人問怎麼把函數全局化,不用import便可隨處調用 os.getcwd() #當前py所在目錄 b.__file__ #這個模塊的路徑 os.__module__ #這個函數在哪一個模塊
參考:http://blog.csdn.net/l_b_yuan/article/details/52260646vue
os.path.abspath(path) #返回絕對路徑 os.path.split(path #將path分割成目錄和文件名二元組返回 os.path.dirname(path) #返回path的目錄。其實就是os.path.split(path)的第一個元素 os.path.basename(path) #返回path最後的文件名 os.path.exists(path) #若是path存在,返回True;若是path不存在,返回False os.path.isabs(path) #若是path是絕對路徑,返回True os.path.isfile(path) #若是path是一個存在的文件,返回True。不然返回False os.path.isdir(path) #若是path是一個存在的目錄,則返回True。不然返回False os.path.getatime(path) #返回path所指向的文件或者目錄的最後存取時間 os.path.getmtime(path) #返回path所指向的文件或者目錄的最後修改時間 s.path.join(path1[, path2[, ...]]) #將多個路徑組合後返回,第一個絕對路徑以前的參數將被忽略。 >>> os.path.join('c:\\', 'csv', 'test.csv') 'c:\\csv\\test.csv' >>> os.path.join('windows\temp', 'c:\\', 'csv', 'test.csv') 'c:\\csv\\test.csv' >>> os.path.join('/home/aa','/home/aa/bb','/home/aa/bb/c') '/home/aa/bb/c'
pip install virtualenv pip install virtualenvwrapper pip install virtualenvwrapper-win mkvirtualenv --python==C:\Python27\python.exe py27env exit mkvirtualenv --python==C:\Python34\python.exe py34env workon { "workbench.colorTheme": "Solarized Light", "window.zoomLevel": 1, "window.menuBarVisibility": "default", "editor.wordWrap": "on", "editor.fontSize": 16, "files.autoSave": "afterDelay", "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe", "editor.rulers": [80,120] }
• ~/.bash_profile:用戶每次登陸時執行 • ~/.bashrc:每次進入新的Bash環境時執行 • ~/.bash_logout:用戶每次退出登陸時執行
yum install sendmail -y cat >>/etc/mail.rc<<EOF set from=xxx@tt.com set smtp=smtp.exmail.qq.com set smtp-auth-user=xxx@tt.com set smtp-auth-password=123456 set smtp-auth=login EOF source /etc/mail.rc
echo "test"| mail -s "郵件標題" iher@foxmail.com
mail -s "郵件標題" iher@foxmail.com < /etc/passwd
mail -s "郵件標題" -a /var/log/messages iher@Foxmail.com < /etc/passwd
C6 postfix /var/spool/postfix/maildrop C5 sedmail /var/spool/clientmqueue
注: centos6.5已經不自動安裝sendmail了因此不必走這一步優化java
mkdir -p /server/scripts cat /root/shell/spool_clean.sh #!/bin/sh find/var/spool/clientmqueue/-type f -mtime +30|xargs rm-f
echo '*/30 * * * * /bin/sh /server/scripts/spool_clean.sh >/dev/null 2>&1'>>/var/spool/cron/root
# locale -a
locale #調取了/etc/sysconfig/i18n
export LANG='zh_CN.UTF-8'
yum install sysstat sar -n DEV 1 5 #1s監控1次,共監控5次. sar -n DEV (-n network)
watch more /proc/net/dev
find . -mtime +10 -exec rm -rf {} \; find . -mtime +10|xargs rm -f
$ nc -vuz 192.168.6.6 53 Connection to 192.168.6.6 53 port [udp/domain] succeeded!
實際使用時能夠只用-u參數,-u表明udp協議 ,-v表明詳細模式,-z表明只監測端口不發送數據。node
nc -l -u 8021 --server #能夠配置tcpdump -i eth0 port 8021 -nnv抓包 nc -u 192.168.6.52 8021 --client #交互式發送消息
server: nc -l -u 8021 client: nc -u 192.168.6.52 8021 < /etc/hosts
server: tar -cf - /home/database | nc -l 5677 #將/home/database文件 client: nc 192.168.6.52 5677 | tar -xf - #傳到client的當前目錄
openssl rand -hex 8
$mkpasswd -l 16 -s 2 3Hte^bd-pkylSbf7
echo "ansible"|passwd --stdin ansible #centos7改用戶密碼
cat /etc/fstab 需掛載的設備 掛載點 fs類型 參數 備份 檢查 /dev/mapper/centos-data /data xfs defaults 0 0
192.168.8.68:/data/backup/no75/confluence/data /data/confluence/ nfs defaults 0 0
/usr/bin/mount -t nfs 192.168.8.68:/data/owncloud /data/owncloud-192.168.8.68
/data/backup/no75/confluence/data 192.168.8.0/24(rw,sync,no_root_squash)
Filesystem Size Used Avail Use% Mounted on /dev/sda1 32G 1.3G 29G 5% / tmpfs 16G 16G 0 100% /dev/shm mount -o remount,size=18G /dev/shm
Mount the file system and make it writeable mount -uw / Make the filesystem read only again. mount -ur /
date +%Y-%m-%d~%H-%M-%S -d "-1 day"
date "+%Y-%m-%d %H-%M-%S" -d "-1 day"
tar zcvf etc_$(date +%F -d "-1 day").tar.gz /etc/
rm -rf /etc/localtime && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && ntpdate ntp1.aliyun.com
/user/sbin/ntpdate ntp1.aliyun.com echo '*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2 >&1' >>/var/spool/cron/root
date -s "2016/06/11 22:50"
ifconfig eth0|grep -oP "([0-9]{1,3}\.){3}[0-9]{1,3}"|sed -n '1p' ifconfig|sed -n '2p'|sed -r 's#^.*addr:(.*) Bcast.*$#\1#g' ifconfig|sed -n '2p'|awk -F':' '{print $2}'|awk '{print $1}'
echo "stty erase ^H" >>/root/.bash_profile source /root/.bash_profile
How to install dig, host, and nslookup – bind-utils on CentOS:python
yum install bind-utils -y [c6使用nslookup] yum install net-tools -y [c7使用ifconfig]
setenforce 0 sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config getenforce /etc/init.d/iptables stop
ulimit -SHn 65535 echo '* - nofile 65536' >>/etc/security/limits.conf echo "* soft nproc 65535" >>/etc/security/limits.conf echo "* hard nproc 65535" >>/etc/security/limits.conf echo "* soft nofile 65535" >>/etc/security/limits.conf echo "* hard nofile 65535" >>/etc/security/limits.conf
> /etc/issuse >/etc/redhat-release
$ useradd sunsky $ echo "123456"|passwd --stdin sunsky&&history –c $ visudo # 99gg 在root ALL=(ALL) ALL #此行下,添加以下內容 sunsky ALL=(ALL) ALL lanny ALL=(ALL) ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom #僅容許他執行這些命令
\cp /etc/ssh/sshd_config /etc/ssh/sshd_config.ori sed -i 's#\#UseDNS yes#UseDNS no#g' /etc/ssh/sshd_config sed -i 's#GSSAPIAuthentication yes#GSSAPIAuthentication no#g' /etc/ssh/sshd_config /etc/init.d/sshd restart Port 22345 PermitRootLogin no PermitEmptyPasswords no UseDNS no ListenAddress 192.168.138.24 GSSAPIAuthentication no
export TMOUT=10 echo "export TMOUT=10" >>/etc/profile source /etc/profile
yum -y install vim-enhanced cat >>/etc/vimrc<<a set nu set cursorline set nobackup set ruler set autoindent set vb t_vb= set ts=4 set expandtab a . /etc/vimrc
cat /usr/local/rsync/rsync.conf uid = root gid = root use chroot = no max connections = 10 strict modes = yes pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log [web] path = /code/pp100web/target/ROOT comment = web file ignore errors read only = no write only = no hosts allow = 192.168.14.132 list = false uid = root gid = root auth users = webuser secrets file = /usr/local/rsync/rsync.passwd
kill -HUP `cat /var/run/rsyncd.pid` /usr/bin/rsync --daemon --config=/usr/local/rsync/rsync.conf ps -ef|grep rsync
vim /usr/local/rsync/rsync.conf hosts allow = 192.168.14.132,192.168.14.133
注意:密碼文件統一600,且普通用戶爲誰,屬主即爲誰.mysql
export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar export TOMCAT_HOME=/usr/local/tomcat export CATALINA_BASE="/data/tomcat" export PATH=/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.7.0_45/bin:/root/bin:/usr/local/jdk1.7.0_45/bin:/root/bin
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo yum clean all yum makecache yum install lrzsz ntpdate sysstat dos2unix wget telnet tree -y
crontab -l */5 * * * * /usr/sbin/ntpdate times.windows.com >/dev/null 2>&1
stty erase "^H" #追加到/etc/profile
export HISTTIMEFORMAT="%F %T `whoami` " echo "export HISTTIMEFORMAT="%F %T `whoami` "" >> /etc/profile
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg";}'
cat /etc/salt/master |grep -v "#" | sed '/^$/d' grep -nir -i 不區分大小寫 -n 顯示行號 -r 查找目錄, grep -r 'xx' .
/usr/bin/killall -HUP syslogd /bin/kill -USR1 $(cat /var/run/nginx.pid 2>/dev/null) 2>/dev/null || :
echo "net.ipv4.icmp_echo_ignore_all=1">>/etc/sysctl.conf tail -1 /etc/sysctl.conf sysctl -p echo 1 > /proc/sys/net/ipv4/ip_forward #這樣好處能夠tab
sysctl -w net.ipv4.ip_forward=1 #好像沒寫到/etc/sysctl.conf裏
sed -i 'N;4addpdf' a.txt sed -i 'N;4ieepdf' a.txt sed -i 'N;4a44444444444444444444444444testt' 1.log在第四行後加一行 http://www.361way.com/sed-process-lines/2263.html
sed -i 's#^\#set bell-style none#set bell-style none#g' /etc/inputrc echo "modprobe -r pcspkr" > /etc/modprobe.d/blacklist
\cp /etc/init/control-alt-delete.conf /etc/init/control-alt-delete.conf.bak sed -i 's#exec /sbin/shutdown -r now "Control-Alt-Deletepressed"#\#exec /sbin/shutdown -r now "Control-Alt-Deletepressed"#g'
yum groupinstall base -y yum groupinstall core -y yum groupinstall development libs -y yum groupinstall development tools -y
echo -e "\033[32m crontab has been added successfully \033[0m"
yum install nfs-utils rpcbind -y
/etc/init.d/rpcbind start ps -ef |grep rpc /etc/init.d/rpcbind status rpcinfo -p localhost
echo "/data 10.0.0.0/24(rw,sync,no_root_squash)" >> /etc/exports chkconfig rpcbind on chkconfig nfs on
/etc/init.d/rpcbind start chkconfig rpcbind on showmount -e 10.1.1.10 mount -t nfs 10.1.1.10:data /mnt 寫到/etc/rc.local裏
yum install pcre pcre-devel openssl openssl-devel –y
useradd -s /sbin/nologin -M nginx
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.6.2 --with-http_stub_status_module --with-http_ssl_module make && make install echo $? ln -s /usr/local/nginx-1.6.2 /usr/local/nginx
/usr/local/sbin/nginx # -t檢查配置文件語法 /usr/local/nginx/sbin/nginx # 啓動
echo PATH=/application/nginx/sbin/:$PATH >> /etc/profile source /etc/profile netstat -ntulp |grep nginx lsof -i:80 curl 192.168.14.151 nginx -s stop nginx -s reload
worker_processes auto; events { multi_accept on; use epoll; worker_connections 51200; } error_log stderr notice; worker_rlimit_nofile 65535; http { include mime.types; default_type application/octet-stream; server_info off; server_tag off; server_tokens off; server_name_in_redirect off; client_max_body_size 20m; client_header_buffer_size 16k; large_client_header_buffers 4 16k; sendfile on; tcp_nopush on; keepalive_timeout 65; server_tokens on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_proxied any; gzip_http_version 1.1; gzip_comp_level 3; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; upstream owncloud { server 127.0.0.1:8000; } upstream confluence { server 127.0.0.1:8090; } server { listen 80; server_name owncloud.maotai.org; location / { proxy_next_upstream error timeout invalid_header http_500 http_503 http_404 http_502 http_504; proxy_pass http://owncloud; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 80; server_name confluence.maotai.org; location / { proxy_next_upstream error timeout invalid_header http_500 http_503 http_404 http_502 http_504; proxy_pass http://confluence; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 80; server_name status-no189.maotai.org; location /nginx_status { stub_status on; access_log off; } } }
參考: https://linux.cn/article-4126-1.htmllinux
head -c 10M < /dev/urandom > /var/log/log-file # 生成隨機字符串 cat /dev/urandom |tr -dc [:alnum:] |head -c 8
天天3點才切割問題: 參考: http://www.voidcn.com/article/p-tpivuevp-gn.html
cat > /etc/logrotate.d/nginx /usr/local/nginx/logs/*.log { daily missingok rotate 7 dateext compress delaycompress notifempty sharedscripts postrotate if [ -f /usr/local/nginx/logs/nginx.pid ]; then kill -USR1 `cat /usr/local/nginx/logs/nginx.pid` fi endscript }
DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.6.28 NETMASK=255.255.255.0 GATEWAY=192.168.6.1
export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$"
export PS1="[\u@\h \W]\$"
yum install -y httpd php php-cli php-common php-pdo php-gd yum install -y httpd php php-cli php-common php-pdo php-gd mysql mysql-server php-mysql yum install -y httpd php php-ldap php-gd
vim /etc/php.ini 729 post_max_size = 16M 946 date.timezone = PRC #(中華人民共和國)
cat adduser.sh #!/bin/bash # Add system user for ldap in {1..5};do if id user${ldap} &> /dev/null;then echo "System account already exists" else adduser user${ldap} echo user${ldap} | passwd --stdin user${ldap} &> /dev/null echo "user${ldap} system add finish" fi done # chmod +x adduser.sh # ./adduser.sh # id user1 uid=502(user1) gid=502(user1) groups=502(user1)
useradd test -u 6000 -g 6000 -s /sbin/nologin -M -d /dev/null
[root@node1 ~]# cat test.sh #!/bin/sh for i in "$*";do echo $i done [root@node1 ~]# sh test.sh 1 2 3 4 1 2 3 4 [root@node1 ~]# cat test.sh #!/bin/sh for i in "$@";do echo $i done [root@node1 ~]# sh test.sh 1 2 3 4 5 1 2 3 4 5
使用小括號爲數組賦值
a=(1 2 3)
注意: 默認空格隔開
$ b=(bbs www http ftp) $ echo ${b[*]} bbs www http ftp
$ echo ${b[0]};echo '*******';echo ${b[2]} bbs ******* http
注: 記住是小括號,不是大括號
name=( alice bob cristin danny ) for i in "${!name[@]}";do echo ${name[$i]} done
length=${#array_name[@]}
length=${#array_name[*]}
lengthn=${#array_name[n]}
優化小結:
一清: 定時清理日誌/var/spool/clientsqueue
一精: 精簡開機啓動服務
一增: 增大文件描述符
兩優: linux內核參數的優化、yum源優化
四設:設置系統的字符集、設置ssh登陸限制、設置開機的提示信息與內核信息、設置block的大小
七其餘:文件系統優化、sync數據同步寫入磁盤、不更新時間戳、鎖定系統關鍵文件、時間同步、sudo集權管理、關閉防火牆和selinux
centos一鍵優化腳本:
\cp /etc/sysctl.conf /etc/sysctl.conf.$(date +%F) cat >>/etc/sysctl.conf<<EOF net.ipv4.tcp_fin_timeout = 2 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_keepalive_time = 600 net.ipv4.ip_local_port_range = 4000 65000 net.ipv4.tcp_max_syn_backlog = 16384 net.ipv4.tcp_max_tw_buckets = 36000 net.ipv4.route.gc_timeout = 100 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_synack_retries = 1 net.core.somaxconn = 16384 net.core.netdev_max_backlog = 16384 net.ipv4.tcp_max_orphans = 16384 net.netfilter.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_tcp_timeout_established = 180 net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60 net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120 EOF sysctl -p
注: 如下參數是對centos6.x的iptables防火牆的優化,防火牆不開會有提示,能夠忽略不理。
若是是centos5.X須要吧netfilter.nf_conntrack替換成ipv4.netfilter.ip
centos5.X爲net.ipv4.ip_conntrack_max = 25000000
net.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_tcp_timeout_established = 180 net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60 net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
CentOS6 內核更換爲: 2.6.32-504.3.3.el6.x86_64
rpm -ivh http://soft.91yun.org/ISO/Linux/CentOS/kernel/kernel-firmware-2.6.32-504.3.3.el6.noarch.rpm rpm -ivh http://soft.91yun.org/ISO/Linux/CentOS/kernel/kernel-2.6.32-504.3.3.el6.x86_64.rpm --force
CentOS7 內核更換爲: 3.10.0-229.1.2.el7.x86_64
rpm -ivh http://soft.91yun.org/ISO/Linux/CentOS/kernel/kernel-3.10.0-229.1.2.el7.x86_64.rpm --force
reboot uname -r rpm -qa | grep kernel 百度: site:centos.org 你須要的內核 site:centos.org kernel-2.6.32-504.3.3.el6.x86_64.rpm