當(dāng)前位置:
首頁 >
高性能Linux架构实战 [高俊峰] 笔记摘要
發(fā)布時(shí)間:2024/1/1
36
豆豆
生活随笔
收集整理的這篇文章主要介紹了
高性能Linux架构实战 [高俊峰] 笔记摘要
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一 Linux服務(wù)器安全與運(yùn)維1.賬戶和登錄安全可刪除的默認(rèn)無用用戶:adm lp sync shutdown halt news uucp operator games gopher可刪除的默認(rèn)無用組:adm lp uucp games dip pppusers popusers slipusers關(guān)閉不需要的服務(wù):anacron auditd autofs avahi-daemon avahi-dnsconfd bluetooth cupspeed firstboot gpm haldaemon hidd ip6tables ipsec isdn lpd mcstrans messagebus netfs nfs nfslock nscd pcscd portmap readahead_early restorecond rpcgssd rpcidmapd rstatd sendmail setroubleshoot yppasswdd ypserv.[chkconfig --level 345 anacron off]將SSH客戶端生成的密鑰放置服務(wù)端 啟用Publickey認(rèn)證mkdir /home/test/.sshchmod 700 /home/test/.sshssh-keygen -i -f test.pub >> /root/.ssh/authorized_key2vim /etc/ssh/sshd_configProtocol 2? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#僅使用SSH2認(rèn)證PubkeyAuthentication yes? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #啟用PublicKey認(rèn)證AuthorizedKeysFile .ssh/authorized_key2? ? ? ? #PublicKey文件路徑PasswordAuthentication no? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#不使用口令認(rèn)證/etc/rc.d/init.d/sshd restart開放普通用戶單文件特權(quán)? ?(使用sudo 訪問無權(quán)限的文件 輸入密碼后獲得5分鐘的訪問券)vim /etc/sudoerstest01 ALL = /bin/more /etc/shadow#無需密碼的方式test01 ALL = NOPASSWD: /etc/init.d/nagios restart?#普通用戶提權(quán)為超級(jí)用戶并不需要密碼test01 ALL=(ALL) NOPASSWD: ALL系統(tǒng)登錄歡迎信息/etc/issue /etc/issue.net /etc/redhat-release /etc/motdvim /etc/ssh/sshd_config?Banner /etc/issue.net禁止Ctrl+Alt+Del 關(guān)機(jī)centos5.xvim /etc/inittabca::ctrlaltdel:/sbin/shutdown -t3 -r now? ? ? ? ? ?#將此行注釋telinit qcentos6.xvim /init/control-alt-delete.confexec /sbin/shutdown -r now "Control-Alt-Delete pressed"? ?#注釋此行禁止telnet方式認(rèn)證登錄vim /etc/ssh/sshd_config修改shell歷史記錄長度vim /etc/bashrcHISTFILESIZE=10000HISTSIZE=10000HISTTIMEFORMAT='%F %T'export HISTTIMEFORMAT
/etc/profile#historyUSER_IP= `who -u am i 2>/dev/null |awk '{print $NF}'|sed -e 's/[()]//g'`HISTDIR=/usr/share/.historyif [ -z $USER_IP]thenUSER_IP=`hostname`fi
if [ ! -d $HISTDIR ]thenmkdir -p $HISTDIRchmod 777 $HISTDIRfi
if [ ! -d $HISTDIR/${LOGNAME} ]then?mkdir -p $HISTDIR/${LOGNAME}chmod 300 $HISTDIR/${LOGNAME}fiexport HISTSIZE=10000DT=`date +%Y%m%d_%H%M%s`export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.history.$DY"export HISTTIMEFORMAT="{%Y.%m.%d %H:%M:%S}"chmod 600 $HISTDIR/${LOGNAME}/*.history* 2>/dev/null-------------------------------------------------------------文件權(quán)限檢查任何用戶都有寫權(quán)限find / -type f -perm -2 -o -perm -20 |xargs ls -alfind / -type d -perm -2 -o -perm -20 |xargs ls -al含有s位的程序find / -type f -perm -4000 -o -perm -2000 -print |xargs ls -al查詢含有suid和sgid文件find / -user root -perm -2000 -print -exec md5sum {} \;find / -user root -perm -4000 -print -exec md5sum {} \;查詢沒有屬主的文件find / -nouser -o nogroup?/tmp單獨(dú)分區(qū)時(shí)安全的掛載方式LABEL=/tmp? ? /tmp? ? ext4? ? rw,nosuid,noexec,nodev? ? 0 0/tmp是目錄的安全掛載方式 [啟動(dòng)loopback文件系統(tǒng)]dd if=/dev/zero of=/dev/tmpfs bs=1M count=10000mke2fs -j /dev/tmpfscp -av /tmp /tmp.oldmount -o loop,noexec,nosuid,rw /dev/tmpfs /tmpchmod 1777 /tmpmv -f /tmp.old/* /tmprm -rf /tmp.oldvim /etc/fstab?/dev/tmpfs /tmp ext4 loop,nosuid,noexec,rw 0 0/dev/shm 安全掛載方式vim /etc/fstabtmpfs /dev/shm tmpfs defaults,nosuid,noexec,rw 0 0
文件級(jí)rootkit檢查文件完整性:Tripwire aide后門檢測(cè)工具 chkrootkit避免chkrootkit依賴的工具被污染提前備份一份完整所需工具至指定目錄mkdir /usr/share/.commandscp `which --skip-alias awk cut echo find egrep id head ls netstat ps strings sed uname` /user/share/.commands?chkrootkit -p /usr/share/.commands/檢測(cè)工具2 RKHunter? ? ? ? ? ??#./installer.sh --layout default --installrkhunter -crkhunter --check --skip-keypress? ? ?#靜默檢查09 3 *** root rkhunter --check --cronjobpidof?2.網(wǎng)絡(luò)安全運(yùn)維Ntop:嗅探網(wǎng)絡(luò)數(shù)據(jù)包類型,分析區(qū)分?jǐn)?shù)據(jù)流量Ntopng?iperf:網(wǎng)絡(luò)性能評(píng)估工具iperf3 -c 192.168.12.168iperf3 -c 192.168.12.168 -t 20 -i 5iperf3 -c 192.168.12.168 -i 10 -n 5000000000? #每隔十秒發(fā)送5G的數(shù)據(jù)iperf3 -c 192.168.12.168 -F test.tar.gz -i 5 -t 20 -f Miperf3 -c 192.168.12.168 -u -b 100M -f M -i 3nmap:網(wǎng)絡(luò)發(fā)現(xiàn)工具nmap 39.106.125.107nmap -T4 -A -v?39.106.125.107nmap -sn -PE -PS22,80 -PU53 www.baidu.comPE:發(fā)送ICMP echo 報(bào)文? ? ?PS:發(fā)送TCP SYN/ACK的形式偵探主機(jī)? ? PU:以UDP形式偵探nmap -sU -sS -F www.myblogsite.top? ?nmap -O --osscan-guess 192.168.3.1-2543.數(shù)據(jù)安全DRDByum -y install kmod-drbd83 drbd83modprobe drbdlsmod|grep -i drbdmodprobe -l|grep -i drbddd創(chuàng)建空數(shù)據(jù): dd if=/dev/zero of=/mnt/testblack.tmp bs=10M count=20數(shù)據(jù)恢復(fù)extundelete:? Linux常用恢復(fù)工具:debugfs R-Liunx ext3grep extundelete等.extundelete與ext3grep比較常用,兩款工具原理較為相似.前者功能更強(qiáng)大.通過分析文件系統(tǒng)的日志,解析出所有文件的indoe信息,從而可以恢復(fù)Linux下主流的ext3 ext4文件系統(tǒng)下被誤刪除的文件.而ext3grep僅支持ext3文件系統(tǒng),此外在恢復(fù)速度上前者要更快,是通過掃描inode和數(shù)據(jù)恢復(fù)同時(shí)進(jìn)行,且支持單文件 單目錄 inode恢復(fù) block恢復(fù)與完整磁盤恢復(fù).而ext3grep略顯笨拙需要掃描所有inode信息然后開始恢復(fù)數(shù)據(jù),速度上相對(duì)比較慢且不支持目錄 時(shí)間恢復(fù)等.前置安裝e2fsprogs與e2fsprogs-libs1.誤操作刪除需要立即將分區(qū)卸載.2.extundelete /dev/sdc1 --inode 23.extundelete /dev/sdc1 --restore-file passwd? ?#單文件恢復(fù)4.extundelete /dev/sdc1 --restore-directory /ganglia-3.4.0? #單目錄恢復(fù)5.extundelete /dev/sdc1 --restore-all? #全部文件恢復(fù)6.extundelete --after 1379146740 --restore-all /dev/sdc1? #恢復(fù)一小時(shí)內(nèi)文件? ?當(dāng)前 date +%s-36004.Linux系統(tǒng)運(yùn)維故障排查思路Linux系統(tǒng)常見無法啟動(dòng)a.文件系統(tǒng)受損 [ext3 ext4文件系統(tǒng)都是具備日志記錄功能的日志文件系統(tǒng),并且可以進(jìn)行簡(jiǎn)單的容錯(cuò)與糾錯(cuò).日志文件系統(tǒng)并不是將數(shù)據(jù)實(shí)時(shí)寫入到磁盤,而是定期批量寫入,但文件系統(tǒng)的所有讀寫操作都會(huì)實(shí)時(shí)記錄到日志文件中,當(dāng)系統(tǒng)發(fā)生掉電等錯(cuò)誤導(dǎo)致數(shù)據(jù)沒有寫入磁盤時(shí)可以通過日志文件的記錄回滾發(fā)生故障的讀寫操作,從而保證數(shù)據(jù)和文件系統(tǒng)的一致性,但是由于實(shí)際環(huán)境復(fù)雜多樣導(dǎo)致文件系統(tǒng)不能每一次都可以成功自我修復(fù),這是就需要運(yùn)維人員手動(dòng)介入修復(fù).]掉電開機(jī)提示:? /dev/sda6 contains a file system with errors,check forced/dev/sda6:UNEXPECTED INCONSISTENCY;RUN fsck MANUALLY(or type Control-D to continue):give root password for maintenance輸入root密碼后進(jìn)入修復(fù)模式,使用fsck命令修復(fù).fsck.ext3 -y /dev/sda6? ? ? ? ? [無法恢復(fù)的數(shù)據(jù)會(huì)存放在文件系統(tǒng)lost+found目錄中]? ? (fsck -A -y)若忘記root密碼centos6.x1.引導(dǎo)參數(shù)中增加? init=/bin/bash 載入系統(tǒng).2.mount -o remount,rw /? ? ? ? ? ? ?#重掛根3.passwd? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#修改密碼4.重啟輸入root密碼繼續(xù)修復(fù).centos7.x1.引導(dǎo)參數(shù)中增加??rd.break console=tty0? 載入系統(tǒng)2.mount remount,rw /sysroot? ? ? ? #重掛根3.chroot /sysroot? ? ? ? ? ? ? ? ? ? ? ? ? ? #切換根4.passwd? ? ? ? ??5.touch /.autorelabel? ? ? ? ? ? ? ? ? ? ? ? ??6.exit7.rebootb.系統(tǒng)文件配置不當(dāng)或/etc/fstab文件丟失開機(jī)提示: starting system logger1.開機(jī)使用引導(dǎo)介質(zhì)進(jìn)入救援模式? [linux rescue]2.e2label 可查看每個(gè)分區(qū)對(duì)應(yīng)的掛載點(diǎn)?3.查找出原系統(tǒng)的跟分區(qū)目錄查找出對(duì)應(yīng)分區(qū) 如 /dev/sda34.創(chuàng)建一個(gè)目錄 /rescue_tmp 將原根掛載至此? ? mkdir /rescue_tmp ;mount /dev/sda3 /rescue_tmp5.vim /rescue_tmp/etc/fstab6.恢復(fù)完成后重啟系統(tǒng).c.Linux內(nèi)核丟失或崩潰d.引導(dǎo)程序出錯(cuò)e.硬件故障f.無響應(yīng)分析系統(tǒng)硬件問題: SCSI卡 主板 RAID卡 HBA卡 網(wǎng)卡 硬盤等硬件設(shè)備導(dǎo)致,通過更換硬件解決外圍硬件問題: 主要為網(wǎng)絡(luò)問題導(dǎo)致.網(wǎng)絡(luò)設(shè)備 網(wǎng)絡(luò)參數(shù)等方面查找軟件問題: 系統(tǒng)內(nèi)核bug 應(yīng)用軟件bug 驅(qū)動(dòng)程序bug等? 通過升級(jí)內(nèi)核 修復(fù)程序bug 更新驅(qū)動(dòng)程序解決系統(tǒng)設(shè)置問題: 防火墻配置 開機(jī)啟動(dòng)不正確等.iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT?iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
5.常見故障案例su 切換普通用戶時(shí)報(bào)錯(cuò).報(bào)錯(cuò)提示: su: warning: cannot change directory to /home/oracle: Permission deniedsu: /bin/bash: Permission denied?排查思路:
操作大量文件時(shí)遇到 Argument list too long? ? ?getconf ARG_MAX? 控制傳遞參數(shù)手動(dòng)分批刪除find傳遞刪除shell腳本循環(huán)刪除重新編譯linux內(nèi)核? include/liunx/binfmts.h文件 #define MAX_ARG_PAGES 32? ?將32改為64或128.重新編譯inode消耗殆盡?dumpe2fs -h /dev/sda3|grep 'Inode count'
文件刪除后空間不釋放:? 文件存放分為數(shù)據(jù)部分和指針部分,指針部分位于文件系統(tǒng)的meta-data中,將數(shù)據(jù)清除后指針從meta-data中被清除.將數(shù)據(jù)對(duì)應(yīng)的指針清除后空間隨之釋放.進(jìn)程占用不斷的寫數(shù)據(jù)導(dǎo)致
Too many open files?ulimit -n? ? ? ? ? ? ? [/etc/security/limits.conf]www soft nofile 65535www hard nofile 65535內(nèi)核文件大小限制進(jìn)程數(shù)據(jù)塊大小限制shell進(jìn)程創(chuàng)建文件大小限制可加鎖內(nèi)存大小限制常駐內(nèi)存集的大小限制打開文件句柄數(shù)限制分配堆棧的最大大小限制CPU占用時(shí)間限制用戶最大可用的進(jìn)程數(shù)shell進(jìn)程所能使用的最大虛擬內(nèi)存限制
No speace left on device:mod_rewrite:could not create rewrite_log_lock Configyration Failed??信號(hào)量占盡.? ipcs -s |grep nobody|perl -e 'while (<STDIN> { @a=split(/\s+/); print `ipcrmsem $a[1]`})'
6.輕量級(jí)運(yùn)維利器pssh pdsh mussh并行ssh運(yùn)維工具pssh? ?parallel-ssh? 支持文件并行復(fù)制/遠(yuǎn)程并行執(zhí)行命令/殺死遠(yuǎn)程主機(jī)進(jìn)程等&? 需要保證本地主機(jī)與管理服務(wù)器之間單向信任&? Python版本大于2.4&? 附帶5個(gè)主程序?ssh(pssh)? ? ? ? ? 遠(yuǎn)程主機(jī)并行運(yùn)行命令scp(pscp)? ? ? ? ? 復(fù)制文件至遠(yuǎn)程多臺(tái)主機(jī)rsync(prsync)? ? 使用rsync協(xié)議將文件從本地同步到遠(yuǎn)程多臺(tái)主機(jī)nuke(pnuke)? ? ?在遠(yuǎn)程主機(jī)并行killall某進(jìn)程slurp(pslurp)? ? ?將文件從遠(yuǎn)程主機(jī)復(fù)制到本地查看user002 003的時(shí)間pssh -H opsuser@user002.bestbook.com:9529 -P datepssh -H user003.bestbook.com?-i date批量管理列表? /etc/pssh/hosts批量下發(fā)命令獲取運(yùn)行時(shí)間?pssh -i -O "StrictHostKeyChecking=no" -h /etc/pssh/hosts "uptime"? ? ? ? -O?"StrictHostKeyChecking=no"? 讓遠(yuǎn)程主機(jī)自動(dòng)接受本地hostkey解壓文件passh -i -h /etc/pssh/hosts "tar -xzvf test.zip"連接指定端口passh -i -x "-l opsuser" "-p 9529" -h /etc/pssh/hosts -o /etc/pssh/info "uptime;name-a"? ? ? ? ? ? ? ? ? ? ? ? ??本地文件推送給批量遠(yuǎn)端pscp -h /etc/pssh/hosts /etc/ssh/ssh_config /tmppscp -h /etc/pssh/hosts -r /etc/httpd/conf /tmp??本地拉取遠(yuǎn)端文件pslurp -h /etc/pssh/hosts -L /home/opsuser/test > /home/opsuser/gmond.conf gmond1.confpslurp -h /etc/pssh/hosts -r -L /home/opsuser/test > /home/opsuser/gmond gmond1本地文件同步到遠(yuǎn)程主機(jī) prsync -h /etc/pssh/hosts -l opsuser -a -r /etc/httpd /tmp prsync -h /etc/pssh/hosts -l opsuser -az -r /var/log/httpd /tmp? ? ? ? ? ? ? ?#壓縮傳輸 殺死遠(yuǎn)端進(jìn)程 punke -h /etc/pssh/hosts httpd
分布式運(yùn)維工具pdsh? parallel distributed shell? 適用于大批量服務(wù)器配置/部署/文件復(fù)制/運(yùn)維等操作 &? 需要保證本地主機(jī)與管理服務(wù)器之間的單向信任 &? 默認(rèn)rsh方式? 支持ssh mrsh qsh mqsh krb4 xcpu 等多種rcmd模塊 &? --with-ssh? --with-dshgroups? --with-machines? --with-dshgroups &? 傳輸文件時(shí) 本地與遠(yuǎn)端都必須安裝pdcp 批量統(tǒng)計(jì)信息 pdsh -w ssh:192.168.16.[1-3]? "uname -n" pdsh -w ssh:user00[1-5] -x user003 "uptime" pdsh -w ssh:user00[10-31],/15/ "uptime" 文件批量調(diào)用 /etc/pdsh/machines pdsh -R ssh -a uptime pdsh -R ssh -g userhosts uptime pdsh -R ssh -a -X userhosts uptume 交互模式 pdsh -R ssh -w user001 文件傳輸 pdcp -R ssh -g userhosts /home/opsuser/mysqldb.tar.gz /home/opsuser pdcp -R ssh -w userhosts -r /home/opsuser/webdata /home/opsuser
多主機(jī)ssh封裝mussh? MUltihost SSH Wrapper &? 需要保證本地主機(jī)與管理服務(wù)器之間的單向信任 批量命令: mussh -h opsuser@user01 opsuser@user02 -c uptime 文件批量命令? ? ? ?/home/opsuser/myhosts mussh -H myhosts -l opsuser -c uptime 本地腳本遠(yuǎn)端執(zhí)行 mussh -o "port=22" -H myhosts -s /usr/bin/python -C "/home/opsuser/checkos.py"
7.分布式監(jiān)控 Ganglia HPC(高性能計(jì)算集群) 采集CPU 內(nèi)存 硬盤使用率 I/O負(fù)載 網(wǎng)絡(luò)流量等情況匯總到gmetad守護(hù)進(jìn)程下,使用rrdtool存儲(chǔ)數(shù)據(jù).以曲線方式展示 &? gmond: ganglia monitoring daemon 守護(hù)檢測(cè)進(jìn)程默認(rèn)監(jiān)聽8649 &? gmetad:ganglia meta daemon 數(shù)據(jù)匯聚守護(hù)進(jìn)程,將數(shù)據(jù)存儲(chǔ)至RRD引擎中 &? webfrontend:從gmetad中讀取RRD數(shù)據(jù)通過rrdtool生成圖表 gmetric -n disk_used -v 40 -t int32 -u '% test' -d 50 -s '8.8.8.8:cloud1'
8.高性能Nginx服務(wù)器 HTTP/IMAP/POP3/SMTP代理服務(wù)器 --with-http_stub_status_module? ? #開啟nginx status功能 監(jiān)控狀態(tài) --with-http_gzip_static_module? ? ?#開啟Gzip壓縮功能 select? ? ? ? ? 標(biāo)準(zhǔn)工作模式1 poll? ? ? ? ? ? ?標(biāo)準(zhǔn)工作模式2 kqueque? ? ?高效工作模式1 epoll? ? ? ? ? ?高效工作模式2 rtsig? ? ? ? ? ?? /dev/poll max_client=worker_processes * worker_connections(默認(rèn)1024)? ?#ulimit -n 65536 sendfile? on; tcp_nopush on ; tco_nodelay on; 開啟ngin運(yùn)行狀態(tài) localtion /NginxStatus { stub_status? ? ? ? ? ? ? ? ?on; access_log? ? ? ? ? ? ? ? ? logs/NginxStatus.log; auth_basic? ? ? ? ? ? ? ? ? "NginxStatus"; auth_basic_user_file? ?../htpasswd; } htpasswd -C htpassswd password 信號(hào)處理: QUIT:? 15? ?處理完當(dāng)前請(qǐng)求關(guān)閉進(jìn)程 HUP:? ? ? ? ?重載配置,關(guān)閉原由進(jìn)程開啟新進(jìn)程,不中斷請(qǐng)求 USR1:? ? ? ? Nginx日志切割 USR2:? ? ? ? 平滑升級(jí) WINCH:? ? ?從容關(guān)閉 rewrite重寫 來自www.taob.com的請(qǐng)求至www.tb.com? service { service_name? www.taob.com; rewirte ^/(.*)$? http://www.tb.com/$1?permanent;? ?#301 redirect 302 } 基于核心變量$host實(shí)現(xiàn)重定向 service { server_name? www.tb.com?www.taob.com; if ($host != 'www.tb.com') { rewirte ^/(.*)$ http://www.tb.com/$1?permanent; } } 禁止訪問特定資源 location ~* \.(txt|doc)$ { root /data/www/wwwroot; deny all; } Nginx內(nèi)置變量 $args? ? ? ? ? ? ? ? ? ? ? ?與請(qǐng)求行的參數(shù)相等 $document_root? ? ?當(dāng)前root命令指定的值 $uri? ? ? ? ? ? ? ? ? ? ? ? ? 當(dāng)前request中的URI $document_uri? ? ? ? 同等$uri $host? ? ? ? ? ? ? ? ? ? ? ?與頭部"Host"行的值一致 $limit_rate? ? ? ? ? ? ? ?限制連接速率 $request_method? ? 同等于request的method GET或POST $remote_addr? ? ? ? ? 客戶端IP $remote_port? ? ? ? ? ?客戶端端口 $remote_user? ? ? ? ? ?用戶名? ngx_http_auth_basic_module認(rèn)證 $request_filename? ? 當(dāng)前請(qǐng)求的文件的路徑名,由root或alias與URI request組合而成 $request_uri? ? ? ? ? ? ? 參數(shù)完整的初始URI $query_string? ? ? ? ? ? 與$args一致 $server_name? ? ? ? ? ? 請(qǐng)求到達(dá)的服務(wù)器名 $server_port? ? ? ? ? ? ? ?請(qǐng)求到達(dá)的端口號(hào) location ~ ^/best/ { rewirte ^/best/(.*)$ /test/$1 break; proxy_pass http://www.taob.com; }
location / { proxy_pass http://127.0.0.1:8080/; set $query $query_string; rewrite /dade /wordpress?$query?; } 可將http://www.tb.com/wp/?p=160的頁面重寫到www.tb.com/wordpress/?p=160 service { listen? ? ? ? ? ? ?80; server_name www.tb.cn? www.taob.com; if ($host != 'www.tb.cn') { rewirte ^/(.*)$ http://www.tb.cn/error.txt? bread; rewirte ^/(.*)$ http://www.tb.cn/$1?permanent; } }
nginx 編譯時(shí)注釋 auto/cc/gcc 的? CFLAGS="$CFLAGS -g" --with-cc-opt='-O3' --with-cpu-opt=CPU? [pentinm pentiumpro pentium3 pentium4 athlon opteron adm64 sparc32 sparc64 ppc64]? ? ?cat /proc/cpuinfo? |grep "model name"
TCMalloc 優(yōu)化Nginx性能? 1.安裝libunwind庫 2.安裝google-perftools 3.重新編譯nginx 添加參數(shù) --with-google_perftools_module 4.添加google-perftools線程目錄? 0777 權(quán)限 5.nginx主配置文件pid處寫入 google_perftools_profiles /tmp/tcmalloc; 6.重啟nginx 驗(yàn)證
針對(duì)nginx的內(nèi)核優(yōu)化? ?/sbin/sysctl -p net.ipv4.tcp_max_tw_buckets = 6000? ? ? ? ? ? ? ?#timewait數(shù)量? 默認(rèn)180000 net.ipv4.ip_local_port_range = 1024 65000? ? ?#允許系統(tǒng)打開的端口范圍 net.ipv4.tcp_tw_recycle = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #啟用timewait快速回收 net.ipv4.tcp_tw_reuse = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#允許TIME-WAIT sockets net.ipv4.tcp_syncookies = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#SYN等待隊(duì)列溢出時(shí)啟用cookies處理 net.core.somaxconn = 262144? ? ? ? ? ? ? ? ? ? ? ? ?#tcp并發(fā)連接 默認(rèn) 128 net.core.netdev_max_backlog?= 262144? ? ? ? ? #網(wǎng)口數(shù)據(jù)包速率比內(nèi)核處理快時(shí)允許等到的隊(duì)列大小 net.ipv4.tcp_max_orphans = 262144? ? ? ? ? ? ? ? #設(shè)定最大套接字不被關(guān)聯(lián)到任何用戶文件句柄上 net.ipv4.tcp_max_syn_backlog?= 262144? ? ? ? ? #記錄尚未收到客戶端確認(rèn)信息的連接請(qǐng)求最大值 net.ipv4.tcp_synack_retries = 1? ? ? ? ? ? ? ? ? ? ? ? ?#內(nèi)核放棄連接之前發(fā)送SYN+ACK包的數(shù)量 net.ipv4.tcp_syn_retres = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#內(nèi)核放棄建立連接前發(fā)送SYN包的數(shù)量 net.ipv4.tcp_fin_timeout = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#保持FIN-WAIT-2狀態(tài)的時(shí)間 默認(rèn)60 net.ipv4.tcp_keepalive_time = 30? ? ? ? ? ? ? ? ? ? ? #keepalive啟動(dòng)時(shí)tcp發(fā)送的頻度 默認(rèn)2
/etc/profile#historyUSER_IP= `who -u am i 2>/dev/null |awk '{print $NF}'|sed -e 's/[()]//g'`HISTDIR=/usr/share/.historyif [ -z $USER_IP]thenUSER_IP=`hostname`fi
if [ ! -d $HISTDIR ]thenmkdir -p $HISTDIRchmod 777 $HISTDIRfi
if [ ! -d $HISTDIR/${LOGNAME} ]then?mkdir -p $HISTDIR/${LOGNAME}chmod 300 $HISTDIR/${LOGNAME}fiexport HISTSIZE=10000DT=`date +%Y%m%d_%H%M%s`export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.history.$DY"export HISTTIMEFORMAT="{%Y.%m.%d %H:%M:%S}"chmod 600 $HISTDIR/${LOGNAME}/*.history* 2>/dev/null-------------------------------------------------------------文件權(quán)限檢查任何用戶都有寫權(quán)限find / -type f -perm -2 -o -perm -20 |xargs ls -alfind / -type d -perm -2 -o -perm -20 |xargs ls -al含有s位的程序find / -type f -perm -4000 -o -perm -2000 -print |xargs ls -al查詢含有suid和sgid文件find / -user root -perm -2000 -print -exec md5sum {} \;find / -user root -perm -4000 -print -exec md5sum {} \;查詢沒有屬主的文件find / -nouser -o nogroup?/tmp單獨(dú)分區(qū)時(shí)安全的掛載方式LABEL=/tmp? ? /tmp? ? ext4? ? rw,nosuid,noexec,nodev? ? 0 0/tmp是目錄的安全掛載方式 [啟動(dòng)loopback文件系統(tǒng)]dd if=/dev/zero of=/dev/tmpfs bs=1M count=10000mke2fs -j /dev/tmpfscp -av /tmp /tmp.oldmount -o loop,noexec,nosuid,rw /dev/tmpfs /tmpchmod 1777 /tmpmv -f /tmp.old/* /tmprm -rf /tmp.oldvim /etc/fstab?/dev/tmpfs /tmp ext4 loop,nosuid,noexec,rw 0 0/dev/shm 安全掛載方式vim /etc/fstabtmpfs /dev/shm tmpfs defaults,nosuid,noexec,rw 0 0
文件級(jí)rootkit檢查文件完整性:Tripwire aide后門檢測(cè)工具 chkrootkit避免chkrootkit依賴的工具被污染提前備份一份完整所需工具至指定目錄mkdir /usr/share/.commandscp `which --skip-alias awk cut echo find egrep id head ls netstat ps strings sed uname` /user/share/.commands?chkrootkit -p /usr/share/.commands/檢測(cè)工具2 RKHunter? ? ? ? ? ??#./installer.sh --layout default --installrkhunter -crkhunter --check --skip-keypress? ? ?#靜默檢查09 3 *** root rkhunter --check --cronjobpidof?2.網(wǎng)絡(luò)安全運(yùn)維Ntop:嗅探網(wǎng)絡(luò)數(shù)據(jù)包類型,分析區(qū)分?jǐn)?shù)據(jù)流量Ntopng?iperf:網(wǎng)絡(luò)性能評(píng)估工具iperf3 -c 192.168.12.168iperf3 -c 192.168.12.168 -t 20 -i 5iperf3 -c 192.168.12.168 -i 10 -n 5000000000? #每隔十秒發(fā)送5G的數(shù)據(jù)iperf3 -c 192.168.12.168 -F test.tar.gz -i 5 -t 20 -f Miperf3 -c 192.168.12.168 -u -b 100M -f M -i 3nmap:網(wǎng)絡(luò)發(fā)現(xiàn)工具nmap 39.106.125.107nmap -T4 -A -v?39.106.125.107nmap -sn -PE -PS22,80 -PU53 www.baidu.comPE:發(fā)送ICMP echo 報(bào)文? ? ?PS:發(fā)送TCP SYN/ACK的形式偵探主機(jī)? ? PU:以UDP形式偵探nmap -sU -sS -F www.myblogsite.top? ?nmap -O --osscan-guess 192.168.3.1-2543.數(shù)據(jù)安全DRDByum -y install kmod-drbd83 drbd83modprobe drbdlsmod|grep -i drbdmodprobe -l|grep -i drbddd創(chuàng)建空數(shù)據(jù): dd if=/dev/zero of=/mnt/testblack.tmp bs=10M count=20數(shù)據(jù)恢復(fù)extundelete:? Linux常用恢復(fù)工具:debugfs R-Liunx ext3grep extundelete等.extundelete與ext3grep比較常用,兩款工具原理較為相似.前者功能更強(qiáng)大.通過分析文件系統(tǒng)的日志,解析出所有文件的indoe信息,從而可以恢復(fù)Linux下主流的ext3 ext4文件系統(tǒng)下被誤刪除的文件.而ext3grep僅支持ext3文件系統(tǒng),此外在恢復(fù)速度上前者要更快,是通過掃描inode和數(shù)據(jù)恢復(fù)同時(shí)進(jìn)行,且支持單文件 單目錄 inode恢復(fù) block恢復(fù)與完整磁盤恢復(fù).而ext3grep略顯笨拙需要掃描所有inode信息然后開始恢復(fù)數(shù)據(jù),速度上相對(duì)比較慢且不支持目錄 時(shí)間恢復(fù)等.前置安裝e2fsprogs與e2fsprogs-libs1.誤操作刪除需要立即將分區(qū)卸載.2.extundelete /dev/sdc1 --inode 23.extundelete /dev/sdc1 --restore-file passwd? ?#單文件恢復(fù)4.extundelete /dev/sdc1 --restore-directory /ganglia-3.4.0? #單目錄恢復(fù)5.extundelete /dev/sdc1 --restore-all? #全部文件恢復(fù)6.extundelete --after 1379146740 --restore-all /dev/sdc1? #恢復(fù)一小時(shí)內(nèi)文件? ?當(dāng)前 date +%s-36004.Linux系統(tǒng)運(yùn)維故障排查思路Linux系統(tǒng)常見無法啟動(dòng)a.文件系統(tǒng)受損 [ext3 ext4文件系統(tǒng)都是具備日志記錄功能的日志文件系統(tǒng),并且可以進(jìn)行簡(jiǎn)單的容錯(cuò)與糾錯(cuò).日志文件系統(tǒng)并不是將數(shù)據(jù)實(shí)時(shí)寫入到磁盤,而是定期批量寫入,但文件系統(tǒng)的所有讀寫操作都會(huì)實(shí)時(shí)記錄到日志文件中,當(dāng)系統(tǒng)發(fā)生掉電等錯(cuò)誤導(dǎo)致數(shù)據(jù)沒有寫入磁盤時(shí)可以通過日志文件的記錄回滾發(fā)生故障的讀寫操作,從而保證數(shù)據(jù)和文件系統(tǒng)的一致性,但是由于實(shí)際環(huán)境復(fù)雜多樣導(dǎo)致文件系統(tǒng)不能每一次都可以成功自我修復(fù),這是就需要運(yùn)維人員手動(dòng)介入修復(fù).]掉電開機(jī)提示:? /dev/sda6 contains a file system with errors,check forced/dev/sda6:UNEXPECTED INCONSISTENCY;RUN fsck MANUALLY(or type Control-D to continue):give root password for maintenance輸入root密碼后進(jìn)入修復(fù)模式,使用fsck命令修復(fù).fsck.ext3 -y /dev/sda6? ? ? ? ? [無法恢復(fù)的數(shù)據(jù)會(huì)存放在文件系統(tǒng)lost+found目錄中]? ? (fsck -A -y)若忘記root密碼centos6.x1.引導(dǎo)參數(shù)中增加? init=/bin/bash 載入系統(tǒng).2.mount -o remount,rw /? ? ? ? ? ? ?#重掛根3.passwd? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#修改密碼4.重啟輸入root密碼繼續(xù)修復(fù).centos7.x1.引導(dǎo)參數(shù)中增加??rd.break console=tty0? 載入系統(tǒng)2.mount remount,rw /sysroot? ? ? ? #重掛根3.chroot /sysroot? ? ? ? ? ? ? ? ? ? ? ? ? ? #切換根4.passwd? ? ? ? ??5.touch /.autorelabel? ? ? ? ? ? ? ? ? ? ? ? ??6.exit7.rebootb.系統(tǒng)文件配置不當(dāng)或/etc/fstab文件丟失開機(jī)提示: starting system logger1.開機(jī)使用引導(dǎo)介質(zhì)進(jìn)入救援模式? [linux rescue]2.e2label 可查看每個(gè)分區(qū)對(duì)應(yīng)的掛載點(diǎn)?3.查找出原系統(tǒng)的跟分區(qū)目錄查找出對(duì)應(yīng)分區(qū) 如 /dev/sda34.創(chuàng)建一個(gè)目錄 /rescue_tmp 將原根掛載至此? ? mkdir /rescue_tmp ;mount /dev/sda3 /rescue_tmp5.vim /rescue_tmp/etc/fstab6.恢復(fù)完成后重啟系統(tǒng).c.Linux內(nèi)核丟失或崩潰d.引導(dǎo)程序出錯(cuò)e.硬件故障f.無響應(yīng)分析系統(tǒng)硬件問題: SCSI卡 主板 RAID卡 HBA卡 網(wǎng)卡 硬盤等硬件設(shè)備導(dǎo)致,通過更換硬件解決外圍硬件問題: 主要為網(wǎng)絡(luò)問題導(dǎo)致.網(wǎng)絡(luò)設(shè)備 網(wǎng)絡(luò)參數(shù)等方面查找軟件問題: 系統(tǒng)內(nèi)核bug 應(yīng)用軟件bug 驅(qū)動(dòng)程序bug等? 通過升級(jí)內(nèi)核 修復(fù)程序bug 更新驅(qū)動(dòng)程序解決系統(tǒng)設(shè)置問題: 防火墻配置 開機(jī)啟動(dòng)不正確等.iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT?iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
5.常見故障案例su 切換普通用戶時(shí)報(bào)錯(cuò).報(bào)錯(cuò)提示: su: warning: cannot change directory to /home/oracle: Permission deniedsu: /bin/bash: Permission denied?排查思路:
- 用戶目錄權(quán)限存在問題ls -ld /home/oracle?
- su? ?程序權(quán)限存在問題ll /bin/su
- 程序依賴的共享庫問題ldd /bin/su?
- SELinux問題grep "SELINUX" /etc/selinux/config
- 系統(tǒng)根分區(qū)問題檢查剩余容量檢查根分區(qū)權(quán)限
操作大量文件時(shí)遇到 Argument list too long? ? ?getconf ARG_MAX? 控制傳遞參數(shù)手動(dòng)分批刪除find傳遞刪除shell腳本循環(huán)刪除重新編譯linux內(nèi)核? include/liunx/binfmts.h文件 #define MAX_ARG_PAGES 32? ?將32改為64或128.重新編譯inode消耗殆盡?dumpe2fs -h /dev/sda3|grep 'Inode count'
文件刪除后空間不釋放:? 文件存放分為數(shù)據(jù)部分和指針部分,指針部分位于文件系統(tǒng)的meta-data中,將數(shù)據(jù)清除后指針從meta-data中被清除.將數(shù)據(jù)對(duì)應(yīng)的指針清除后空間隨之釋放.進(jìn)程占用不斷的寫數(shù)據(jù)導(dǎo)致
Too many open files?ulimit -n? ? ? ? ? ? ? [/etc/security/limits.conf]www soft nofile 65535www hard nofile 65535內(nèi)核文件大小限制進(jìn)程數(shù)據(jù)塊大小限制shell進(jìn)程創(chuàng)建文件大小限制可加鎖內(nèi)存大小限制常駐內(nèi)存集的大小限制打開文件句柄數(shù)限制分配堆棧的最大大小限制CPU占用時(shí)間限制用戶最大可用的進(jìn)程數(shù)shell進(jìn)程所能使用的最大虛擬內(nèi)存限制
No speace left on device:mod_rewrite:could not create rewrite_log_lock Configyration Failed??信號(hào)量占盡.? ipcs -s |grep nobody|perl -e 'while (<STDIN> { @a=split(/\s+/); print `ipcrmsem $a[1]`})'
6.輕量級(jí)運(yùn)維利器pssh pdsh mussh并行ssh運(yùn)維工具pssh? ?parallel-ssh? 支持文件并行復(fù)制/遠(yuǎn)程并行執(zhí)行命令/殺死遠(yuǎn)程主機(jī)進(jìn)程等&? 需要保證本地主機(jī)與管理服務(wù)器之間單向信任&? Python版本大于2.4&? 附帶5個(gè)主程序?ssh(pssh)? ? ? ? ? 遠(yuǎn)程主機(jī)并行運(yùn)行命令scp(pscp)? ? ? ? ? 復(fù)制文件至遠(yuǎn)程多臺(tái)主機(jī)rsync(prsync)? ? 使用rsync協(xié)議將文件從本地同步到遠(yuǎn)程多臺(tái)主機(jī)nuke(pnuke)? ? ?在遠(yuǎn)程主機(jī)并行killall某進(jìn)程slurp(pslurp)? ? ?將文件從遠(yuǎn)程主機(jī)復(fù)制到本地查看user002 003的時(shí)間pssh -H opsuser@user002.bestbook.com:9529 -P datepssh -H user003.bestbook.com?-i date批量管理列表? /etc/pssh/hosts批量下發(fā)命令獲取運(yùn)行時(shí)間?pssh -i -O "StrictHostKeyChecking=no" -h /etc/pssh/hosts "uptime"? ? ? ? -O?"StrictHostKeyChecking=no"? 讓遠(yuǎn)程主機(jī)自動(dòng)接受本地hostkey解壓文件passh -i -h /etc/pssh/hosts "tar -xzvf test.zip"連接指定端口passh -i -x "-l opsuser" "-p 9529" -h /etc/pssh/hosts -o /etc/pssh/info "uptime;name-a"? ? ? ? ? ? ? ? ? ? ? ? ??本地文件推送給批量遠(yuǎn)端pscp -h /etc/pssh/hosts /etc/ssh/ssh_config /tmppscp -h /etc/pssh/hosts -r /etc/httpd/conf /tmp??本地拉取遠(yuǎn)端文件pslurp -h /etc/pssh/hosts -L /home/opsuser/test > /home/opsuser/gmond.conf gmond1.confpslurp -h /etc/pssh/hosts -r -L /home/opsuser/test > /home/opsuser/gmond gmond1本地文件同步到遠(yuǎn)程主機(jī) prsync -h /etc/pssh/hosts -l opsuser -a -r /etc/httpd /tmp prsync -h /etc/pssh/hosts -l opsuser -az -r /var/log/httpd /tmp? ? ? ? ? ? ? ?#壓縮傳輸 殺死遠(yuǎn)端進(jìn)程 punke -h /etc/pssh/hosts httpd
分布式運(yùn)維工具pdsh? parallel distributed shell? 適用于大批量服務(wù)器配置/部署/文件復(fù)制/運(yùn)維等操作 &? 需要保證本地主機(jī)與管理服務(wù)器之間的單向信任 &? 默認(rèn)rsh方式? 支持ssh mrsh qsh mqsh krb4 xcpu 等多種rcmd模塊 &? --with-ssh? --with-dshgroups? --with-machines? --with-dshgroups &? 傳輸文件時(shí) 本地與遠(yuǎn)端都必須安裝pdcp 批量統(tǒng)計(jì)信息 pdsh -w ssh:192.168.16.[1-3]? "uname -n" pdsh -w ssh:user00[1-5] -x user003 "uptime" pdsh -w ssh:user00[10-31],/15/ "uptime" 文件批量調(diào)用 /etc/pdsh/machines pdsh -R ssh -a uptime pdsh -R ssh -g userhosts uptime pdsh -R ssh -a -X userhosts uptume 交互模式 pdsh -R ssh -w user001 文件傳輸 pdcp -R ssh -g userhosts /home/opsuser/mysqldb.tar.gz /home/opsuser pdcp -R ssh -w userhosts -r /home/opsuser/webdata /home/opsuser
多主機(jī)ssh封裝mussh? MUltihost SSH Wrapper &? 需要保證本地主機(jī)與管理服務(wù)器之間的單向信任 批量命令: mussh -h opsuser@user01 opsuser@user02 -c uptime 文件批量命令? ? ? ?/home/opsuser/myhosts mussh -H myhosts -l opsuser -c uptime 本地腳本遠(yuǎn)端執(zhí)行 mussh -o "port=22" -H myhosts -s /usr/bin/python -C "/home/opsuser/checkos.py"
7.分布式監(jiān)控 Ganglia HPC(高性能計(jì)算集群) 采集CPU 內(nèi)存 硬盤使用率 I/O負(fù)載 網(wǎng)絡(luò)流量等情況匯總到gmetad守護(hù)進(jìn)程下,使用rrdtool存儲(chǔ)數(shù)據(jù).以曲線方式展示 &? gmond: ganglia monitoring daemon 守護(hù)檢測(cè)進(jìn)程默認(rèn)監(jiān)聽8649 &? gmetad:ganglia meta daemon 數(shù)據(jù)匯聚守護(hù)進(jìn)程,將數(shù)據(jù)存儲(chǔ)至RRD引擎中 &? webfrontend:從gmetad中讀取RRD數(shù)據(jù)通過rrdtool生成圖表 gmetric -n disk_used -v 40 -t int32 -u '% test' -d 50 -s '8.8.8.8:cloud1'
8.高性能Nginx服務(wù)器 HTTP/IMAP/POP3/SMTP代理服務(wù)器 --with-http_stub_status_module? ? #開啟nginx status功能 監(jiān)控狀態(tài) --with-http_gzip_static_module? ? ?#開啟Gzip壓縮功能 select? ? ? ? ? 標(biāo)準(zhǔn)工作模式1 poll? ? ? ? ? ? ?標(biāo)準(zhǔn)工作模式2 kqueque? ? ?高效工作模式1 epoll? ? ? ? ? ?高效工作模式2 rtsig? ? ? ? ? ?? /dev/poll max_client=worker_processes * worker_connections(默認(rèn)1024)? ?#ulimit -n 65536 sendfile? on; tcp_nopush on ; tco_nodelay on; 開啟ngin運(yùn)行狀態(tài) localtion /NginxStatus { stub_status? ? ? ? ? ? ? ? ?on; access_log? ? ? ? ? ? ? ? ? logs/NginxStatus.log; auth_basic? ? ? ? ? ? ? ? ? "NginxStatus"; auth_basic_user_file? ?../htpasswd; } htpasswd -C htpassswd password 信號(hào)處理: QUIT:? 15? ?處理完當(dāng)前請(qǐng)求關(guān)閉進(jìn)程 HUP:? ? ? ? ?重載配置,關(guān)閉原由進(jìn)程開啟新進(jìn)程,不中斷請(qǐng)求 USR1:? ? ? ? Nginx日志切割 USR2:? ? ? ? 平滑升級(jí) WINCH:? ? ?從容關(guān)閉 rewrite重寫 來自www.taob.com的請(qǐng)求至www.tb.com? service { service_name? www.taob.com; rewirte ^/(.*)$? http://www.tb.com/$1?permanent;? ?#301 redirect 302 } 基于核心變量$host實(shí)現(xiàn)重定向 service { server_name? www.tb.com?www.taob.com; if ($host != 'www.tb.com') { rewirte ^/(.*)$ http://www.tb.com/$1?permanent; } } 禁止訪問特定資源 location ~* \.(txt|doc)$ { root /data/www/wwwroot; deny all; } Nginx內(nèi)置變量 $args? ? ? ? ? ? ? ? ? ? ? ?與請(qǐng)求行的參數(shù)相等 $document_root? ? ?當(dāng)前root命令指定的值 $uri? ? ? ? ? ? ? ? ? ? ? ? ? 當(dāng)前request中的URI $document_uri? ? ? ? 同等$uri $host? ? ? ? ? ? ? ? ? ? ? ?與頭部"Host"行的值一致 $limit_rate? ? ? ? ? ? ? ?限制連接速率 $request_method? ? 同等于request的method GET或POST $remote_addr? ? ? ? ? 客戶端IP $remote_port? ? ? ? ? ?客戶端端口 $remote_user? ? ? ? ? ?用戶名? ngx_http_auth_basic_module認(rèn)證 $request_filename? ? 當(dāng)前請(qǐng)求的文件的路徑名,由root或alias與URI request組合而成 $request_uri? ? ? ? ? ? ? 參數(shù)完整的初始URI $query_string? ? ? ? ? ? 與$args一致 $server_name? ? ? ? ? ? 請(qǐng)求到達(dá)的服務(wù)器名 $server_port? ? ? ? ? ? ? ?請(qǐng)求到達(dá)的端口號(hào) location ~ ^/best/ { rewirte ^/best/(.*)$ /test/$1 break; proxy_pass http://www.taob.com; }
location / { proxy_pass http://127.0.0.1:8080/; set $query $query_string; rewrite /dade /wordpress?$query?; } 可將http://www.tb.com/wp/?p=160的頁面重寫到www.tb.com/wordpress/?p=160 service { listen? ? ? ? ? ? ?80; server_name www.tb.cn? www.taob.com; if ($host != 'www.tb.cn') { rewirte ^/(.*)$ http://www.tb.cn/error.txt? bread; rewirte ^/(.*)$ http://www.tb.cn/$1?permanent; } }
nginx 編譯時(shí)注釋 auto/cc/gcc 的? CFLAGS="$CFLAGS -g" --with-cc-opt='-O3' --with-cpu-opt=CPU? [pentinm pentiumpro pentium3 pentium4 athlon opteron adm64 sparc32 sparc64 ppc64]? ? ?cat /proc/cpuinfo? |grep "model name"
TCMalloc 優(yōu)化Nginx性能? 1.安裝libunwind庫 2.安裝google-perftools 3.重新編譯nginx 添加參數(shù) --with-google_perftools_module 4.添加google-perftools線程目錄? 0777 權(quán)限 5.nginx主配置文件pid處寫入 google_perftools_profiles /tmp/tcmalloc; 6.重啟nginx 驗(yàn)證
針對(duì)nginx的內(nèi)核優(yōu)化? ?/sbin/sysctl -p net.ipv4.tcp_max_tw_buckets = 6000? ? ? ? ? ? ? ?#timewait數(shù)量? 默認(rèn)180000 net.ipv4.ip_local_port_range = 1024 65000? ? ?#允許系統(tǒng)打開的端口范圍 net.ipv4.tcp_tw_recycle = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #啟用timewait快速回收 net.ipv4.tcp_tw_reuse = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#允許TIME-WAIT sockets net.ipv4.tcp_syncookies = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#SYN等待隊(duì)列溢出時(shí)啟用cookies處理 net.core.somaxconn = 262144? ? ? ? ? ? ? ? ? ? ? ? ?#tcp并發(fā)連接 默認(rèn) 128 net.core.netdev_max_backlog?= 262144? ? ? ? ? #網(wǎng)口數(shù)據(jù)包速率比內(nèi)核處理快時(shí)允許等到的隊(duì)列大小 net.ipv4.tcp_max_orphans = 262144? ? ? ? ? ? ? ? #設(shè)定最大套接字不被關(guān)聯(lián)到任何用戶文件句柄上 net.ipv4.tcp_max_syn_backlog?= 262144? ? ? ? ? #記錄尚未收到客戶端確認(rèn)信息的連接請(qǐng)求最大值 net.ipv4.tcp_synack_retries = 1? ? ? ? ? ? ? ? ? ? ? ? ?#內(nèi)核放棄連接之前發(fā)送SYN+ACK包的數(shù)量 net.ipv4.tcp_syn_retres = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#內(nèi)核放棄建立連接前發(fā)送SYN包的數(shù)量 net.ipv4.tcp_fin_timeout = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#保持FIN-WAIT-2狀態(tài)的時(shí)間 默認(rèn)60 net.ipv4.tcp_keepalive_time = 30? ? ? ? ? ? ? ? ? ? ? #keepalive啟動(dòng)時(shí)tcp發(fā)送的頻度 默認(rèn)2
總結(jié)
以上是生活随笔為你收集整理的高性能Linux架构实战 [高俊峰] 笔记摘要的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 北京邮电大学计算机学院李剑,北京邮电大学
- 下一篇: linux修改数据库内容命令,linux