相关代码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