In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to use shell script to automatically switch between intranet and extranet, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
First of all, explain that our configuration files are all in a similar format. If the private network is 192.168.0.3 and the public network is 123.123.123, the configuration files are as follows:
$db ['salver'] [' hostname'] = '192.168.0.3 virtual 3306'
/ / $db ['salver'] [' hostname'] = '123.123.123.123.123purl 3306'
At this time, the public network is the status of comments. I'm on the intranet.
To talk about the train of thought, it is a configuration file, copy it out and put it somewhere else. One of these two copies is set up with an internal network and the other with an external network. If the internal network is not accessible, judge whether you are currently using an internal network or an external network. If it is an internal network, copy the configuration file of the external network to the website file. If the intranet is connected, copy the configuration file of the intranet to the website file. It is equivalent to that the internal network IP is the master and the public network IP is the backup. Put this script in the scheduled task and execute it every minute.
The code is as follows:
#! / bin/bash
# Private and public network IP of master-slave database
Master_IP_N=
Master_IP_W=
Salver_IP_N=
Salver_IP_W=
# IP of mongo's private and public networks
Mongo_IP_W=
Mongo_IP_N=
# Master-slave private and public network IP of redis
Redis_master_IP_W=
Redis_master_IP_N=
Redis_slave_IP_W=
Redis_slave_IP_N=
# IP of sphinx's private and public networks
Sphinx_IP_W=
Sphinx_IP_N=
# location of website configuration file
Database_path=/home/caoy/database.php
Mongo_path=/home/caoy/over_sea_stock.php
Redis_path=/home/caoy/Rediska_connector.php
Sphinx_path=/home/caoy/SphinxConnector.php
Config_path=/data/check_ip_config/
# detect the network card currently in use
Function check_ip () {
IP_config= `cat $1 | grep $2 | cut-C1-2`
If ["$IP_config" = = "/ /"]; then
Ip_status=1
Else
Ip_status=0
Fi
}
# determine whether the private network card is faulty
Function check_network () {
Nmap-sP $1 | grep "1 host up" > / dev/null | | (sleep 5; nmap-sP $1) | grep "1 host up" > / dev/null
# ping $1-c 5 > / dev/null
If [["$?" = = "1"]; then
Check_ip $database_path $1
If [["$ip_status" = = "0"]; then
Cp-r $config_path/database_w.php $database_path
Echo "cp database_w.php is ok!"
Fi
Check_ip $mongo_path $1
If [["$ip_status" = = "0"]; then
Cp-r $config_path/over_sea_stock_w.php $mongo_path
Echo "cp over_sea_stock_w.php is ok!"
Fi
Check_ip $redis_path $1
If [["$ip_status" = = "0"]; then
Cp-r $config_path/Rediska_connector_w.php $redis_path
Echo "cp Rediska_connector_w.php is ok!"
Fi
Check_ip $sphinx_path $1
If [["$ip_status" = = "0"]; then
Cp-r $config_path/SphinxConnector_w.php $sphinx_path
Echo "cp SphinxConnector_w.php is ok!"
Fi
Else
Check_ip $database_path $1
If [["$ip_status" = = "1"]; then
Cp-r $config_path/database_n.php $database_path
Echo "cp database_n.php is ok!"
Fi
Check_ip $mongo_path $1
If [["$ip_status" = = "1"]; then
Cp-r $config_path/over_sea_stock_n.php $mongo_path
Echo "cp over_sea_stock_n.php is ok!"
Fi
Check_ip $redis_path $1
If [["$ip_status" = = "1"]; then
Cp-r $config_path/Rediska_connector_n.php $redis_path
Echo "cp Rediska_connector_n.php is ok!"
Fi
Check_ip $sphinx_path $1
If [["$ip_status" = = "1"]; then
Cp-r $config_path/SphinxConnector_n.php $sphinx_path
Echo "cp SphinxConnector_n.php is ok!"
Fi
Fi
}
# check whether each network card is unobstructed
Check_network $master_IP_N
Check_network $salver_IP_N
Check_network $mongo_IP_N
Check_network $redis_master_IP_N
Check_network $redis_slave_IP_N
Check_network $sphinx_IP_N
The above is all the contents of the article "how to use shell script to automatically switch between intranet and extranet". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.