1、编写脚本/root/bin/backup.sh,可实现每日将/etc/目录备份到 /root/etcYYYY-mm-dd中
#!/bin/bash
echo "start backup"
sleep 2
date=`date "+%Y-%m-%d"`
cp -av /etc /root/etc$date
echo "backup finish"
2、编写脚本/root/bin/disk.sh,显示当前硬盘分区中空间利用率最大的值
#!/bin/bash
echo "disk use max :`df -h|grep ^/dev/[svm]d |tr -s " " "%"|cut -d% -f5|sort -rn|head -n1`"
3、编写脚本/root/bin/nologin.sh和login.sh,实现禁止和充许普通用户登录系统
login
#!/bin/bash
[ -f "/etc/nologin" ] && rm -rf /etc/nologin && echo "User Can Login" ||echo "User Already Login"
nologin
#!/bin/bash
[ -f "/etc/nologin" ] && echo "Other User Cannot Login System" ||{ touch /etc/nologin; echo "Other User Cannot Login System"; }
4、查找/var目录下不属于root、lp、gdm的所有文件
find /var -not ( -user root -o -user lp -o -user gdm )
5、统计/etc/init.d/functions文件中每个单词的出现次数,并排序(用grep和 sed两种方法分别实现)
sed -r "s/[^[:alpha:]]+/
/g" /etc/init.d/functions | sed "/^$/d" |sort|uniq -c
egrep -o "[[:alpha:]]+" /etc/init.d/functions|sort|uniq -c
6、利用sed 取出ifconfig命令中本机的IPv4地址
ifconfig | sed -n "2p" |sed -r "s/.*inet (.*) netmask.*/1/g"
7、总结yum的配置和使用,包括yum仓库的创建
yum install 安装
yum groupinstall 组安装
yum remove 卸载
yum groupremove 组卸载
yum list 显示所有包
yum clean all 清除缓存
yum makecache 建立缓存
yum仓库目录/etc/yum.repos.d/
[base]
name=base
baseurl=http:// ftp:// file:///
gpgcheck=1
enabled=1
8、编写系统初始化脚本reset.sh,包括别名,提示符颜色,yum仓库配置文件, 安装tree,ftp,lftp,telnet等包
#!/bin/bash
#
#********************************************************************
#Author: DreamDZhu
#QQ: 852749070
#Date: 2019-01-30
#FileName: autoInitSystem.sh
#Description: AutoInitSystem
#********************************************************************
#decide current system os
echo "Start Init System,Please Waiting Some Time~~"
sleep 2
version=`egrep -o "[0-9]" /etc/redhat-release |head -n1`
echo "Current System Version is Centos $version"
echo "Setting Alias...."
sleep 1
cat >>/root/.bashrc<<END
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias cdnet='cd /etc/sysconfig/network-scripts/'
alias IPOUT='ifconfig | egrep -o "<([[:digit:]]{1,3}.){3}[[:digit:]]{1,3}>" | head -1'
alias p='poweroff'
alias cl='clear'
`if [ "$version" -eq 7 ];then
ps1="[e[1;36m][u@h W]$[e[0m]"
elif [ "$version" -eq 6 ];then
ps1="[e[1;33m][u@h W]$[e[0m]"
else
ps1="[e[1;35m][u@h W]$[e[0m]"
fi`
PS1=$ps1
END
echo "Alias and PS1 be Ready~"
echo "Start Setting Yum Repository..."
sleep 1
#mount cd rom
mkdir /media/cdrom
mount /dev/sr0 /media/cdrom
mkdir /etc/yum.repos.d/bak
#move system Centos repo
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
cat >>/etc/yum.repos.d/bash.repo<<END
[base]
name=Centos "$version"
baseurl=file:///media/cdrom
gpgcheck=0
[epel]
name=Aliyun
baseurl=https://mirrors.aliyun.com/epel/$version/x86_64
gpgcheck=1
gpgkey=file:///media/cdrom/RPM-GPG-KEY-CentOS-$version
END
echo "Yum Repo be Ready~"
echo "Start Install Rpms"
sleep 1
yum cleanall && yum makecache
yum -y install tree && yum -y install ftp && yum -y install lftp && yum -y install telnet
echo "tree ,ftp,lftp,telnet already Install~"
if [ $version -eq 7 ];then
systemctl stop firewalld
systemctl disable firewalld
elif [ $version -eq 6 ];then
service iptables stop
chkconfig iptables off
else
echo "Please Manual Stop Firewall"
echo "Init System Over"
9、在CentOS7上编译安装apache2.4源码包,并启动此服务
./configure --help 可以查看这个程序源码的可改编译选项
解压四个包
tar xvf apr-1.4.5.tar.gz
tar xvf apr-util-1.3.12.tar.bz2
tar xvf httpd-2.4.33.tar.bz2
tar xvf pcre-8.10.tar.gz
先编译apr依赖包
mkdir -p /usr/local/apr
cd /data/apr-1.4.5/
./configure --prefix=/usr/local/apr
make -j 2 && make install
再编译apr-util
mkdir -p /usr/local/apr-util
cd apr-util-1.3.12/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make -j 2 && make install
编译安装pcre依赖包
mkdir -p /usr/local/pcre
cd /data/pcre-8.10/
./configure --prefix=/usr/local/pcre
make -j 2 && make install
最后编译安装http
mkdir /app
mkdir /etc/httpd24
./configure --prefix=/app --sysconfdir=/etc/httpd24 --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util (--disable-proxy)
make -j 4 && install
由于我们安装在app,所以需要手动开启,或者配置PATH
/app/bin/apachectl start
安装时要注意配置文件的路径!!!
编译错误解决
基于Make工具编译软件;
n Make编译报错信息如下:
mod_proxy_balancer.c:25:24: fatal error: apr_escape.h: No such file or directory,#include "apr_escape.h"
`/data/sh/20180330/httpd-2.4.33/modules/proxy'
make[2]: *** [shared-build-recursive] Error 1
解决方法:
l 跳过该错误,后期指定该模块,一般安装不成功,推荐解决该问题;
l 或者编译参数可以去掉该模块,禁止该模块,添加--disable-proxy;
l 更换软件版本,考虑到操作系统和软件兼容性问题;