文件搜索压缩 sed 软件包管理 rpm yum 源码编译安装httpd

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

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

[root@centos7 ~]#find /var ! \( -user root -o -user lp -o -user gdm \) -ls
    73    0 drwxr-xr-x   2 abrt     abrt            6 May  6 19:21 /var/tmp/abrt
101354809    0 drwxr-xr-x   4 colord   colord         67 May  6 19:22 /var/lib/colord
279449    0 drwxr-xr-x   2 colord   colord          6 Aug  6  2017 /var/lib/colord/icc
101898310    4 -rw-r--r--   1 colord   colord       4096 May  6 19:22 /var/lib/colord/mapping.db
101898311    8 -rw-r--r--   1 colord   colord       7168 May  6 19:22 /var/lib/colord/storage.db
36406408    0 drwx------   2 colord   colord          6 May  6 19:22 /var/lib/colord/.cache
67530828    0 drwx------   2 rpc      rpc             6 Oct 31  2018 /var/lib/rpcbind
34876696    0 drwx------   2 pulse    pulse           6 Apr 13  2018 /var/lib/pulse
355825    0 drwxr-xr-x   2 chrony   chrony          6 Apr 13  2018 /var/lib/chrony
358967    0 drwx------   4 rpcuser  rpcuser        30 May  6 18:56 /var/lib/nfs/statd
34908271    0 drwx------   2 rpcuser  rpcuser         6 Nov  8  2018 /var/lib/nfs/statd/sm

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

方法一 cat /etc/init.d/functions | grep -o "[[:alpha:]]\+" | sort | uniq -c | sort -nr

[root@centos7 profile.d]#cat /etc/init.d/functions | grep -o "[[:alpha:]]\+" | sort | uniq -c | sort -nr     
     73 pid
     60 if
     58 file
     57 echo
     54 return
     52 then
     51 fi
     39 n
     38 base
     37 local
     34 kill
     28 z

方法二 cat /etc/init.d/functions | sed -r 's/[^[:alpha:]]/\n/g' | sed '/^$/d' | sort | uniq -c | sort -nr

[root@centos7 data]#cat /etc/init.d/functions | sed -r 's/[^[:alpha:]]/\n/g' | sed '/^$/d' | sort | uniq -c | sort -nr
     73 pid
     60 if
     58 file
     57 echo
     54 return
     52 then
     51 fi
     39 n
     38 base
     37 local
     34 kill
     28 z

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

方法一ifconfig ens33 | sed -n '2p' | sed 's/.*inet //' | sed 's/ netmask.*$//'

[root@centos7 data]#ifconfig ens33 | sed -n '2p' | sed 's/.*inet //' | sed 's/  netmask.*$//'
192.168.38.101

方法二ifconfig ens33 | sed -n '2s/ *inet *\(.*\) \{2,\}netmask.*/\1/pg'

[root@centos7 data]#ifconfig ens33 | sed -n '2s/ *inet *\(.*\) \{2,\}netmask.*/\1/pg'
192.168.38.101

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

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

yum配置:
    yum的配置文件分为两部分:main和repositoy
    · man部分定义了全局配置选项,整个yum配置文件应该只有一个main,位于 /etc/yum.conf 中;
    · repository 部分定义了每个源/服务器的具体配置,可以有一到多个。位于 /etc/yum.repo.d 目录下的各个文件中

仓库指向的定义:
    [repositoryID]
    name=Some name for this repository
    baseurl=url://path/to/repository/
    enabled={1|0}
    gpgcheck={1|0}
    gpgkey=URL
    enablegroups={1|0}
    failovermethod={roundrobin|priority}
    roundrobin:意为随机挑选,默认值
    priority:按顺序访问
    cost= 默认为1000

命令 说明 命令 说明
yum repolist 显示仓库列表 yum list 显示程序包
yum install package1 安装程序包package1 yum update package1 升级程序包package1
yum remove package 卸载程序包 yum downgrade package1 降级程序包package1
yum info [...] 查看程序包信息 yum clean 清理本地缓存
yum search keyword 以指定的关键字搜索程序包 yum makecache 构建缓存
--disablerepo=repoidglob 临时禁用此处指定的repo --enablerepo=repoidglob 临时启用此处指定的repo

加入epel源

[root@centos7 yum.repos.d]#cat base.repo 
[base]
name=CentOS
baseurl=file:///media
gpgcheck=0

[epel]
name=EPEL
baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch/
        https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/$basearch/
gpgcheck=0
enabled=1

搭建局域网内部服务器,不连接外网,局域http协议的网络yum仓库

也可以先建立本地yum用yum安装httpd
[root@centos7 ~]#rpm -ql httpd
/etc/httpd
/etc/httpd/conf
/var/www
/var/www/cgi-bin
/var/www/html
[root@centos7 ~]#cd /var/www/html
[root@centos7 html]#systemctl start httpd
[root@centos7 html]#systemctl stop firewalld.service
此时在浏览器输入IP可以看到测试页面
建立一个页面
[root@centos7 html]#echo welcome to nyc! > index.html
建立目录
[root@centos7 html]#mkdir -pv centos/{6,7}/os/x86_64/
mkdir: created directory ‘centos’
mkdir: created directory ‘centos/6’
mkdir: created directory ‘centos/6/os’
mkdir: created directory ‘centos/6/os/x86_64/’
mkdir: created directory ‘centos/7’
mkdir: created directory ‘centos/7/os’
mkdir: created directory ‘centos/7/os/x86_64/’
挂载光盘到目录
[root@centos7 html]#mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
修改repo后yum clean all 清理缓存
yum repolist 缓存刷新成功
同理添加光驱挂载c6.10光盘
echo - - - > /sys/class/scsi_host/host2/scan 刷新显示光驱
参考上步骤

自己建立无库的rpm安装包的库
createrepo


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

#!/bin/bash
#
#********************************************************************
#Author:                Jack
#QQ:                    Secret
#Date:                  2019-06-03
#FileName:             reset.sh
#URL:                   Building
#Description:          The test script
#Copyright (C):         2019 All rights reserved
#********************************************************************
rootbashrc=`cd;pwd`/.bashrc
echo "alias net='cd /etc/sysconfig/network-scripts/'" >> $rootbashrc
echo "PS1='\[\e[1;32m\][\u@\h \W]\\$\[\e[0m\]'" > /etc/profile.d/env.sh
cd `df | grep /dev/sr* | tr -s ' ' | cut -d ' ' -f 6-` || \
  mount `df | grep /dev/sr* | tr -s ' ' | cut -d ' ' -f 1` /media
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=file:///media
#baseurl=http://192.168.2.165/centos/$releasever/os/$basearch/
gpgcheck=0

[epel]
name=EPEL
baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch/
        https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/$basearch/
gpgcheck=0
enabled=1
EOF

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

yum install tree ftp lftp telnet -y

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

  1. 安装开发工具包,此方法偷懒,生产中建议依赖什么装什么
    yum grouplist
    yum groupinstall "development tools"
  2. 解压下载的源码后!!!必须!!!要进入到编译的目录
    查看说明
[root@centos7 httpd-2.4.39]#./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local/apache2]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]
  1. 创建帐号
[root@centos7 httpd-2.4.39]#getent passwd | grep 80
[root@centos7 httpd-2.4.39]#useradd -r -u 80 -d /data/www/ -s /sbin/nologin httpd
[root@centos7 httpd-2.4.39]#id httpd
uid=80(httpd) gid=80(httpd) groups=80(httpd)
  1. 开始选择设置
[root@centos7 httpd-2.4.39]#./configure --prefix=/app/httpd --sysconfdir=/etc/httpd24 --enable-ssl --disable-status
  1. 提示依赖,安装软件
yum install apr-devel
yum install apr-util-devel
yum install pcre-devel
yum install openssl-devel
  1. 再次运行编译
[root@centos7 httpd-2.4.39]#./configure --prefix=/app/httpd --sysconfdir=/etc/httpd24 --enable-ssl --disable-status
  1. 编译成功生成了Makefile文件,开始编译,有可能会提示依赖
[root@centos7 httpd-2.4.39]#make
  1. 提示完成
make[4]: Leaving directory `/data/httpd-2.4.39/modules/mappers'
make[3]: Leaving directory `/data/httpd-2.4.39/modules/mappers'
make[2]: Leaving directory `/data/httpd-2.4.39/modules'
make[2]: Entering directory `/data/httpd-2.4.39/support'
make[2]: Leaving directory `/data/httpd-2.4.39/support'

make[1]: Leaving directory `/data/httpd-2.4.39'
  1. 开始编译
[root@centos7 httpd-2.4.39]#make install
Making install in srclib
进入安装目录的bin下
[root@centos7 httpd-2.4.39]#cd /app/httpd/bin/
[root@centos7 bin]#pwd
/app/httpd/bin
[root@centos7 bin]#ls
ab         apxs      dbmmanage  envvars-std  htcacheclean  htdigest  httpd      logresolve
apachectl  checkgid  envvars    fcgistarter  htdbm         htpasswd  httxt2dbm  rotatelogs
  1. 由于此处bin目录不存在PATH变量中,把目录加进去
[root@centos7 bin]#echo 'PATH=/app/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@centos7 bin]#cat /etc/profile.d/httpd.sh 
PATH=/app/httpd/bin:$PATH
[root@centos7 bin]#. /etc/profile.d/httpd.sh
[root@centos7 bin]#echo $PATH               
/app/httpd/bin:/data/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
  1. 启动运行软件
[root@centos7 ~]#apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using centos7.localdomain. Set the 'ServerName' directive globally to suppress this message
  1. 此时浏览器打开查看页面,页面地址在这里
[root@centos7 ~]#cd /app/httpd
[root@centos7 httpd]#ls
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules
[root@centos7 httpd]#cd htdocs/
[root@centos7 htdocs]#ls
index.html
[root@centos7 htdocs]#cat index.html 
<html><body><h1>It works!</h1></body></html>
  1. 查看账号是否被用上
[root@centos7 htdocs]#ps aux
root      48304  0.0  0.2 101656  2636 ?        Ss   22:29   0:00 /app/httpd/bin/httpd -k start
daemon    48305  0.0  0.3 456104  3024 ?        Sl   22:29   0:00 /app/httpd/bin/httpd -k start
daemon    48333  0.0  0.2 456104  2420 ?        Sl   22:29   0:00 /app/httpd/bin/httpd -k start
daemon    48334  0.0  0.2 456104  2416 ?        Sl   22:29   0:00 /app/httpd/bin/httpd -k start
daemon    48394  0.0  0.2 456104  2408 ?        Sl   22:30   0:00 /app/httpd/bin/httpd -k start
  1. 未用上 需要更改
[root@centos7 htdocs]#vim /etc/httpd24/httpd.conf
166 User httpd
167 Group httpd 
保存后,停止应用再启动
[root@centos7 htdocs]#apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using centos7.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@centos7 htdocs]#apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using centos7.localdomain. Set the 'ServerName' directive globally to suppress this message
  1. 再次查看查看账号是否被用上 成功!
[root@centos7 htdocs]#ps aux
root      48525  0.0  0.2 101656  2632 ?        Ss   22:36   0:00 /app/httpd/bin/httpd -k start
httpd     48526  0.0  0.2 456104  2952 ?        Sl   22:36   0:00 /app/httpd/bin/httpd -k start
httpd     48527  0.0  0.2 456104  2412 ?        Sl   22:36   0:00 /app/httpd/bin/httpd -k start
httpd     48528  0.0  0.2 456104  2412 ?        Sl   22:36   0:00 /app/httpd/bin/httpd -k start
httpd     48610  0.0  0.2 456104  2408 ?        Sl   22:36   0:00 /app/httpd/bin/httpd -k start
  1. 添加man帮助的地址 下面为C7,C6在/etc/man.config
[root@centos7 man]#cd /app/httpd/man/
[root@centos7 man]#pwd
/app/httpd/man
[root@centos7 man]#vim /etc/man_db.conf 
  1 # 
  2 #
  3 # This file is used by the man-db package to configure the man and cat paths.
  4 # It is also used to provide a manpath for those without one by examining
  5 # their PATH environment variable. For details see the manpath(5) man page.
  6 #
  7 # Lines beginning with `#' are comments and are ignored. Any combination of
  8 # tabs or spaces may be used as `whitespace' separators.
  9 #
 10 # There are three mappings allowed in this file:
 11 # --------------------------------------------------------
 12 # MANDATORY_MANPATH                     manpath_element
 13 # MANPATH_MAP           path_element    manpath_element
 14 # MANDB_MAP             global_manpath  [relative_catpath]
 15 #---------------------------------------------------------
 16 # every automatically generated MANPATH includes these fields
 17 #
 18 #MANDATORY_MANPATH                      /usr/src/pvm3/man
 19 #
 20 MANDATORY_MANPATH                       /usr/man
 21 MANDATORY_MANPATH                       /usr/share/man
 22 MANDATORY_MANPATH                       /usr/local/share/man
 23 MANDATORY_MANPATH                       /app/httpd/man
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,332评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,508评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,812评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,607评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,728评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,919评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,071评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,802评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,256评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,576评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,712评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,389评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,032评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,798评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,026评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,473评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,606评论 2 350

推荐阅读更多精彩内容