第四周作业2019-07-16

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

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

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

grep -o' [[:alpha:]]\+ '/etc/init.d/functions| sort | uniq -csed -r's@[^[:alpha:]]+@\n@g'/etc/init.d/functions| sort | uniq -c| sort -n

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

ifconfig | sed -n'/inet .* netmask/p'| sed -n -r's/inet (.*) netmask.*$/\1/p'| head -1

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

配置自己的yum仓库来实现yum安装在/etc/yum.repo/目录中新建一个以.repo后缀中的文件指定本机yum安装路径通常分四种

http:// https:// ftp:// file:// 前三中为网络路径 file为本地路径

一、挂载光盘到目录

lsblk

mkdir /data/base

mount /der/sr0 /data/base/

二、创建修改 /etc/yum.repos.d/base.repo文件

配置本地的yum路径将本地路径指向本地yum源就可以使用了

[base]name=cdrom repo 软件仓库指定名字baseurl=file://data/base 指定路径指向本地挂载光盘gogcheck=0包校验0为不校验1为校验

也可配置将路径指向网络中的yum仓库

[base]name=cdrom repo 软件仓库指定名字baseurl=https://mirrors.aliyun.com/epel/7/x86_64/ 指定路径指向网络中的yum仓库gogcheck=0包校验0为不校验1为校验

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

#!/bin/bash##********************************************************************#Author: DreamDZhu#QQ: 852749070#Date: 2019-01-30#FileName: autoInitSystem.sh#Description: AutoInitSystem#********************************************************************#decide current system osecho "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<

PS1=$ps1ENDecho "Alias and PS1 be Ready~"echo "Start Setting Yum Repository..."sleep 1#mount cd rommkdir /media/cdrom

mount /dev/sr0 /media/cdrom

mkdir /etc/yum.repos.d/bak#move system Centos repomv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak

cat >>/etc/yum.repos.d/bash.repo<

[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-$versionENDecho "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 telnetecho "tree ,ftp,lftp,telnet already Install~"if [ $version -eq 7 ];then    systemctl stop firewalld

    systemctl disable firewalldelif [ $version -eq 6 ];then    service iptables stop

    chkconfig iptables offelse    echo "Please Manual Stop Firewall"echo "Init System Over"

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

yum install tree ftp lftp telnet

7,centos7上编译安装apache2.4源码包并启动此程序

一、准备工作

在进行编译安装前均需要安装相关的依赖软件包,如:

yum install -y gcc gcc++ zlib zlib-devel expat-devel pcre-devel

随后使用wget命令下载相应的源码包到指定的目录:

httpd:http://mirrors.shu.edu.cn/apache//httpd/httpd-2.4.29.tar.gz

apr:http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz

apr-util:http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz

在做完相应的准备工作后,可以开始编译安装的过程了。

二、编译安装

在编译安装httpd的源码包之前,我们得下编译安装apr和apr-until这两个对应源码包。

1、安装apr

[root@localhost tmp]# tar xf apr-1.6.3.tar.gz    [root@localhost tmp]# cd apr-1.6.3[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr[root@localhost apr-1.6.3]# make && make install

2、安装apr-util

[root@localhost tmp]# tar xf apr-util-1.6.1.tar.gz [root@localhost tmp]# cd apr-util-1.6.1[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr[root@localhost apr-util-1.6.1]# make && make install

3、安装httpd

[root@localhost tmp]# tar xf httpd-2.4.29.tar.gz [root@localhost tmp]# cd httpd-2.4.29[root@localhost httpd-2.4.29]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util[root@localhost httpd-2.4.29]# make && make install

三、编译安装完成后的工作

1、启动Apache

[root@localhost ~]# cd /usr/local/apache/bin/[root@localhost bin]# ./apachectl start

需要编辑/usr/local/apache/conf/httpd.conf文件中找到#ServerName www.example.com:80并在其下方添加:ServerName localhost:80。

2、修改iptables允许访问80端口

通过情况下,Linux系统的iptables 会拒绝任何访问到80端口的流量,此时可以通过使用iptables添加对应的访问规则来允许对应的流量。

[root@localhost ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT[root@localhost ~]# service iptables saveiptables:Saving firewall rules to /etc/sysconfig/iptables:[  确定  ]

如果系统无法找到service iptables save命令,需先yum安装iptables-service。

另外也可以停用iptables:

[root@localhost ~]# systemctl stop firewalld      #临时停用firewalld[root@localhost ~]# systemctl disable firewalld  #关闭开机自动开启firewalldRemoved symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

3、设置开机自动开启apache

首先将/usr/local/apache/bin/apachectl 复制到/etc/init.d/目录下。

[root@localhost ~]# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/

随后编辑/etc/rc.d/init.d/apachectl,在首行#!/bin/sh下添加下面两句命令:

#chkconfig: 234 20 80#escription: apache

随后用chkconfig命令将apachectl添加到系统服务并设置开机启动:

[root@localhost ~]# chkconfig --add apachectlroot@localhost ~]# chkconfig apachectl on

此时使用systemctl命令就能正常管理到apachectl服务了:

[root@localhost ~]# systemctl status apachectl● apachectl.service -SYSV:apacheLoaded:loaded (/etc/rc.d/init.d/apachectl)Active:active (exited) since 五2018-01-0505:14:59CST;5s agoDocs:man:systemd-sysv-generator(8)Process:66466ExecStart=/etc/rc.d/init.d/apachectl start (code=exited, status=0/SUCCESS)1月0505:14:59localhost.localdomain systemd[1]: StartingSYSV:apache...1月0505:14:59localhost.localdomain apachectl[66466]: httpd (pid64222) already running1月0505:14:59localhost.localdomain systemd[1]: StartedSYSV:apache.[root@localhost ~]#

你可能感兴趣的:(第四周作业2019-07-16)