第四周作业

1.查找/var目录不属于root,lp,gdm的所有文件

find /var ! \( -user root -o -user lp -o -user gdm \)
find /var -not -user root -a -not -user lp -a -not -user gdm

2.统计/etc/init.d/functions文件中每个单词的出现次数,并排序(用grep和sed两种方法分别实现)

grep -E -o "[[:alpha:]]+" /etc/init.d/functions |sort|uniq -c|sort -rn
egrep -o "[[:alpha:]]+" /etc/init.d/functions |sort|uniq -c|sort -rn

sed -r "s#[^[:alpha:]]+#\n#g" /etc/init.d/functions |sort|uniq -c|sort -rn

3.利用sed取出ifconfig命令中本机的IPv4地址

ifconfig|sed -rn "s/.*inet (addr:)?([^ ]+).*/\2/p"
ifconfig eth0|sed -rn "2s/.*inet (.*) net.*/\1/p"
ifconfig eth0|sed -rn "2s/.*inet (addr:)?([^ ]+).*/\2/p"

4.总结yum的配置和使用,包括yum仓库的创建

    YUM: Yellowdog Update Modifier,rpm的前端程序,可解决软件包相关依赖性,可在多个库之间定位软件包,up2date的替代工具
    yum repository: yum repo,存储了众多rpm包,以及包的相关的元数据文件(放置于特定目录repodata下)
    客户端配置文件指定对应服务器访问方式如下几种
       http://
       https://
       ftp://
       file://

    YUM的主配置 /etc/yum.conf
    YUM仓库配置 /etc/yum.repos.d/*.repo

配置本地YUM源:
	移除/etc/yum.repos.d/*.repo下文件
	挂载光盘,并找到光盘的repodata路径,该文件夹的上一级目录就是yum的目录
	vim /etc/yum.repos.d/local.repo
		[yumname]                                # 名称,不能有空格
		name=local yum                           # yum仓库的名字
		baseurl=file:///mnt/                     # repoodata的上一级目录
		gpgcheck=0                               # 忽略检查    
搭建基于http的yum本地仓库服务器
	1.安装httpd服务
	2.设置yum路径为http路径
		mkdir -p /var/www/html/centos/{6,7}/os/x86_64/
	3.把安装光盘目录挂载到以上目录
		mount /dev/cdrom /var/www/html/centos/7/os/x86_64/
	4.修改repo文件
		baseurl=http://10.0.0.201/centos/$releasever/os/$basearch/   
	5.另一种写法
		在/var/www/html/下新建repo.txt文件
		repo.txt文件中添加
			mirrorlist=http://10.0.0.201/repo.txt
			file:///mnt/
			http://10.0.0.201/centos/$releasever/os/$basearch/        
自建yum仓库
	1.创建db目录
		mkdir /data/repodb
	2.复制rpm包到db目录
		cp /mnt/Packages/tree-1.6.repo /data/repodb
	3.使用createrepo命令创建
		createrepo /data/repodb/
	4.在/etc/yum.repo.d/下.repo中添加路径
            vim /etc/yum.repos.d/test.repo
                [test]
                name=test                               #yum仓库的名字
                baseurl=file:///yum/repo                #仓库路径,由于是放在本地的只能用file协议而不是http
                enabled=1                               #开启该仓库
                gpgcheck=0                              #忽略检查
    
YUM命令总结
	yum install                                     # 安装
	yum remove                                      # 卸载
	yum groupinstall                                # 组安装
	yum groupremove                                 # 组卸载
	yum list                                        # 显示所有包
	yum clean all                                   # 清除缓存
	yum makecache                                   # 建立缓存
        yum history                                     # YUM安装历史
	yum history undo 序号                            # 通过历史撤销
	yum history redo 序号                            # 通过历史取消撤销操作
        yum provides                                    # 反向查询命令属于哪个yum包    

5.编写系统初始化脚本reset.sh,包括别名,提示符颜色,yum仓库配置文件

#!/bin/bash
#
#********************************************************************
#Author:		li
#QQ: 			12345678
#Date: 			2019-07-16
#FileName:		reset.sh
#URL: 			http://www.magedu.com
#Description:		The test script
#Copyright (C): 	2019 All rights reserved
#********************************************************************

echo "System Initialization"
version=`egrep -o "[0-9]" /etc/redhat-release |head -n1`
echo "Version is Centos $version"
echo "Setting Alias...."
cat >>/root/.bashrc<<EOF
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias cdnet='cd /etc/sysconfig/network-scripts/'
alias ipadd='ifconfig | egrep -o "\<([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}\>" | head -1'
alias pw='poweroff'
EOF

if [ "$version" -eq 7 ];then
echo PS1='"\[\e[1;36m\][\u@\h \W]\$\[\e[0m\]"' > /etc/profile.d/env.sh
elif [ "$version" -eq 6 ];then
echo PS1='"\[\e[1;33m\][\u@\h \W]\$\[\e[0m\]"' > /etc/profile.d/env.sh
else
echo PS1='"\[\e[1;35m\][\u@\h \W]\$\[\e[0m\]"' > /etc/profile.d/env.sh
fi

#mount cdrom
mkdir /media/cdrom &>/dev/null
mount /dev/cdrom /media/cdrom &>/dev/null
mkdir /etc/yum.repos.d/bak &>/dev/null
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak &>/dev/null
cat >>/etc/yum.repos.d/bash.repo<<EOF
[localyum]
name=Local YUM 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
EOF
yum clean all && yum makecache &>/dev/null
yum -y install tree lrzsz autofs &>/dev/null

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*

if [ $version -eq 7 ];then
systemctl enable autofs
systemctl start autofs
systemctl stop firewalld
systemctl disable firewalld
elif [ $version -eq 6 ];then
service autofs on
sercice autofs start
service iptables stop
chkconfig iptables off
else
echo "Please Manual Stop Firewall"
fi

echo "Disable SELinux"
sleep 1
sed -i "s#^SELINUX=.*#SELINUX=disabled#g" /etc/selinux/config
setenforce 0
echo "System Initialization Complete"

6.安装tree,ftp,lftp,telnet等包

yum install -y tree ftp lftp telnet 

7.在Centos7上编译安装apache2.4源码包,并启动服务

1.安装开发工具包
    yum groupinstall -y "development tools"
2.下载并解压源码包
    tar xf httpd-2.4.37.tar.bz2 -C /data
3.进到解压后的目录
4.创建用户
    useradd -r -u 666 -d /data/www/ -s /sbin/nologin apache
5.编译
    ./configure --prefix=/app/apache --sysconfdir=/etc/httpd24
    make -j4
6.根据提示,安装所需依赖包
    yum install -y apr-devel apr-util pcre-devel 
7.安装
    make install
8.设置环境变量
    echo 'PATH=/app/apache/bin:$PATH' > /etc/profile.d/httpd.sh
9.添加man帮助路径到环境变量
    vim /etc/man_db.conf	(C6 /etc/man.config)
        23 MANDATORY_MANPATH                       /app/apache/man
10.启动服务
    /app/bin/apachectl start

  

posted @ 2019-07-15 18:22  李卓航  阅读(204)  评论(0编辑  收藏  举报