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 > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1 、 list_sys_status.sh
Displays the following information used by the system:
Hostname, IP address, subnet mask, gateway, DNS server IP address information
#! / bin/bash
IP= `ifconfig eth0 | head-2 | tail-1 | awk'{print $2}'| awk-F ":"'{print $2}'`
ZW= `ifconfig eth0 | head-2 | tail-1 | awk'{print $3}'| awk-F ":"'{print $2}'`
GW= `route-n | tail-1 | awk'{print $2}'`
HN= `hostname`
DNS= `head-1 / etc/resolv.conf | awk'{print $2}'`
Echo 'this machine's IP address is' $IP
Echo 'the subnet mask of this machine is' $ZW
Echo 'this gateway is' $GW
Echo 'this hostname is' $HN
Echo 'this machine DNS is' $DNS
2. Mysqlbak.sh backup database directory script
#! / bin/bash
DAY= `date +% Y% m% d`
SIZE= `du-sh / var/lib/ mysql`
Echo "Date: $DAY" > > / tmp/dbinfo.txt
Echo "Data Size: $SIZE" > > / tmp/dbinfo.txt
Cd / opt/dbbak & > / dev/null | | mkdir / opt/dbbak
Tar zcf / opt/dbbak/mysqlbak-$ {DAY} .tar.gz / var/lib/mysql / tmp/dbinfo.txt & > / dev/null
Rm-f / tmp/dbinfo.txt
Crontab-e
55 23 * / 3 * / opt/dbbak/dbbak.sh
3. Make a full backup of the webdb library on the database server at 23:30 every Sunday.
Save each file to the / mysqlbak directory of the system
Use the system date as the backup file name webdb-YYYY-mm-dd.sql
Generate a new binlog log after each full backup
Back up all current binlog logs to the / mysqlbinlog directory
# mkdir / mysqlbak
# mkdir / mysqlbinlog
# service mysqld start
Cd / shell
# vi webdb.sh
#! / bin/bash
Day= `date +% F`
Mysqldump-hlocalhost-uroot-p123 webdb > / mysqlbak/webdb-$ {day} .sql
Mysql-hlocalhost-uroot-p-e "flush logs"
Tar zcf / mysqlbinlog.tar.gz / var/lib/mysql/mysqld-bin.0*
# chmod + x webdb.sh
# crontab-e
30 23 * 7 / shell/webdb.sh
4. Very.ser.sh (check the running status of any service)
Check only the status of any one of the services vsftpd httpd sshd crond or mysql
If it is not one of the five services, prompt the user to check the name of the service and exit the script
If the service is running, output "service name is running"
Start the service if the service is not running
Method 1: write a script using read
#! / bin/bash
Read-p "Please enter your service name:" service
If [$service! = 'crond'-a $service! =' httpd'-a $service! = 'sshd'-a $service! =' mysqld'-a $service! = 'vsftpd']; then
Echo "can only check 'vsftpd,httpd,crond,mysqld,sshd"
Exit 5
Fi
Service $service status & > / dev/null
If [$?-eq 0]; thhen
Echo "Service online"
Else
Service $service start
Fi
Or
Method 2: use location variables to write scripts
If [- z $1]; then
Echo "You mast specify a servername!"
Echo "Usage: `basename$ 0` servername"
Exit 2
Fi
If [$1 = = "crond"] | | [$1 = = "mysql"] | | [$1 = = "sshd"] | | [$1 = = "httpd"] | | [$1 = = "vsftpd"]; then
Service $1 status & > / dev/null
If [$?-eq 0]; then
Echo "$1 is running"
Else
Service $1 start
Fi
Else
Echo "Usage: `basename $0` server name"
Echo "But only check for vsftpd httpd sshd crond mysqld" & & exit2
Fi
5 、 pc_noline.sh
Output the ip address of the online host in the 24 network segment of 192.168.1.0.
Count the number of offline hosts
And save the ip address of the offline host and the time when it is not online to the / tmp/ip.txt file.
#! / bin/bash
Ip=192.168.1.
Jroom0
For i in `seq 10 12`
Do
Ping-c 3$ ip$i & > / dev/null
If [$?-eq 0]; then
The hosts of echo online are: $ip$i
Else
Let jacks +
Echo $ip$i > > / tmp/ip.txt
Date > > / tmp/ip.txt
Fi
Done
The number of hosts where echo is not online is $j.
6. A simple test script for website forums
Use interactive input method to automatically log in to the forum database and change the user password
[root@test1 scripts] # vim input.sh
#! / bin/bash
End=ucenter_members
MYsql=/home/lnmp/mysql/bin/mysql
Read-p "Enter a website directory:" webdir
WebPath=/home/WebSer/$webdir/config
Echo $WebPath
Read-p "Enter dbuser name:" dbuser
Echo $dbuser
Read-sp "Enter dbuser password:" dbpass
Read-p "Enter dbname:" dbname
Echo $dbname
Read-p "Enter dbtablepre:" dbtablepre
Echo $dbtablepre
Globalphp= `grep "tablepre*" $WebPath/config_global.php | cut-d "'"-f8`
Ucenterphp= `grep "UC_DBTABLEPRE*" $WebPath/config_ucenter.php | cut-d'.'- f2 | awk-F "'{print $1}'`
If [$dbtablepre = = $Globalphp] & & [$dbtablepre = = $Ucenterphp]; then
Start=$dbtablepre
Pre= `echo $Start$ End`
Read-p "Enter you name:" userset
Echo $userset
Result= `$ MYsql-u$dbuser-p$dbpass $dbname-e "select username from $Pre where username='$userset'\ G" | cut-d'- f2 | tail-1`
Echo $Result
If [$userset = = $Result]; then
Read-p "Enter your password:" userpass
Passnew= `echo-n $userpass | openssl md5 | cut-d'- f2`
$MYsql-u$dbuser-p$dbpass $dbname-e "update $Pre set password='$passnew' where username='$userset';"
$MYsql-u$dbuser-p$dbpass $dbname-e "flush privileges;"
Else
Echo "$userset is not right user!"
Exit 1
Fi
Else
Exit 2
Fi
7. Slave_status.sh (check the status of the slave database server in the mysql master-slave structure)
1) whether the local database service is running
2) can you communicate with the main database server normally?
3) can you use authorized users to connect to the database server
4) whether the native slave_IO process is in YES state
Whether the native slave_SQL process is in YES state
[root@test1 scripts] # vim test.sh
#! / bin/bash
Netstat-tulnp | grep: 3306 > / dev/null
If [$?-eq 0]; then
Echo "Service is running"
Else
Service mysqld start
Fi
Ping-c 3 192.168.1.100 & > / dev/null
If [$?-eq 0]; then
Echo "Network connection is normal"
Else
Echo "Network connection failed"
Fi
Mysql-h292.168.1.100-uroot-p123456 & > / dev/null
If [$?-eq 0]; then
Echo "Database connection successful"
Else
Echo "Database connection failed"
Fi
IO= mysql-uroot-p123-e "show slave status\ G" | grep Slave_IO_Running | awk'{print $2}'> / dev/null
SQL= mysql-uroot-p123-e "show slave status\ G" | grep Slave_SQL_Running | awk'{print $2}'/ dev/null
If [IO==Yes] & & [SQL==Yes]; then
Echo "IO and SQL connection successful"
Else
Echo "IO thread and SQL thread connection failed"
Fi
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.