Operation Course Record

This blog is for record what I learn from this Operation Course

shell

SHORTCUTS

Ctrl + r:find the histroy
Ctrl + l:clear the terminal
Ctrl + a \ Ctrl + e:move to head\end in row
Ctrl + w \ Ctrl + k:delete before\after cursor

ZZ : VIM save and quit

Ctrl+C: Interrupt (kill) the current foreground process running in in the terminal. This sends the SIGINT signal to the process, which is technically just a request—most processes will honor it, but some may ignore it.
Ctrl+Z: Suspend the current foreground process running in bash. This sends the SIGTSTP signal to the process. To return the process to the foreground later, use the fg process_name command.
Ctrl+D: Close the bash shell. This sends an EOF (End-of-file) marker to bash, and bash exits when it receives this marker. This is similar to running the exit command.

top SHORTCUTS

Shift + p:Sort by CPU
Shift + m:Sort by Memory

find large file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
du -x --max-depth=1 / |sort -k1 -nr
du -x -d 1 -h / |sort -k1 -nr


# find which folder has most inode
find -type f | awk -F / -v OFS=/ '{$NF="";dir[$0]++}END{for(i in dir)print dir[i]" "i}'| sort -k1 -nr | head

769 ./wrk/obj/openssl-1.1.1b/test/
551 ./.cache/mozilla/firefox/hha91z74.default-release/cache2/entries/
462 ./wrk/obj/openssl-1.1.1b/doc/man3/
229 ./wrk/obj/LuaJIT-2.1.0-beta3/src/
212 ./wrk/obj/openssl-1.1.1b/test/certs/
207 ./wrk/obj/openssl-1.1.1b/apps/
199 ./wrk/obj/openssl-1.1.1b/crypto/asn1/
194 ./.cache/gnome-software/icons/
185 ./wrk/obj/openssl-1.1.1b/crypto/evp/
157 ./wrk/obj/openssl-1.1.1b/test/recipes/

rename

1
2
3
4
5
6

# find consumer.xml file and replace all aaaaaa to bbbbbb
find ./ -type f -name consumer.xml -exec sed -i "s/aaaaaa/bbbbbb/g" {} \;

# find all .txt file and compress then copy to /home/.
(find . -name "*.txt"|xargs tar -cvf test.tar) && cp -f test.tar /home/.

network

1
2
3
4
5
# network status
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

# get IP
ip a|grep "global"|awk '{print $2}'| awk -F/ '{print $1}'

nginx

cpu affinity

1
worker_cpu_affinity auto

offical document

epoll

Add in kernel 2.6

  1. epoll’s event flow model is thread-safe;
  2. epoll follow the selection model and improve efficiency;
  3. epoll is event-driven. You can select the relevant state of the entire file to be scanned according to your needs. epoll avoids replacing the scanned file according to the event. You can directly call the callback function, which is more efficient.
  4. Removed the maximum limit on the number of file sizes that can be monitored by the temporary process inside the select model (1024). If you have used an earlier version of Apache, the selection model it uses will be delayed when the request exceeds 1000. The request is wrong, and the performance will be significantly improved by using Nginx.
  5. In addition, an optimization place involved in the events {} configuration is worker_connections, which is also set in events. Through the above learning, we know the role of the worker thread, and the connections supported by each worker thread are Limited, it will be set to 1024 by default here, and when we are dealing with high concurrency scenarios, it is often too low to split worker threads to 1024. It is recommended that you increase the worker_connections, you can refer to the actual business needs Nginx processing Maximum to increase this setting.

sendfile


refer docs

1
2
3
4
5
location /video/ {
sendfile on;
tcp_nopush on;
aio on;
}

gzip

docs

  1. gzip on is responsible for turning on the compression function of the backend;
  2. gzip_buffer 16 8k means to set the memory space of Nginx when processing file compression;
  3. gzip_comp_level 6 indicates the compression level of Nginx when processing compression. Generally, the higher the level, the larger the compression ratio. However, it does not mean that the larger the compression ratio, the better. It is still necessary to choose a suitable compression ratio according to the actual situation. The compression ratio is too large. Affects performance. Compression ratio is too small to achieve the desired effect. Generally, it is recommended that you set it to 6 to be more appropriate.
  4. gzip_http_version 1.1 means only compress the HTTP 1.1 version of the protocol;
  5. gzip_min_length 256 means that compression is performed only when the length is greater than the minimum 256 bytes, and if it is less than this length, no compression is performed;
  6. gzip_proxied any means that Nginx as a reverse proxy sets some gzip compression policies based on the information returned by the backend server;
  7. gzip_vary on indicates whether to send Vary: Accept_Encoding response header field, to realize that the receiver server is gzip compressed;
  8. application / vnd.ms-fontobject image / x-icon; gip compression type;
  9. gzip_disable "msie6"; Turn off compression for IE6.