Linux setup host mutual trust /// install and configure subversion (SVN) /// shell script

Linux sets up mutual trust between hosts

1. Set up mutual trust between hosts

Modify hostname

<The default host name is localhost.localhostDomain>

Step 1: Two ways to modify the host name:

(1) hostnamectl set-hostname new hostname
(2) vi /etc/hostname in which change [hostname] to [new hostname] needs to be restarted to take effect

Step 2: host list vi /etc/hosts add: host ip address host name

E.g:
Insert picture description here

Add mutual trust:

Step 3: Generate the key:

ssh -keygen -t rsa -P “”

Step 4: Copy to the key verification file:

cat ~/.ssh/id_rsa.pub > .ssh/authorized_keys

Step 5: Transfer to the machine that needs to be copied:

ssh-copy-id -i ~/.ssh/id_rsa.pub -p22 username@ corresponding hostname

Step 6: Test the connection to the host:

ssh username@hostname/ip address: connect to the corresponding host,
such as: [root@hadoop5 ~]#ssh root@hadoop1

Two, install and configure subversion (SVN)

2.1 What is SVN?

Subversion (SVN) is an open source version control system, which means that Subversion manages data that changes over time. These data are placed in a central repository. This archive is much like a normal file server, but it will remember every file change. In this way, you can restore the file to the old version, or browse the change history of the file.
repository (source code library): the unified storage place of the source code
Checkout (extract): when you do not have the source code, you need to check out a
Commit (submit) from the repository : when you have modified the code, you need Commit to repository
Update (Update): When you have checked out a source code, you can synchronize with the source code on the Repository once you update, and the code in your hand will have the latest changes

SVN adopts a client/server system. Various versions of the project are stored on the server. The program developer will first obtain a copy of the latest version of the project from the server and copy it to the machine. Then, on this basis, every A developer can carry out independent development work on his client, and can submit new code to the server at any time. Of course, you can also obtain the latest code on the server through an update operation, so as to maintain consistency with the version used by other developers. [3]
There are two types of SVN clients, one is Web-based WebSVN, and the other is client software represented by Tortoise SVN. The former requires the support of a Web server, the latter requires users to install the client locally, and both have free open source software for use. SVN also stores version data in two ways: BDB (a transaction-safe table type) and FSFS (a storage system that does not require a database). Because the BDB method may lock data when the server is interrupted, the FSFS method is safer.

2.2 SVN configuration steps

Need to install server side and customer service side

1. Install subversion server
yum -y install subversion
2. Create SVN resource library directory
mkdir /svndata
3. Generate SVN resource directory
svnadmin create /svndata/projects/jdbc
4. Configure SVN project permission authentication
(1) Enter SVN project library configuration Folder
cd /svndata/projects/jdbc/conf/
(2) Configure SVN read and write permissions, modify authz information: vi authz
add after [group]:
[/]
root=rw
(3) Set the initial password for the user: vi
add passwd in the last line:
root=1
Remarks: here is username = password
(4) The option to modify the svnserve file: vi svnserve.conf
1. Add after # anon-access = read # auth-access = write:
anon -access=none
auth-access=write
2. Add after # password-db = passwd:
password-db=passwd
3. Add after # authz-db = authz:
authz-db=authz
Start SVN: svnserve -d -r /svndata to
open SVN default port 3690

Customer service:
1. Download the client software:
Insert picture description here

2. Create a folder on Disk D:
At this time, click the right mouse button, select SVN checkout,
fill in the resource directory name created on the server side, click OK, and enter the username and password you just added

Insert picture description here
3. Display the graphical interface Insert picture description here
4. Put a java file in the folder, click the + sign, add relevant modification information, and update

Three, Shell programming

Basic grammar

1. Every shell has a header definition, normal #!/bin/bash
2. Print: echo "thing to be printed" (single quotes and double quotes are acceptable)
3. The defined script needs to add execution permissions: chmod +x script path
4. Three call methods:
(1) Path call: if you are in the current directory, use ./test.sh, absolute path is also available
(2) Ordinary script execution: sh script path
(3) Specify b shell Execution: /bin/bash script path
5. Definition of variables
(1) Direct assignment method: a=1 b=”abc” arr=(1 2 3 4)
(2) Reference assignment method: b=ac = ac=ac ={b}
(2) Assignment of the execution result of the quoted command: a=ls -l
Note: There can be no spaces between the variable name and the equal sign, which is different from all familiar programming languages.
7. Perform variable operations: b=expr KaTeX parse error: Expected'EOF', got'&' at position 215: …to be omitted into [[ conditional statement]] & ̲& result statement 11. In single quotation marks... {a} refers to variables

Shell script custom function

1. [function] Function name (){function body;} can have return statement, but only return value type
2. Parameter passing: The parameter list inside the function depends only on the parameter list when the function is called, and the parameters of the script No direct impact

'Single quotation mark': When the content I need to display is plain text, use single quotation mark
"Double quotation mark": When there is a quotation in the content I need to display, use double quotation mark.

1. Example of expr usage

The expr command can realize functions such as numerical calculation, numerical or string comparison, string matching, string extraction, string length calculation and so on. It also has several special functions to determine whether a variable or parameter is an integer, whether it is empty, whether it is 0, etc.

The following examples will be used to introduce the usage of expr. Before the introduction, three points need to be paid attention to:

(1). Numerical expressions ("+-* / %") and comparison expressions ("< <= = == != >= >") will first convert the parameters at both ends to numeric values, and an error will be reported if the conversion fails. Therefore, it can be used to determine whether the parameter or variable is an integer.

(2) Many symbols in .expr need to be escaped or surrounded by quotation marks.

(3). There must be spaces on both sides of all operators.

The following is an example of expr.

(1). "string: REGEX" string matching example. To output the matched string results, you need to use "(" and ")", otherwise the number of matched strings will be returned.

[root@xuexi ~]# expr abcde : ‘ab(.*)’
cde

[root@xuexi ~]# expr abcde : ‘ab(.)’
c

[root@xuexi ~]# expr abcde : ‘ab.*’
5

[root@xuexi ~]# expr abcde : ‘ab.’
3

[root@xuexi ~]# expr abcde : ‘.cd
4

(2). "index string chars" usage example.

This expression is to search the position of a character in chars from the string, which is the first character in the string. E.g:

[root@xuexi ~]# expr index abcde dec
3
This command decomposes the string "dec" character by character, first decomposes to get the first character d, searches for the position of d from abcde to 4, and then decomposes to get the second A character e, the position of the character in abcde is 5, the final character is c, and the position of the character in abcde is 3. Among them, 3 is the first character, so the result returned by the command is 3.

[root@xuexi ~]# expr index abcde xdc
3
If none of the characters in chars exist in the string, 0 is returned.

[root@xuexi ~]# expr index abcde 1
0

[root@xuexi ~]# expr index abcde 1x
0

(3). "substr string pos len" usage example.

This expression is to take a substring of length len from the pos position from the string. If pos or len is a non-positive integer, an empty string will be returned.

[root@xuexi ~]# expr substr abcde 2 3
bcd

[root@xuexi ~]# expr substr abcde 2 4
bcde

[root@xuexi ~]# expr substr abcde 2 5
bcde

[root@xuexi ~]# expr substr abcde 2 0

[root@xuexi ~]# expr substr abcde 2 -1

(4). "length string" usage example. This expression returns the length of the string, where the string is not allowed to be empty, otherwise an error will be reported, so it can be used to determine whether the variable is empty.

[root@xuexi ~]# expr length abcde
5

[root@xuexi ~]# expr length 111
3

[root@xuexi ~]# expr length $xxx
expr: syntax error

[root@xuexi ~]# if [ ? − n e 0 ] ; t h e n e c h o ′ ? -ne 0 ];then echo ' ?n e 0 ] ;thenecho' Xxx is null'; fi
$xxx is null
(6). Examples of arithmetic operation usage.

[root@xuexi ~]# expr 1 + 2
3

[root@xuexi ~]# a=3
[root@xuexi ~]# b=4

[root@xuexi ~]# expr $a + $b
7

[root@xuexi ~]# expr 4 + $a
7

[root@xuexi ~]# expr $a-$b
-1 The
arithmetic multiplication symbol "*" is a metacharacter of the shell, so to escape it, you can use quotation marks or use a backslash.

[root@xuexi ~]# expr $a * $b
expr: syntax error

[root@xuexi ~]# expr $a ‘*’ $b
12

[root@xuexi ~]# expr $a * $b
12

[root@xuexi ~]# expr $b / $a # Division can only take the integer
1

[root@xuexi ~]# expr $b% $a
1
Any operator must have spaces at both ends, otherwise:

[root@xuexi ~]# expr 4+$a
4+3

[root@xuexi ~]# expr 4 +$a
expr: syntax error
When expr performs arithmetic operations, it first converts the parameters on both sides of the operator to integers, and any conversion failure at either end will report an error, so it can be used to judge Whether the parameter or variable is an integer.

[root@xuexi ~]# expr $a + $c
expr: non-integer argument

[root@xuexi ~]# if [ ? ! = 0 ] ; t h e n e c h o ′ ? != 0 ];then echo ' ?!=0];thenechoa or $c is non-integer’;fi
$a or $c is non-integer

(5). Comparison operator <<= = == != >=> usage example. Among them, "<" and ">" are the anchor metacharacters of the regular expression, and "<" will be parsed as a redirection symbol by the shell, so it needs to be escaped or enclosed in quotation marks.

These operators will first convert the parameters at both ends into numeric values. If the conversion succeeds, the numeric comparison is used, and if the conversion fails, the character size comparison is performed according to the collation rules of the character set. If the result of the comparison is true, expr returns 1, otherwise it returns 0.

[root@xuexi ~]# a=3

[root@xuexi ~]# expr $a = 1
0

[root@xuexi ~]# expr $a = 3
1

[root@xuexi ~]# expr $a * 3 = 9
1

[root@xuexi ~]# expr abc > ab
1

[root@xuexi ~]# expr akc > ackd
1

(6). Examples of usage of logical connection symbols "&" and "|". Both of these symbols need to be escaped or enclosed in quotation marks.

The following is the explanation given in the official document, but it is not completely correct in actual use.

"&" means that if the two parameters are both non-empty and non-zero, the value of the first parameter will be returned, otherwise 0 will be returned. And if the first parameter is found to be empty or 0, the second parameter is skipped without any calculation.

"|" means that if the first parameter is non-empty and non-zero, the first parameter value is returned, otherwise the second parameter value is returned, but if the second parameter is empty or 0, then 0 is returned. And if the first parameter is found to be non-empty or non-zero, the second parameter will be skipped without any calculation.

The correct one should be:

"&" means that if both parameters are non-zero, the first parameter will be returned, otherwise 0 will be returned. But if any parameter is empty, expr reports an error. Unless the empty string is surrounded by quotation marks, the processing method is the same as 0.

"|" means that if the first parameter is not 0, the value of the first parameter is returned, otherwise the second parameter is returned. But if any parameter is empty, expr reports an error. Unless the empty string is surrounded by quotation marks, the processing method is the same as 0.

[root@xuexi ~]# expr $abc ‘|’ 1
expr: syntax error

[root@xuexi ~]# expr “$abc” ‘|’ 1
1

[root@xuexi ~]# expr “$abc” ‘&’ 1
0

[root@xuexi ~]# expr $abc ‘&’ 1
expr: syntax error

[root@xuexi ~]# expr 0 ‘&’ abc
0

[root@xuexi ~]# expr abc ‘&’ 0
0

[root@xuexi ~]# expr abc ‘|’ 0
abc

[root@xuexi ~]# expr 0 ‘|’ abc
abc

[root@xuexi ~]# expr abc'&' cde
abc
Reprinted from: https://www.cnblogs.com/f-ck-need-u/p/7231832.html

Guess you like

Origin blog.csdn.net/qq_42005540/article/details/114795082