#!/bin/bash # Date:2018/11/29 # Author: linyaohong # BLOG: ************ # Qq:122123498 # Version:1.0 # User: Centos 7 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin [ -f /etc/init.d/functions ] && . /etc/init.d/functions # set color SRED="\E[41;5m" RED="\E[31m" GREEN="\E[32m" CEND="\E[0m" user="www" rsync_passwd_file=/etc/rsync.passwd rsync_user=backup rsync_passwd=backup2018 # Check you network status NET_NUM=`ping -c 4 www.baidu.com |awk '/packet loss/{print $6}' |sed -e 's/%//'` if [ -z "$NET_NUM" ] || [ $NET_NUM -ne 0 ];then echo "Please check your internet" exit 1 fi yum -y install redhat-lsb # check_os CentOS_ver=$(lsb_release -sr | awk -F . '{print $1}') if [ ${CentOS_ver} != "7" ]; then echo "Error: You must be Centos7 to run this script" exit 1 fi # Check if user is root #[ $(id -u) != "0" ] && { echo "Error: You must be root to run this script"; exit 1; } if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script" exit 1 fi # Chenck if rsync install if [ -f /etc/rsyncd.conf ];then /bin/cp /etc/rsyncd.conf /etc/rsyncd.conf_$(date +%F) action "backup rsyncd.conf" /bin/true if [ `ps -ef|grep -w rsync|grep -v grep|wc -l` -ge "1" ];then echo -e "${RED}rsync is runing exit.please check rsync service an reruns the script ${CEDN}" exit 1 fi else yum -y install rsync action "install rsync " /bin/true fi cat >/etc/rsyncd.conf < ${rsync_passwd_file} chmod 600 ${rsync_passwd_file} [ -f /var/run/rsyncd.pid ]&& rm -rf /var/run/rsyncd.pid `which rsync` --daemon /etc/rsyncd.conf if [ `ps -ef|grep -w rsync|grep -v grep|wc -l` -ge "1" ];then echo -e "${GREEN}rsync install successfully ${CEDN}" else echo -e "${RED}rsync install failed${CEND}" exit 1 fi # iptables Ftp systemctl status firewalld >/dev/null 2>&1 if [ $? = "0" ];then firewall-cmd --permanent --zone=public --add-port=873/tcp >/dev/null 2>&1 firewall-cmd --reload >/dev/null 2>&1 echo -e "${GREEN}firewalld port open 873${CEND}" else echo -e "${RED}your firewall is closed! Please open firewalld ${CEND}" echo -e "${RED}please open 873 port${CEND}" echo -e "${GREEN}firewall-cmd --permanent --zone=public --add-port=873/tcp${CEND}" echo -e "${GREEN}firewall-cmd --reload${CEND}" fi read -p "do you want install inotify [y|n]:" option case "${option}" in y|Y) wget -O /etc/yum.repos.d/eple.repo http://mirrors.aliyun.com/repo/epel-7.repo yum -y install inotify-tools ;; n|N) echo "rsync install ok" exit 1 ;; *) echo "rsync install ok" esac