Linux Basic work article

Source: Internet
Author: User

1. Automatic deployment of reverse Proxy web NFS

#!/usr/bin/python#-*-coding:utf-8-*-#automated deployment and monitoring of development scripts#1. Scripting automatic deployment of reverse proxy, web, NFS;#!/bin/bash#Detect installation Nginxfunction Detection_nginx () {if[-f/etc/nginx/nginx.conf]#determine if the Nginx file existsThen Echo'Nginx has been installed'ExitElseThen yum Install Epel-release-y yum install nginx-y Echo'Nginx already installed'fi}#Overwrite configuration filefunction modify_nginx_conf () {msg='upstream pythonweb{server 192.168.205.129 weight=3;server 192.168.205.129;server 192.168.205.129}'sed-ri"/^http/a $msg"/etc/nginx/nginx.conf#Increase upstreamSed-ri"/^ *location \ \{$/a proxy_pass http://pythonweb\;"/etc/nginx/nginx.conf#Modify Localtion}systemctl Reload Nginx#Reload Nginx#Detect and install NFS and Rpcbindfunction Detection_nfs () {if[-d/var/lib/NFS] then echo'NFS has been installed'ExitElseThen yum Install rpcbind NFS-utils-y Echo'rpcbind nfs-utils already installed'fi}function Start_service () {#Create a shared directorymkdir/Share#Add Write permissions to the userChmod-r o+w/share/#Overwrite the NFS configuration fileEcho'/share 192.168.205.0/24 (rw,sync,fsid=0)'>>/etc/exports#write in Append mode    #Start the servicesystemctl start rpcbind.server systemctl start NFS-Utils.server#Set boot upSystemctl Enable nfs-server.service systemctl Enable Rpcbind.service}detection_nginx#perform the instrumentation installation Nginx functionModify_nginx_conf#perform the overwrite nginx.conf functionDetection_nfs#Perform a Detection install NFS functionStart_service#executing the start service function
View Code

2. Monitor the memory of the host and send alarm messages if the threshold is exceeded

#!/usr/bin/python#-*-coding:utf-8-*-title: Monitoring the Memory of the host, exceeding the threshold to send alarm messages1. Prepare code to send mail#!/usr/bin/python#-*-coding:utf-8-*-ImportSYSImportSmtplibImportEmail.mime.multipartImportEmail.mime.textserver='smtp.163.com'Port=' -'defSendMail (server,port,user,pwd,msg): SMTP=Smtplib. SMTP () smtp.connect (server,port) smtp.login (user, PWD) smtp.sendmail (msg[' from'], msg[' to'], msg.as_string ()) Smtp.quit ()Print('Mail sent successfully email has send out!')if __name__=='__main__': Msg=Email.mime.multipart.MIMEMultipart () msg['Subject'] ='you are the wind, I am the sand, wrapped around my home'msg[' from'] ='[email protected]'msg[' to'] ='[email protected]'User='Python4_mail'pwd='sbalex3714'content='%s\n%s'%('\ n'. Join (Sys.argv[1:4]),' '. Join (Sys.argv[4:]))#format processing, specifically for our message formattxt= Email.mime.text.MIMEText (Content, _charset='Utf-8') Msg.attach (TXT) sendmail (server,port,user,pwd,msg)#Put the above code in the/usr/bin/my_mailVim/usr/bin/my_mail#Copy the code inside .chmod +x My_mail#permissions that can be performed on a file My_mail2. Create my own script monitoring file 15.sh#!/bin/bashMen = 0#memory usage over 0% will alert you .function Monitor_mem () {mem_total='Free | awk'nr==2{Print$/$}"'                                             "'Mem_use='Free | awk'nr==2{Print$-$}"'Mem_per='echo "scale=2; $mem _use/$mem _total" |bc-l |cut-d.-f2'    if[$mem _per-GT $ mem] then msg='time:$ (date +%f_%t)'hostnam:$ (hostname) ipaddr:$ (ifconfig| Awk'Nr==2{print $}') echo $msg/usr/bin/my_mail $mag fi}#3. Writing a scheduled taskcrontab-E-u root* * * * * */root/home/gandong/15.sh restart#test every Minute
View Code

Linux Basic work article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.