centos7常用命令
内核参数修改
显示当前系统可用的内核参数
> sysctl -a
abi.vsyscall32 = 1
crypto.fips_enabled = 0
debug.exception-trace = 1
debug.kprobes-optimization = 1
debug.panic_on_rcu_stall = 0
dev.hpet.max-user-freq = 64
dev.mac_hid.mouse_button2_keycode = 97
dev.mac_hid.mouse_button3_keycode = 100
dev.mac_hid.mouse_button_emulation = 0
...
Linux修改内核参数有三种方式:
- 修改 /etc/sysctl.conf 文件,加入配置选项,格式为 key = value ,修改保存后调用 sysctl -p 加载新配置(此种方式在系统重新启动时不会丢失)
- 使用sysctl命令临时修改,例如 sysctl -w kernel.hostname=**** 修改主机名
- 修改/proc/sys目录中的文件,如: echo “379008 505344 758016” > /proc/sys/net/ipv4/tcp_mem
注:第二三种方式会使机器在重启之后就失效
redis内核参数调优
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
vm.swappiness = 0
net.ipv4.neigh.default.gc_stale_time=120
# see details in https://help.aliyun.com/knowledge_detail/39428.html
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_announce=2
# see details in https://help.aliyun.com/knowledge_detail/41334.html
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_mem = 185340 988480 1482720
#net.ipv4.tcp_mem = 185340 247120 370680
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.core.somaxconn = 8000
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 1048576
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.ip_local_port_range = 10240 61000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_synack_retries = 1
fs.file-max = 1048576
#net.netfilter.nf_conntrack_generic_timeout = 600
#net.netfilter.nf_conntrack_max = 1048576
#net.netfilter.nf_conntrack_generic_timeout = 10
kernel.sysrq=1
vm.overcommit_memory = 1
查看Java进程所在目录
查看进程
> jps -lv
> 851 com.aliyun.tianji.cloudmonitor.Application -Djava.compiler=none -XX:-UseGCOverheadLimit -XX:NewRatio=1 -XX:SurvivorRatio=8 -XX:+UseSerialGC -Djava.io.tmpdir=../../tmp -Xms16m -Xmx32m -Djava.library.path=../lib:../../lib -Dwrapper.key=tf9w0goQx2NBh7VR -Dwrapper.port=32000 -Dwrapper.jvm.port.min=31000 -Dwrapper.jvm.port.max=31999 -Dwrapper.disable_console_input=TRUE -Dwrapper.pid=849 -Dwrapper.version=3.5.27 -Dwrapper.native_library=wrapper -Dwrapper.arch=x86 -Dwrapper.service=TRUE -Dwrapper.cpu.timeout=10 -Dwrapper.jvmid=1
进入/proc目录查找进程851
> cd /proc/851
> ll cwd
/dev/null与2>&1讲解
首先先来看下几种标识的含义:
-
/dev/null 表示空设备文件。意思是把输出重定向到设备/dev/null上。
/dev/null 是类Unix系统中的一个特殊文件设备,他的作用是接受一切输入它的数据并丢弃这些数据。通常被当做垃圾桶来用。将输出流重定向到它上面,就是丢弃这个输出流上的所有输出。
-
0 表示stdin标准输入
-
1 表示stdout标准输出
-
2 表示stderr标准错误
先看/dev/null
command > /dev/null相当于执行了command 1 > /dev/null。执行command产生了标准输出stdout(用1表示),重定向到/dev/null的设备文件中
/dev/null可以理解为/dev路径下的空文件;该命令将command命令的标准输出输出到空文件中;
再看 1>test.log
执行./test.sh > res1.log 或 ./test.sh 1> res1.log结果为
我们发现stdout被重定向到了res1.log中,stderr并没有被重定向到res1.log中,stderr被打印到了屏幕上。
2>test.log
执行./test.sh 2> res3.log结果为
我们发现stderr被重定向到了res3.log中
2>&1
command>a 2>&1 可以理解为执行command产生的标准输出重定向到文件a中,标准错误也重定向到文件a中,期间只打开一次文件a,&1的含义就可以理解为用标准输出的引用,引用的就是重定向标准输出产生打开的a。
执行./test.sh>res2.log 2>&1结果为这次我们发现stdout和stderr都被重定向到了res2.log中了
下面是一个挂后台的样例:
nohup sh loop_dwa_m_sms_chunjie_fs_zdg.sh 20190120 >loop_dwa_m_sms_chunjie_fs_zdg.log 2>&1 &