Shell-Related Tips Summary application (1)

Source: Internet
Author: User
Tags gz file rsync

1. Run the command as a specified user

Runuser-work-c "Cd/home/work/uc/bin && sh start.sh"

Runuser-push-c "Cd/home/push/mucs/bin && sh start.sh"

Or:

Daemon--user mongod "Mongod--config conf/mongod.conf"

Daemon is a function name that needs to be source/etc/rc.d/init.d/functions before being used


2, about the Rsync data synchronization related applications:

Synchronizing company UC Data

RSYNC-AVZPTOGL--progress UC--exclude "Uc/logs" zayhu05-mb:/home/work/

synchronizing mucs data

RSYNC-AVZPOGTL--progress mucs--exclude "mucs/logs"--exclude "mucs/saved"--exclude "Mucs/ttscache" mucs06-fk:/home/p Ush

Synchronize locally when replacing a disk

RSYNC-AVZTOPGL--progress/data//data03/

Note: If there is no-l parameter, soft link will not be synchronized;--exclude can exclude subdirectories that you do not want to synchronize


3. Defense method New Challenge Response limit attack:

By using sysctl to raise the challenge response limit to a larger range , so that the attacker cannot reasonably reach it, it is not possible to infer any additional data from the client server connection to achieve defensive purposes.

1) Set the net.ipv4.tcp_challenge_ack_limit in /etc/sysctl.conf to a larger value (such as 999999999):

Net.ipv4.tcp_challenge_ack_limit = 999999999

2) load settings:

Sysctl-p


4, in Umount a disk, the system always prompt busy, the error is as follows:

[Email protected] ~]# lsof +d/data2/

COMMAND PID USER FD TYPE DEVICE size/off NODE NAME

Bash 6646 push cwd DIR 202,80 4096 3145731/data2/mucs/logs

[Email protected] ~]# ps-ef | grep 6646

Root 5866 1567 0 14:56 pts/1 00:00:00 grep--color=auto 6646

Push 6646 6645 0 Nov23 pts/0 00:00:00-bash

[Email protected] ~]# kill 6646

[[email protected] ~]# and then umount, uninstall successful


5, Statistics company application error log distribution ratio:

[[email protected] logs]$ grep-i error mucs.err.log.2016-12-09 | awk-f ' [\\[\\]] ' {state[$4]+=1;line+=1}end{for (i I n state) printf ("%-35s%10d\t%-8f%\n", I,state[i],state[i]*100/line)} '

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/8B/5E/wKioL1hLg0nTx46qAAIxizXQwiA724.png-wh_500x0-wm_3 -wmp_4-s_2787783991.png "title=" screen shot 2016-12-10 11.26.21.png "alt=" Wkiol1hlg0ntx46qaaixizxqwia724.png-wh_50 "/>

Note: awk can define more than one when defining delimiters, for example: Df-h | Awk-f "[%]" '/data/{if ($ (NF-2) >50) print $} ' is delimited by a space or percent semicolon, but if the delimiter needs to be defined as brackets, the escape character must be used. awk needs to use ' \ \ ' When escaping the brackets.


6. Filter the error log from the/var/log/nginx/error.log file for nearly 10 minutes:

[Email protected] ~]# tail-c 10m/var/log/nginx/error.log | grep-a "Error" | awk-f ' [' begin{' Date +%s ' | getli Ne nowts}{"date-d \" "$" \ "+%s" | getline ts; if ((Nowts-ts) <) print $} '

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/8B/62/wKiom1hLj7CTUMKZAAG7MBZJRks548.png-wh_500x0-wm_3 -wmp_4-s_2379091928.png "title=" screen shot 2016-12-10 13.16.02.png "alt=" Wkiom1hlj7ctumkzaag7mbzjrks548.png-wh_50 "/>

Note: First remove the last 10M log from the log, then filter the line with "error", then take the current timestamp, put the current time stamp into the newts variable using getline, and then use date-d to convert the fixed time in each row of logs to the%s (timestamp) format. And put in the variable TS, and finally determine whether the current timestamp minus the log timestamp is greater than 600s, and output the final result.


7, the Shell function returns the value commonly used two kinds of ways: Return,echo

1) return statement
The return value of the Shell function, which, like the return value of other languages, is returned by a return statement

Note: return can only be used to return an integer value, and the difference to C is that 0 is returned as correct, and the other value is error.

2)echo return value

In fact, in the Shell , the return value of the function has a very safe return, which is returned by output to standard output. Because the child process inherits the standard output from the parent process, the output of the child process is also reflected directly to the parent process. It is important to note that you do not send some information that is not a result to the standard output (that is, do not just echo some unwanted information), such as debugging information (which can be redirected to a file), so remember to add a command that resembles grep. >/dev/null 2>&1 To receive these output information to avoid the output of these commands


8, the company upgrade JDK summary

[Email protected] ~]# tar xfz jdk-9-ea+146_linux-x64_bin.tar.gz

[[email protected] ~]# ls

Jdk-9 jdk-9-ea+146_linux-x64_bin.tar.gz

[Email protected] ~]# cp-r jdk-9/usr/java/

[Email protected] ~]# cd/usr/java/

[Email protected] java]# ll

Total 16

lrwxrwxrwx 1 root root + Jan Default-/usr/java/latest

Drwxr-xr-x 8 root root 4096 Jan jdk1.7.0_80

Drwxr-xr-x 9 root root 4096 Nov 8 13:53 jdk1.8.0_112

Drwxr-xr-x 9 root root 4096 Nov 7 16:48 jdk1.8.0_77

Drwxr-xr-x 8 root root 4096 Dec 8 12:10 jdk-9

lrwxrwxrwx 1 root root 8 13:53 latest-/usr/java/jdk1.8.0_112

[Email protected] java]# RM latest-f

[Email protected] java]# ln-s/usr/java/jdk-9 latest

[Email protected] java]# ll

Total 16

lrwxrwxrwx 1 root root + Jan Default-/usr/java/latest

Drwxr-xr-x 8 root root 4096 Jan jdk1.7.0_80

Drwxr-xr-x 9 root root 4096 Nov 8 13:53 jdk1.8.0_112

Drwxr-xr-x 9 root root 4096 Nov 7 16:48 jdk1.8.0_77

Drwxr-xr-x 8 root root 4096 Dec 8 12:10 jdk-9

lrwxrwxrwx 1 root root 8 12:10 latest-/usr/java/jdk-9

[Email protected] java]# java-version

Java Version "9-ea"

Java (TM) SE Runtime Environment (build 9-ea+146)

Java HotSpot (TM) 64-bit Server VM (build 9-ea+146, Mixed mode)

[[email protected] java]# If you see the current version incorrectly, you need to use alternatives to set the current version to point to latest

[Email protected] java]# alternatives--config java

There is 4 programs which provide ' Java '.

Selection Command

-----------------------------------------------

1/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java

* 2/usr/java/jdk1.8.0_91/jre/bin/java

+ 3/usr/java/latest/bin/java

4/usr/java/jdk-9/bin/java

Enter to keep the current selection[+], or type selection number: 3

[Email protected] java]#

Note: When extracting the jdk-9-ea+146_linux-x64_bin.tar.gz file, try to avoid using the-C parameter to extract directly into the/usr/java directory, and try to avoid the extracted jdk-9 directory directly using the MV command to move to the/usr/java directory, The above two methods of operation cause the exception of the contents owner and group in the/usr/java/jdk-9/directory, as shown in:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/8B/62/wKiom1hLieSwpYU8AALLM8bL5-k757.png-wh_500x0-wm_3 -wmp_4-s_678012454.png "title=" screen shot 2016-12-10 12.33.52.png "alt=" Wkiom1hlieswpyu8aallm8bl5-k757.png-wh_50 "/>


9. Application of awk referencing shell variables

There are many ways in which awk invokes shell variables, and personal habits use the- v option, as follows:

[[email protected] ~]# df-h | awk-v threshold= $threshold-F "[%]" '/data/{if ($ (NF-2) >threshold) print $} '

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/8B/5E/wKioL1hLjCeCj_m0AAEVeVp_Snc841.png-wh_500x0-wm_3 -wmp_4-s_1785149196.png "title=" screen shot 2016-12-10 12.57.47.png "alt=" Wkiol1hljcecj_m0aaevevp_snc841.png-wh_50 "/>


10, about the caching technology of PHP

early PHP needed to implement opcode caching with eaccelerate or XCache-related software to improve speed; PHP5.5 and other advanced versions, compile with the--enable-opcache parameter, PHP will be opcode cache function. The relevant configuration is as follows:

[Email protected] ~]# Vim/usr/local/php-5.5.20/php.ini

Opcache.enable=1

Zend_extension=/usr/local/php-5.5.20/lib/php/extensions/no-debug-non-zts-20121212/opcache.so

opcache.memory_consumption=128

Opcache.interned_strings_buffer=8

opcache.max_accelerated_files=4000

Opcache.revalidate_freq=60

Opcache.fast_shutdown=1

Opcache.enable_cli=1

[Email protected] ~]# service php-fpm Restart

This article from "11462293" blog, declined reprint!

Shell-Related Tips Summary application (1)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.