wget
Overview
wget is一个下载文件的工具,用在命令行下
,Download some software or restore backup from remote server to local server
wget supports HTTP, HTTPS and FTP protocols and can use HTTP proxy
Support Automatic lowering
- wget can be executed in the background after the user exits the system.
- means that you can log in to the system, start a wget download task, and then exit the system,
wget将在后台执行直到任务完成
, compared to most other browsers that require continuous user participation when downloading large amounts of data. The advantages are more obvious
very stable
- It has strong adaptability in situations with very narrow bandwidth and unstable networks.
- If the download fails due to network reasons, wget will continue to try until the entire file is downloaded.
- If the server interrupts the download process, it will contact the server again and continue downloading from where it stopped.
use
Command format:
wget [参数] [URL地址]
Download resources from the Internet. If no directory is specified, the downloaded resources will default to the current directory.
Download a single file
Download a file from the Internet and保存在当前目录
, a progress bar will be displayed during the downloading process, including (Download completion percentage, bytes downloaded, current download speed, remaining download time).
wget http://www.minjieren.com/wordpress-3.1-zh_CN.zip
Speed limited download
When wget is executed, itwill occupy all possible bandwidth downloads by default. But当你准备下载一个大文件
, and you need to download other files, it is necessary to limit the speed
wget --limit-rate=300k http://www.minjieren.com/wordpress-3.1-zh_CN.zip
Background download
When downloading very large files, we can use the parameter -b to download in the background
wget -b http://www.minjieren.com/wordpress-3.1-zh_CN.zip
Use the following command to check the download progress
tail -f wget-log
Increase the number of retries for downloading files
It may also fail if there are network problems or if the download is a large file. wget默认重试20次连接下载文件
. If necessary, you can use --tries to increase the number of retries.
wget --tries=40 URL
Download multiple files
First, save a file with the download link
cat filelist.txt
url1
url2
url3
url4
Then use the following command
wget -i filelist.txt
Store download information in log file
wget -o download.log URL
Download and save with a different file name
By default, wget will use the last character after "/" to command. For dynamic link downloads, the file name will usually be incorrect.
- If you download it directly, it will be saved as:download.aspx?id=1080
wget http://www.minjieren.com/download.aspx?id=1080
下载并以wordpress.zip名称保存
wget -O wordpress.zip URL
ssh
Overview
The ssh service is a daemon. The system monitors client connections in the background. The process of the ssh server is called sshd, which is responsible for monitoring client requests (IP 22 port) in real time, including public key exchange and other information.
The ssh server consists of 2 parts:
- openssh (provides ssh service)
- openssl (program that provides encryption)
Command format
ssh [OPTIONS] [-p PORT] [USER@]HOSTNAME [COMMAND]
Working Mechanism
process:
- When the server starts, it generates a key (768bit public key).
- The local ssh client sends a connection request to the ssh server,
- The server checks the data and IP address sent by the connection point client, and sends the key (768bits) to the client after confirming it is legal.
- At this time, the client combines the local private key (256bit) and the server's public key (768bit) into a key pair key (1024bit), sends it back to the server, and establishes a connection through key-pair data transmission.
Illustration: - The remote server receives the login request from the client user TopGun, and the server sends its public key to the user.
- The Client uses this public key to encrypt the password.
- The Client sends the encrypted password to the Server.
- The remote server uses its own private key to decrypt the login password and then verifies its legitimacy.
- If the result is verified, give the Client a corresponding response.
use
Specify username and port to log in to the remote host
ssh -p3600 [email protected]
After command enter, enter the user login password to complete the login.
ssh realizes password-free login
process
The login process is as follows
Process:
- Use ssh-keygen on the client to generate a pair of keys: public key + private key;
- Append the client's public key to the server's authorized_key file to complete the public key authentication operation;
- After the authentication is completed, the client initiates a login request to the server and transfers the public key to the server;
- The server retrieves the authorized_key file to confirm whether the public key exists. If the public key exists, generate a random number R and encrypt it with the public key to generate the public key encryption string pubKey®;
- Pass the public key encrypted string to the client;
- The client uses the private key to decrypt the public key encrypted string and obtains R;
- When the server and client communicate, a session ID (sessionKey) will be generated, and MD5 is used to encrypt R and SessionKey to generate a digest;
- The client passes the generated MD5 encrypted string to the server;
- The server also generates MD5(R,SessionKey) encrypted string;
- If the encrypted string sent by the client is equal to the encrypted string generated by the server itself, the authentication is successful. At this point, there is no need to enter a password, the connection is established, and you can start executing Shell commands remotely.
accomplish
Step one:Use the ssh-keygen command to generate the RSA public key and private key on the client, and press Enter to confirm. The default names of the public and private keys are id_rsa.pub (public key) and private key (id_rsa),默认保存在 ~/.ssh 目录下
.
ssh-keygen -t rsa
Second step:Append the client public key to the server ~/.ssh/authorized_keys file. authorized_keys is the file used to store the client public key. There are three methods
- Via ssh-copy-id command
- Via scp command
- Manual copy
使用 ssh-copy-id 命令实现如下
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 3600 [email protected]
Step 3: Use ssh for password-free login
ssh -p3600 [email protected]
scp
Overview
scp is the abbreviation of secure copy, a command used to remotely copy files under Linux.
- A similar command is cp, but cp only copies locally and cannot cross servers.
- scp transmission is encrypted
- scp also consumes very little resources, does not increase the system load much, and basically does not affect the normal use of the system.
Command format:
scp [参数] [原路径] [目标路径]
use
Copy from local server to remote server
Copy files
# 指定了用户名,命令执行后需要输入用户密码
# 仅指定了远程的目录,文件名字不变
scp local_file remote_username@remote_ip:remote_folder
# 指定了文件名
scp local_file remote_username@remote_ip:remote_file
# 没有指定用户名,命令执行后需要输入用户名和密码
# 仅指定了远程的目录,文件名字不变
scp local_file remote_ip:remote_folder
# 指定了文件名
scp local_file remote_ip:remote_file
copy directory
# 指定了用户名,命令执行后需要输入用户密码
scp -r local_folder remote_username@remote_ip:remote_folder
# 没有指定用户名,命令执行后需要输入用户名和密码
scp -r local_folder remote_ip:remote_folder
Copy from remote server to local server
从远程复制到本地的scp命令与上面的命令雷同,只要将从本地复制到远程的命令后面2个参数互换顺序就行了。
Notice
If the remote server firewall has set a specified port for the scp command, we need to use the -P parameter to set the port number of the command. The command format is as follows:
#scp 命令使用端口号 4588
scp -P 4588 [email protected]:/usr/local/sin.sh /home/administrator
使用scp命令要确保使用的用户具有可读取远程服务器相应文件的权限,否则scp命令是无法起作用的。
sh
Overview
The sh command is a shell command language interpreter that executes commands to read from standard input or read from a file.
Syntax format:
sh [参数] 脚本
Common parameters
use
Execute the specified script file
[root@xx~]# sh xx.sh
/root
21:33:45 up 42 min, 1 user, load average: 0.06, 0.01, 0.00
Execute the specified script file and trace the commands one by one
[root@xx ~]# sh -x xx.sh
+ pwd
/root
+ uptime
21:33:50 up 42 min, 1 user, load average: 0.05, 0.01, 0.00
Example: jar package shell running script on linux system
启动: ./xxx.sh start
停止: ./xxx.sh stop
重启: ./xxx.sh restart
#!/bin/bash
############################### 参数区start ########################################
source ./00-set-vars.sh
#指定jdk1.8路径 /home/devSoft/jdk1.8.0_77/bin/java || java
JDK_HOME=$JAVA_HOME
#指定注册中心,多个注册中心,使用逗号分隔
EUREKA_SERVER=$EUREKA_CENTER
#指定jar包名称
JAR_NAME=jar包名称.jar
#指定程序端口号
SERVER_PORT=26069
OTHER_PARAM="指定参数,以--开头,多个参数中间空格,参考: --zuul.routes.web-crud-demo.path=/web-crud-demo/** --zuul.routes.web-crud-demo.url=http://1localhost:8080 --zuul.routes.web-crud-demo.stripPrefix=false --zuul.routes.web-crud-demo.custom-sensitive-headers=true"
############################### 参数区end ##########################################
#使用说明,用来提示输入参数
usage() {
echo "Usage: sh 脚本名.sh [start|stop|restart|status]"
exit 1
}
#检查程序是否在运行
is_exist(){
pid=`ps -ef|grep $SERVER_PORT-$JAR_NAME|grep -v grep|awk '{print $2}' `
#如果不存在返回1,存在返回0
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}
#启动方法
start(){
is_exist
if [ $? -eq "0" ]; then
echo "${SERVER_PORT}-${JAR_NAME} is already running. pid=${pid} ."
else
nohup $JDK_HOME -Xms64m -Xmx512m -D$SERVER_PORT-$JAR_NAME -jar $JAR_NAME --server.port=$SERVER_PORT $OTHER_PARAM --eureka.client.serviceUrl.defaultZone=$EUREKA_SERVER >/dev/null 2>&1 &
echo "nohup ${JDK_HOME} -D${SERVER_PORT}-${JAR_NAME} -jar ${JAR_NAME} --server.port=${SERVER_PORT} ${OTHER_PARAM} --eureka.client.serviceUrl.defaultZone=$EUREKA_SERVER >/dev/null 2>&1 & ."
echo "${SERVER_PORT}-${JAR_NAME} start success"
fi
}
#停止方法
stop(){
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
else
echo "${SERVER_PORT}-${JAR_NAME} is not running"
fi
}
#输出运行状态
status(){
is_exist
if [ $? -eq "0" ]; then
echo "${SERVER_PORT}-${JAR_NAME} is running. Pid is ${pid}"
else
echo "${SERVER_PORT}-${JAR_NAME} is NOT running."
fi
}
#重启
restart(){
stop
start
}
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac