筛选命令、yum和编译源码

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

[root@centos7 ~]#find /var ! \( -user root -o -user lp -o -user gdm \)

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

[root@centos7 ~]#cat /etc/init.d/functions | sed -r 's@[^[:alpha:]]+@\n@g'|sort |uniq -c |sort -n
[root@centos7 ~]#cat /etc/init.d/functions | grep -o '[[:alpha:]]*'|sort |uniq -c|sort -n

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

[root@centos7 ~]#ifconfig  | sed -nr '2s/.*inet (addr:)?([^ ]+).*/\2/p'
[root@centos7 ~]#ifconfig |sed -nr '2s/[^0-9]+([.0-9]+).*/\1/p'

4、总结yum的配置和使用,包括yum仓库的创建
yum(全称为 Yellow dog Updater, Modified)是rhel系列系统上rpm包管理器的前端工具;基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。
yum支持的服务器有两种:一种是ftp服务器,第二种是http服务器;
使用yum:
首先要有yum工具;
第二,要有yum仓库的配置文件;
第三,yum仓库要存在,或自建yum仓库;
yum仓库称为yum repository:yum repo
存储了众多的rpm包,以及包的相关的元数据文件(放置于特定目录下:repodata目录);
yum是C/S架构,是rpm的前端工具,依赖于rpm存在的;
yum客户端:
配置文件:
/etc/yum.conf:
主配置文件,为所有仓库提供公共配置或不属于仓库的配置;
一个yum客户端可以指向一个或n个仓库(如一个仓库存储的是基本程序包,一个仓库存储的是扩展程序包,一个仓库存储是第三方程序包),当安装程序包时,yum同时分析多个仓库,从中找出版本最新的安装,同一类仓库可以使用多个镜像,不同类的仓库可以同时指向n个,yum同时指向多个,当多个仓库中都存在某个程序包且版本都一样,则要使用自定义的cost开销,从而优先使用自定义的仓库;
/etc/yum.repos.d/*.repo:
多个repo文件用来指向多仓库的配置文件,为仓库的指向提供配置信息;
一个repo文件也可以定义多个仓库,没必要切分成多个,只不过为了便于管理切割成了多个repo,只要文件不以.repo结尾,就不会被yum所使用;

yum命令的用法:
    yum [options] [command] [package ...]

        command is one of:
        * install package1 [package2] [...]
        * update [package1] [package2] [...]
        * update-to [package1] [package2] [...]
        * check-update
        * upgrade [package1] [package2] [...]
        * upgrade-to [package1] [package2] [...]
        * distribution-synchronization [package1] [package2] [...]
        * remove | erase package1 [package2] [...]
        * list [...]
        * info [...]
        * provides | whatprovides feature1 [feature2] [...]
        * clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
        * makecache
        * groupinstall group1 [group2] [...]
        * groupupdate group1 [group2] [...]
        * grouplist [hidden] [groupwildcard] [...]
        * groupremove group1 [group2] [...]
        * groupinfo group1 [...]
        * search string1 [string2] [...]
        * shell [filename]
        * resolvedep dep1 [dep2] [...]
        * localinstall rpmfile1 [rpmfile2] [...]
           (maintained for legacy reasons only - use install)
        * localupdate rpmfile1 [rpmfile2] [...]
           (maintained for legacy reasons only - use update)
        * reinstall package1 [package2] [...]
        * downgrade package1 [package2] [...]
        * deplist package1 [package2] [...]
        * repolist [all|enabled|disabled]
        * version [ all | installed | available | group-* |  nogroups*  |  grouplist  |
       groupinfo ]
              *      history      [info|list|packages-list|packages-info|summary|addon-
       info|redo|undo|rollback|new|sync|stats]
        * load-transaction [txfile]
        * check
        * help [command]
        * clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
        * makecache
        * groupinstall group1 [group2] [...]
        * groupupdate group1 [group2] [...]
        * grouplist [hidden] [groupwildcard] [...]
        * groupremove group1 [group2] [...]
        * groupinfo group1 [...]
        * search string1 [string2] [...]
        * shell [filename]
        * resolvedep dep1 [dep2] [...]
        * localinstall rpmfile1 [rpmfile2] [...]
           (maintained for legacy reasons only - use install)
        * localupdate rpmfile1 [rpmfile2] [...]
           (maintained for legacy reasons only - use update)
        * reinstall package1 [package2] [...]
        * downgrade package1 [package2] [...]
        * deplist package1 [package2] [...]
        * repolist [all|enabled|disabled]
        * version [ all | installed | available | group-* |  nogroups*  |  grouplist  |
       groupinfo ]
              *      history      [info|list|packages-list|packages-info|summary|addon-
       info|redo|undo|rollback|new|sync|stats]
        * load-transaction [txfile]
        * check
        * help [command]
显示仓库列表:
    yum repolist [all|enabled|disabled]
        all:显示所有仓库;
        enabled:仅显示启用的仓库;(默认)
        disabled:仅显示禁用的仓库;
    用法:
        ]# yum repolist

    yum install 安装
    yum groupinstall 组安装
    yum remove 卸载
    yum groupremove 组卸载
    yum list 显示所有包
    yum clean all 清除缓存
    yum makecache 建立缓存
    yum仓库目录/etc/yum.repos.d/

CentOS7.6搭建本地yum库:

[root@localhost ~]# df
    Filesystem     1K-blocks     Used Available Use% Mounted on
    /dev/sda2      104806400  5056748  99749652   5% /
    devtmpfs          915784        0    915784   0% /dev
    tmpfs             931624        0    931624   0% /dev/shm
    tmpfs             931624    10776    920848   2% /run
    tmpfs             931624        0    931624   0% /sys/fs/cgroup
    /dev/sda3       52403200    32992  52370208   1% /app
    /dev/sda1        1038336   178092    860244  18% /boot
    tmpfs             186328        4    186324   1% /run/user/42
    tmpfs             186328       48    186280   1% /run/user/0
    /dev/sr0        10491772 10491772         0 100% /run/media/root/CentOS 7 x86_64
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
ntOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
▽oot@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# ls
bak               CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-Sources.repo
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo      CentOS-Vault.repo
[root@localhost yum.repos.d]# mv *.repo bak/
[root@localhost yum.repos.d]# ls
bak
[root@localhost yum.repos.d]# vim base.repo
    [base]
    name=cdrom repo
    baseurl=file:///run/media/root/CentOS\ 7\ x86_64 :空格记得转义
    gpgcheck=0
    ~                                                            
    ~                                                                                                                                                           
    "base.repo" 4L, 83C written                                                                         
[root@localhost yum.repos.d]# yum repolist
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
    base                                                                                           | 3.6 kB  00:00:00     
    (1/2): base/group_gz                                                                           | 166 kB  00:00:00     
    (2/2): base/primary_db                                                                         | 6.0 MB  00:00:00     
    repo id                                               repo name                                                 status
    base                                                  cdrom repo                                                10,019
    repolist: 10,019
[root@localhost yum.repos.d]#

5、编写系统初始化脚本reset.sh,包括别名,提示符颜色,yum仓库配置文件
第一步:实现root用户免密码自动登陆

vim /etc/gdm/custom.conf
在[daemon]下增加
AutomaticLoginEnable=True
AutomaticLogin=root

第二步:开机后执行这个脚本

[root@localhost ~]#cat reset.sh

!/bin/bash

初始化系统脚本

echo "alias net='cd /etc/sysconfig/network-scripts/'" >> /root/.bashrc
echo "PS1='[\e[1;35m][\u@\h \W]\$[\e[0m]'" >>/etc/profile.d/env.sh

该脚本用于自动化搭建本地yum仓库

挂载光盘

mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/:因为是本地yum库 所以要先将其他的.repo文件移走避免出现影响
mount /dev/sr0 /mnt &>/dev/null

搭建本地仓库

cd /etc/yum.repos.d
cat >>base.repo< [base]
name=yum
baseurl=file:///mnt
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
OK

清空yum缓存

echo "正在清除yum缓存...."
yum clean all &>/dev/null
yum makecache &>/dev/null
echo "yum缓存清除结束!"

6、安装tree,ftp,lftp,telnet等包
[root@localhost ~]# yum install tree
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================
Package Arch Version Repository Size
=====================================================================================================
Installing:
tree x86_64 1.6.0-10.el7 base 46 k

Transaction Summary

Install 1 Package

Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1

Installed:
tree.x86_64 0:1.6.0-10.el7

Complete!
[root@localhost ~]# yum install ftp -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package ftp.x86_64 0:0.17-67.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================
Package Arch Version Repository Size
=====================================================================================================
Installing:
ftp x86_64 0.17-67.el7 base 61 k

Transaction Summary

Install 1 Package

Total download size: 61 k
Installed size: 96 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : ftp-0.17-67.el7.x86_64 1/1
Verifying : ftp-0.17-67.el7.x86_64 1/1

Installed:
ftp.x86_64 0:0.17-67.el7

Complete!
[root@localhost ~]# yum install lftp -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package lftp.x86_64 0:4.4.8-11.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================
Package Arch Version Repository Size
=====================================================================================================
Installing:
lftp x86_64 4.4.8-11.el7 base 752 k

Transaction Summary

Install 1 Package

Total download size: 752 k
Installed size: 2.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : lftp-4.4.8-11.el7.x86_64 1/1
Verifying : lftp-4.4.8-11.el7.x86_64 1/1

Installed:
lftp.x86_64 0:4.4.8-11.el7

Complete!
[root@localhost ~]# yum install telnet -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package telnet.x86_64 1:0.17-64.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================
Package Arch Version Repository Size
=====================================================================================================
Installing:
telnet x86_64 1:0.17-64.el7 base 64 k

Transaction Summary

Install 1 Package

Total download size: 64 k
Installed size: 113 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:telnet-0.17-64.el7.x86_64 1/1
Verifying : 1:telnet-0.17-64.el7.x86_64 1/1

Installed:
telnet.x86_64 1:0.17-64.el7

Complete!
[root@localhost ~]#

7、在CentOS7上编译安装apache2.4源码包,并启动此服务
安装依赖包:

yum install -y gcc gcc++ zlib zlib-devel expat-devel pcre-devel :编译包

准备好以下3个包:

apr-1.6.5.tar
apr-util-1.6.1.tar
httpd-2.4.37.tar

安装apr:

tar xf apr-1.6.3.tar.gz    
cd apr-1.6.3
./configure --prefix=/usr/local/apr
make && make install

安装apr-util:

tar xf apr-util-1.6.1.tar.gz 
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

安装httpd:

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

启动Apache:

cd /usr/local/apache/bin/
./apachectl start  :开启:start 停止:stop 重启:restart

修改iptables允许访问80端口:

iptables -I INPUT -p tcp --dport 80 -j ACCEPT

设置开机自动开启apache:

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

vim /etc/rc.d/init.d/apachectl
#!/bin/sh:下添加下面两句命令
#chkconfig: 234 20 80
#description: apache

将apachectl添加到系统服务并设置开机启动:
chkconfig --add apachectl
chkconfig apachectl on

systemctl status apachectl:正常管理到apachectl服务

你可能感兴趣的:(筛选命令、yum和编译源码)