N-Taiwan linux server to transfer large files

1. The public and private keys server to establish a trust relationship with the client. As the original file server to storage, ansible host .
1.1. Creating public on ansible host.
1024-keygen -t -b SSH rsa
[root @ Server ~] # SSH-keygen -b 1024 -t rsa
Generating public / Private Key pair rsa. # prompt being generated rsa key pair
Enter file in which to save the key ( /home/usrname/.ssh/id_dsa): # asking where public and private keys stored, enter the default location to
enter passphrase (empty for no passphrase) : # inquiry enter the private key passphrase, enter the passphrase (here enter the $ qt is 2Hbl)
the enter passphrase Same, again: # again prompted for a passphrase confirmation
Your identification has been saved in /home/usrname/.ssh/id_dsa # prompt public and private keys have been stored in /root/.ssh/. directory
Your public /home/usrname/.ssh/id_dsa.pub Key has been saved in.
of the Key Fingerprint IS:
X6: 68: XX: 93: 98: 8x: 87: 95: 7x: 2x: 4x: X9: 81: XX: 56 is: 94
-b length of 1024 bytes 1024 using public / private key pair
-t rsa rsa encryption using public / private key pair
Some people say that using a login password phrase, but also use a password to log phrase is not much easier than using the user name and password. It is not true .
1.2 transmitting the public key to the remote host, the command: sshpass -p 'password remote hosts' IP ssh the root @ -o-Copy-ID NO StrictHostKeyChecking =
1.3 ssh how to avoid IP connection to a remote host, then enter a passphrase

(This is generally common in the cloud server management, network host computer to the fortress ssh connection, but each with a host passphrase is too much trouble, using the following manner)

Eval command runs automatically declared environmental variables. eval ssh-agentSSH environment variable environment variables to join the current session.
ssh-add to add a private key to ssh-agent's cache. Prompted for a passphrase, enter it.
In the current environment variables can be directly ssh to connect to remote host. Exit the current shell when, ssh-agent also quit. When the next connection, you can re-eval.

2. The definition of the relevant script
idea: based on the first step, to establish a ansible host to each client relationship of trust, run tracker file services, generate large .torrent file, the file package distribution needs seeding, the final definition of the client download file script.
2.1 First define two directories: store large files in the directory / opt / data /; custom scripts directory / opt / App /
seeder.conf 2.2 modify configuration files in / opt / app / murder contents.

Large File #
deploy_file = / opt / Data / update_v0.27-91-2
# to generate torrent file storage address, in the corresponding directory ansible.
= torrent_file / etc / ansible / the Roles / Update / Files / update_v0.27-91-2.torrent
#tracker services, other members rely Tracker
tracker_ip = 21.0.0.153: 8998
local_ip = 21.0.0.153

2.3 /opt/app/murder/murder_tracker.sh definition, start.

#/bin/sh
name="murder-tracker"
murder_tracker_bin="/opt/app/murder/murder-master/dist/murder_tracker.py"
murder_tracker_log="/opt/log/murder/murder_tracker.log"
murder_tracker_data="/opt/data/murder/tracker_data"

find_tracker_process(){
  PID=`ps -ef |grep murder_tracker|grep python |grep -v $0|grep -v grep |grep -v sh|awk '{print $2}'`

}
start(){
    LOG_DIR=`dirname $murder_tracker_log`
    DATA_DIR=`dirname $murder_tracker_data`
    if [ ! -d $LOG_DIR ];then
         #echo -e "\e[35mlog dir $LOG_DIR doesn't exist,creating\e[0m"
         printf "log dir $LOG_DIR doesn't exist,creating...\n"
         mkdir -p $LOG_DIR
    fi
        if [ ! -d $DATA_DIR ];then
             printf "data dir $DATA_DIR doesn't exist,creating...\n"
         mkdir -p $DATA_DIR 
        fi
        find_tracker_process
    echo $PID
        if [ "$PID" != "" ]; then
         printf  "$name is already running...\n"
    else
          python $murder_tracker_bin > /dev/null 2>&1 &
          printf  "starting $name done....\n"
    fi

}

stop(){
    if [ `netstat -lnpt |grep 8998 |wc -l` -eq 1 ];then
        find_tracker_process
        kill $PID
        printf "stoping $name done...\n"
    else
        printf "$name is already stopping...\n"
    fi 
}

restart(){

    stop
    sleep 2
    start
}

case $1 in
start)
        start
        ;;
stop)
        stop
        ;;
restart)
        restart
        ;;
*)
        printf "Usage: $0 {start|stop|restart}\n"
esac

exit

2.4 /opt/app/murder/murder_seeder.sh definition, start.

#!/bin/sh
name="murder-seeder"
muder_seeder_data="/opt/data/murder"
muder_seeder_log="/opt/log/murder/muder_seeder.log"
murder_make_torrent_bin="/opt/app/murder/murder-master/dist/murder_make_torrent.py"
murder_seeder_bin="/opt/app/murder/murder-master/dist/murder_client.py"
seeder_conf_path="/opt/app/murder/seeder.conf"

deploy_file=$(awk -F= '/deploy_file/{print $2}' $seeder_conf_path)
torrent_file=$(awk -F= '/torrent_file/{print $2}' $seeder_conf_path)
tracker_ip=$(awk -F= '/tracker_ip/{print $2}' $seeder_conf_path)
local_ip=$(awk -F= '/local_ip/{print $2}' $seeder_conf_path)
#echo $murder_make_torrent_bin  $deploy_file   $tracker_ip  $torrent_file

find_seed_process(){
    PID=`ps -ef |grep murder_client|grep seed |grep -v $0|grep -v grep |grep -v sh|awk '{print $2}'`
}

start(){
    #make torrent
    python $murder_make_torrent_bin  $deploy_file  $tracker_ip   $torrent_file
    #echo $?
        if [ $? != 0 ];then 
           python $muder_make_torrent_bin $deploy_file  $tracker_ip   $torrent_file
        fi

    find_seed_process
        #echo $PID
        if [ "$PID" != "" ]; then
               printf  "$name is already running...\n"
        else
           python $murder_seeder_bin seed $torrent_file $deploy_file $local_ip >/dev/null 2>&1 &
               printf  "starting $name done....\n"
        fi
}

stop(){
    find_seed_process
        if [ $PID != "" ];then
            kill $PID
            printf "stoping $name done...\n"
        else
            printf "$name is already stopping...\n"
        fi  
}

restart(){

        stop
        sleep 2
        start
}

case $1 in
start)
        start
        ;;  
stop)
        stop
        ;;  
restart)
        restart
        ;;  
*)
        printf "Usage: $0 {start|stop|restart}\n"
esac
exit

2.5

Guess you like

Origin blog.51cto.com/12191723/2432761
Recommended