sedはLinuxのテキスト処理、パッケージ管理、ディスク・ストレージとファイルシステム

sedはLinuxのテキスト処理、パッケージ管理、ディスク・ストレージとファイルシステム

1.テイク・グループ名とファイル名

[root@centos7 scripts38]#echo /etc/sysconfig/network-scripts/ |sed -r 's@(^/.*/)([^/]+)/?$@\1@'
/etc/sysconfig/
[root@centos7 scripts38]#echo /etc/sysconfig/network-scripts/ |sed -r 's@(^/.*/)([^/]+)/?$@\2@'
network-scripts

2.ネットワークはeth0のを修正しました

[root@centos7 scripts38]#sed -ri '/^[[:space:]]+linux16/s@(.*)@& net.infnames=0@' /boot/grub2/grub.cfg 
[root@centos7 data]#sed -ri '/GRUB_CMDLINE_LINUX=/s@"$@ net.ifnames=0"@' /etc/default/grub

彼らは魔法のフォルダを開くことができます前に3.あなたが自動的にCDをマウントすることができ、パックのフロントをダウンロードする必要があります。

[root@centos7 Packages]#[root@centos7 ~]#yum install autofs
[root@centos7 data]#systemctl start autofs
[root@centos7 data]#systemctl enable autofs
Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.
[root@centos7 data]#cd /misc
[root@centos7 misc]#cd cd/

4.紙幣識別導入RPM

[root@centos7 scripts38]#ls /misc/cd/
CentOS_BuildTag  images    repodata
EFI              isolinux  RPM-GPG-KEY-CentOS-7
EULA             LiveOS    RPM-GPG-KEY-CentOS-Testing-7
GPL              Packages  TRANS.TBL
[root@centos7 scripts38]#rpm --import /misc/cd/RPM-GPG-KEY-CentOS-7

4.ローカルおよびアリYUMソース構成。すべてきれいにyumのキャッシュをクリア

[base]
name=cdrom base
baseurl=file:///misc/cd
gpgcheck=1
gpgkey=file:///misc/cd/RPM-GPG-KEY-CentOS-7 

[epel]
name=aliyun epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch/
gpgcheck=0
enabled=0     #开启epel换为1

アリクラウドレポソースの設定、作業ディレクトリに注意を払います。

[root@centos7 data]#wget http://mirrors.aliyun.com/repo/Centos-7.repo
[root@centos7 /]#mv Centos-7.repo /etc/yum.repos.d/

ネットワークYUMを構築するためのソース

[root@centos7 data]#yum install httpd
[root@centos7 data]#systemctl start httpd
[root@centos7 data]#cd /var/www/html
[root@centos7 html]#mkdir -pv  centos/{6,7}/os/x86_64/
[root@centos7 html]#mount /dev/sr0 centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 html]#mount /dev/sr1 centos/6/os/x86_64/
mount: /dev/sr1 is write-protected, mounting read-only

6.最初のトレッキングの空白空白文字でcentos7 /etc/grub2.cfgファイルシステムにすべての始まりを削除

[root@centos7 ~]#sed -r 's/^[[:space:]]([[:space:]]+.*)/\1/' /etc/grub2.cfg

前記少なくとも1つの空白文字行と空白文字を#に続いて、#で始まるすべての最初の行に/ etc / fstabファイルを削除します。

[root@centos7 yum.repos.d]#sed -r 's/^#[[:space:]]+//' /etc/fstab

8.に/root/install.log centos6システム第増大番号#各トレッキング

[root@centos6 ~]#sed -r 's/(.*)/#\1/' /root/install.log

9.処理の/ etc / fstabのパス、sedコマンドのディレクトリ名やグ​​ループ名でそれを削除します

[root@centos7 ~]#echo /etc/fstab | sed -r 's@(^/.*/)([^/]+)/?$@\1@'
/etc/
[root@centos7 ~]#echo /etc/fstab | sed -r 's@(^/.*/)([^/]+)/?$@\2@'
fstab

10. ifconfigコマンドの使用は、機械で抽出されたIPv4アドレスをセッド

[root@centos7 ~]#ifconfig eth0 | sed -rn '2s/^[^0-9]+([0-9.]+).*/\1/p'
172.18.145.136

繰り返し周波数分周器11ディレクトリのCDパッケージ内のすべてのファイルをインストールするには、統計CentOSの回転数の最後から二番目のフィールドを持ちます

[root@centos7 Packages]#ls /misc/cd/Packages/ |sed -rn 's@.*\.(.*)\..*@\1@p'|sort|uniq -c|sort -nr
   4639 x86_64
   3122 noarch
   2258 i686

SNARTは、それがどこから来たのか分かりません。

[root@centos7 Packages]#ls /misc/cd/Packages/ |rev|cut -d '.' -f2 |sort |uniq -c |sort -nr
   4639 46_68x
   3122 hcraon
   2258 686i
      1 SNART

12.統計は、ファイル内の各単語の出現回数を/etc/init.d/functions、ソート(grepを用いて、それぞれ実現され、2つのメソッドをSED)

この感覚は何の問題もないはずです

[root@centos7 Packages]#cat /etc/init.d/functions |egrep -o "\<[[:alpha:]]+\>" |sort |uniq -c|sort -nr
     60 if
     54 return
     52 then
     51 fi
     49 echo
     46 pid
     38 n

これは、許可のsedやワード機能を取らないないようです

[root@centos7 Packages]#cat /etc/init.d/functions |sed -r 's@[^[:alpha:]]+@\n@g'|sort|uniq -c|sort -nr|head
   1047 
     73 pid
     60 if
     58 file
     57 echo
     54 return
     52 then
     51 fi
     39 n
     38 base

これは間違っている必要があります。

[root@centos7 Packages]#cat /etc/init.d/functions |sed -r 's@[[:space:]]+@\n@g'|sort|uniq -c|sort -nr|head
    608 
    103 [
     66 #
     64 ]
     59 &&
     58 if
     54 return
     52 then
     51 fi
     43 echo

単一線としてテキストファイルの13 NとN + 1行、行nが奇数であります

[root@centos7 Packages]#seq 10 |xargs -n2
1 2
3 4
5 6
7 8
9 10

sedの高度な使い方が病気である、はげ髪は簡単に、再生されない再生されません

[root@centos7 Packages]#seq 10|sed 'N;s/\n/ /'
1 2
3 4
5 6
7 8
9 10

14.自分自身のyumリポジトリの一部と

[root@centos7 data]#mkdir dnf
[root@centos7 data]#cd dnf/
[root@centos7 dnf]#rz -E
rz waiting to receive.
[root@centos7 dnf]#ll
total 808
-rw-r--r-- 1 root root 213696 Jun  4  2018 dnf-0.6.4-2.sdl7.noarch.rpm
-rw-r--r-- 1 root root  62404 Jun  4  2018 dnf-conf-0.6.4-2.sdl7.noarch.rpm
-rw-r--r-- 1 root root  75472 Jun  4  2018 libcomps-0.1.8-3.el7.x86_64.rpm
-rw-r--r-- 1 root root  46792 Jun  4  2018 python2-libcomps-0.1.8-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 416988 Jun  4  2018 python-dnf-0.6.4-2.sdl7.noarch.rpm
自动生成repodata
[root@centos7 dnf]#createrepo .
Spawning worker 0 with 3 pkgs
Spawning worker 1 with 2 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
自己配置repo
[root@centos7 yum.repos.d]#cat dnf.repo 
[dnf]
name=dnf
baseurl=file:///data/dnf
gpgcheck=0
查看是否成功
[root@centos7 yum.repos.d]#yum repolist 

その後、コンパイル済みスクリプト

tar -xvf httpd-2.4.25.tar.bz2
cd httpd-2.4.25/
指定路径,配置文件所在位置,开启一些服务,报错,缺APR
[root@centos7 httpd-2.4.25]#./configure  --prefix=/apps/httpd24 --sysconfdir=/etc/httpd --enable-ssl --enable-so
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.
一般都是devel开发包
[root@centos7 httpd-2.4.25]#yum search apr
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
========================================== N/S matched: apr ===========================================
apr-devel.i686 : APR library development kit
apr-devel.x86_64 : APR library development kit
下载APR包
[root@centos7 httpd-2.4.25]#yum install apr-devel
缺少什么包补什么包
[root@centos7 httpd-2.4.25]#yum install apr-util-devel
[root@centos7 httpd-2.4.25]#yum install pcre-devel
错误,不是这个包[root@centos7 httpd-2.4.25]#yum install mod_ssl
[root@centos7 httpd-2.4.25]#yum install openssl-devel
还有前面装了个gcc
成功后,执行make编译
然后再make install
[root@centos7 httpd-2.4.25]#make
[root@centos7 httpd-2.4.25]#make install
完成后
[root@centos7 httpd24]#cd /apps/httpd24/
写到环境变量中
[root@centos7 httpd24]#vim /etc/profile.d/env.sh
PATH=/apps/httpd24/bin:/apps/tree/bin:$PATH 
重读,刷新环境变量
[root@centos7 httpd24]#. /etc/profile.d/env.sh
开启服务
[root@centos7 httpd24]#apachectl restart
自动启动的文件,要把路径写里去
[root@centos7 httpd24]#ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 473 Oct 31  2018 /etc/rc.d/rc.local
[root@centos7 httpd24]#vim /etc/rc.d/rc.local
把下面的写到里面
/apps/httpd24/bin/apachectl start 
然后给这个文件执行权限。
[root@centos7 httpd24]#chmod +x /etc/rc.d/rc.local
页面显示的地方,可以自己修改。
[root@centos7 httpd24]#cd htdocs/
[root@centos7 htdocs]#ll
total 4
-rw-r--r-- 1 root root 45 Jun 12  2007 index.html

15.小さなものをコンパイルします

[root@centos7 data]#tar -xvf cmatrix-1.2a.tar.gz 
[root@centos7 cmatrix]#yum install ncurses-devel
[root@centos7 cmatrix]#./configure --prefix=/apps/cmatrix
[root@centos7 cmatrix]#make
[root@centos7 cmatrix]#make install

パーティションテーブル16.mbrをバックアップと復元

查看MBR分区表前512个字节
[root@centos7 data]#hexdump -C /dev/sda -n 512
把分区表的64个字节拷贝出来,skip是跳过原文件的446个字节。
[root@centos7 data]#dd if=/dev/sda of=/data/mar_db bs=1 count=64 skip=446
64+0 records in
64+0 records out
64 bytes (64 B) copied, 0.000585693 s, 109 kB/s
把数据拷贝到其他服务器上
[root@centos7 data]#scp mar_db [email protected]:/data
破坏原来的分区表,seek是跳过目标的446个字节。服务器无法启动。
[root@centos7 data]#dd if=/dev/zero of=/dev/sda bs=1 count=64 seek=446
重启进入救援模式。临时配一个IP地址
[root@centos7 ~]#ifconfig ens33 172.18.145.164
把备份的拷回来
[root@centos7 ~]#scp [email protected]:/data/mar_db .
[root@centos7 data]#dd if=mar_db of=/dev/sda bs=1 count=64 skip=446
重启电脑
exit

MBRパーティション
シリンダーによって、

4つのパーティション、3つのプライマリパーティション、拡張パーティションまで、拡張パーティションは複数の論理パーティションを持つことができます。

2Tスペースまでの管理

GPTパーティション

セクター別

128個のパーティション

8Zスペースの管理まで

128 UUID

パーティションテーブルのバックアップ

17.partedコマンド

parted的操作都是实时生效的,小心使用
用法:parted [选项]... [设备 [命令 [参数]...]...]
parted /dev/sdb mklabel gpt|msdos
parted /dev/sdb print
parted /dev/sdb mkpart primary 1 200 (默认M)
parted /dev/sdb rm 1
parted  /dev/sdb –l 列出分区信息

18.シミュレーション・ファイル・システムに障害が発生しました

破坏
[root@centos7 data]#dd if=/dev/zero of=/dev/sda5 bs=1M count=1
已经被破坏,超级块打不开了
[root@centos7 data]#tune2fs -l /dev/sda5
tune2fs 1.42.9 (28-Dec-2013)
tune2fs: Bad magic number in super-block while trying to open /dev/sda5
Couldn't find valid filesystem superblock.
先取消挂载。必须在取消挂载的情况下修复
[root@centos7 ~]#umount /data
文件系统故障。无法挂载
[root@centos7 ~]#mount /dev/sda5 /data/
mount: mount /dev/sda5 on /data failed: Structure needs cleaning
xfs系统的修复方法
[root@centos7 data]#xfs_repair /dev/sda5
centos6 ext系列的修复方法
fsck /dev/sda5 -y
修复完成可以挂载
[root@centos7 ~]#mount /dev/sda5 /data/
[root@centos7 ~]#cd /data/
数据丢失
[root@centos7 data]#ll
total 12
drwxr-xr-x 246 root root 8192 Aug  8 16:34 lost+found

19.増加のスワップパーティション、プロセスは書いていません。ファイルは、そうでない場合は失われます再起動し、UUIDを使用してファイル名を書き込むことはできません。

[root@centos7 ~]#swapon -s
Filename                Type        Size    Used    Priority
/dev/sdb1                               partition   4194300 0   -1
/dev/sda3                               partition   2097148 0   -2
/swapfile                               file    2097148 0   -3

20.ファイルのマウントファイル

创建一个大文件
[root@centos7 ~]#dd if=/dev/zero of=/bigfile bs=1M count=1024 
格式化EXT4
[root@centos7 ~]#mkfs.ext4 /bigfile
mke2fs 1.42.9 (28-Dec-2013)
/bigfile is not a block special device.
Proceed anyway? (y,n) y
Discarding device blocks: done                 
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
查看格式信息
[root@centos7 ~]#blkid /bigfile
/bigfile: UUID="9e1393ae-8e18-4dee-af73-4fafa373ff29" TYPE="ext4" 
写入文件永久挂载

メンテナンス状態で新しい場所へ21.移行/家庭用データ、。これは、シングルユーザーモードです。INIT 1

[root@centos7 data]#mkfs.xfs /dev/sdb2
[root@centos7 data]#mkdir /mnt/home
[root@centos7 data]#mount /dev/sdb2 /mnt/home/
[root@centos7 data]#cp -av /home/. /mnt/home/
[root@centos7 data]#vim /etc/fstab 
UUID=63b5335d-a455-45a8-8f3f-3ebf66fb240a   /home              xfs      defaults    0  0 
[root@centos7 data]#mount -a
数据保留一段时间,没问题,取消挂载,准备删除原来的数据
[root@centos7 data]#umount /home/
现在看到的是原来/home的数据,挂载的时候是被覆盖的,看不到的
[root@centos7 data]#ls /home
zhang
把原来的数据都删除了,一定要注意不要把文件夹删除
[root@centos7 data]#rm -rf /home/*
重新挂载一下,数据就都迁移到新的硬盘。
[root@centos7 data]#mount -a
[root@centos7 data]#df
/dev/sdb2        2086912   33052   2053860   2% /home

22. 2048バイトの2Gのファイルシステムのブロックサイズを作成し、自動的にパーティション/ testディレクトリのブートを実装するために必要な利用可能なスペース、ファイルシステムext4は、ボリュームラベルTESTの1%を予約して、ACLはオプションがデフォルトを持ってマウント

[root@centos7 data]#fdisk /dev/sdb
[root@centos7 data]#mke2fs -t ext4 -b 2048 -L 'TEST' -m 1 /dev/sdb5
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=TEST
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 1048576 blocks
10485 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=269484032
64 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
    16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 
[root@centos7 data]#vim /etc/fstab
UUID=e02a9d53-6f8a-4dca-a130-5296fe24975b  /mnt/sdb5              ext4     acl            0 0
[root@centos7 data]#mount -a

(1)現在のシステムは、すべてのディスクデバイス(2)ディスクの数が一つであるように、それが表示される使用空間情報を識別する示します。23.スクリプト、以下の関数を記述⼀。それ以外の場合は、ディスクの使用情報の最後のスペースを表示します。

#颜色配置
COLOR="\033[1;$[RANDOM%7+31]m"                                                             
COLOREND='\033[0m'

df |grep /dev/sd | tr -s ' '|cut -d ' ' -f1

echo -e "${COLOR}磁盘设备检查完毕 $COLOREND"

NUM=`df |grep /dev/sd |wc -l`
[ "$NUM" -eq 1 ] && echo -e "磁盘的利用率: ${COLOR}`df |grep /dev/sd | tr -s ' '|cut -d ' ' -f5` $COLOREND"
[ "$NUM" -gt 1 ] && echo -e "最后一个磁盘的利用率: ${COLOR}`df |grep /dev/sd | tr -s ' '|cut -d ' ' -f5|tail -n 1` $COLOREND" 
[root@centos7 data]#bash  aaa.sh 
/dev/sda2
/dev/sda5
/dev/sda1
/dev/sdb5
磁盘设备检查完毕 
最后一个磁盘的利用率: 1% 

24.下の説明Linuxは多くの場合、その違い何のファイルシステムを使用しましたか?

1. EXT3 
(1)最多只能支持32TB的文件系统和2TB的文件,实际只能容纳2TB的文件系统和16GB的文件
(2)Ext3目前只支持32000个子目录
(3)Ext3文件系统使用32位空间记录块数量和i-节点数量
(4)当数据写入到Ext3文件系统中时,Ext3的数据块分配器每次只能分配一个4KB的块
2. EXT4 
EXT4是Linux系统下的日志文件系统,是EXT3文件系统的后继版本。
(1)Ext4的文件系统容量达到1EB,而文件容量则达到16TB 
(2)理论上支持无限数量的子目录
(3)Ext4文件系统使用64位空间记录块数量和i-节点数量
(4)Ext4的多块分配器支持一次调用分配多个数据块
3. XFS 
(1)根据所记录的日志在很短的时间内迅速恢复磁盘文件内容
(2)采用优化算法,日志记录对整体文件操作影响非常小
(3) 是一个全64-bit的文件系统,它可以支持上百万T字节的存储空间
(4)能以接近裸设备I/O的性能存储数据

簡単なスクリプトのような25.個人設定。

#!/bin/bash
#
#********************************************************************
#Author:        zhangfeng
#QQ:            553645084
#Date:          2019-08-03
#FileName:      reset.sh
#URL:           https://blog.51cto.com/14451122
#Description:       The test script
#Copyright (C):     2019 All rights reserved
#********************************************************************

#颜色配置
COLOR="\033[1;$[RANDOM%7+31]m"                                                                         
COLOREND='\033[0m'

echo -e "${COLOR}开机提示配置 $COLOREND"
cat > /etc/issue << EOF
\S
time is \t
tty is \l
hostname is \n 
Kernel \r on an \m
EOF
sleep 1

echo -e "${COLOR}别名环境变量配置 $COLOREND"
cat > /etc/profile.d/env.sh << EOF
alias cdnet="cd /etc/sysconfig/network-scripts"
alias editnet="vim /etc/sysconfig/network-scripts/ifcfg-ens33"
alias scandisk="echo '- - -' > /sys/class/scsi_host/host2/scan;echo '- - -' > /sys/class/scsi_host/host0/scan" 
export PATH=/app/bin:$PATH
export EDITOR=vim
export HISTTIMEFORMAT="%F %T "
export HISTCONTROL=ignoreboth
EOF

echo -e "${COLOR}提示符配置 $COLOREND"
echo 'PS1="\[\e[1;32m\][\u@\h \W]\\$\[\e[0m\]"' >> /etc/profile.d/env.sh
sleep 1 

echo -e "${COLOR}VIM配置$COLOREND"
cat > ~/.vimrc << EOF
set ignorecase
set cursorline
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
    if expand("%:e") == 'sh'
    call setline(1,"#!/bin/bash") 
    call setline(2,"#") 
    call setline(3,"#********************************************************************") 
    call setline(4,"#Author:        zhangfeng") 
    call setline(5,"#QQ:            553645084") 
    call setline(6,"#Date:          ".strftime("%Y-%m-%d"))
    call setline(7,"#FileName:      ".expand("%"))
    call setline(8,"#URL:           https://blog.51cto.com/14451122")
    call setline(9,"#Description:       The test script") 
    call setline(10,"#Copyright (C):    ".strftime("%Y")." All rights reserved")
    call setline(11,"#********************************************************************") 
    call setline(12,"") 
    endif
endfunc
autocmd BufNewFile * normal G
EOF
sleep 1 

#关闭selinux
echo -e "${COLOR}selinux已经关闭 $COLOREND"
sed -i  's/SELINUX=enforcing/SELINUX=disabled/ ' /etc/selinux/config
sleep 1 

#把ens33改为eth0
echo -e "${COLOR}网卡名改为eth0 $COLOREND"
sed -ri '/GRUB_CMDLINE_LINUX=/s@"$@ net.ifnames=0"@' /etc/default/grub
sed -ri '/^[[:space:]]+linux16/s#(.*)#\1 net.ifnames=0#' /boot/grub2/grub.cfg
sleep 1 

#7版本关闭防火墙
echo -e "${COLOR}关闭7版本防火墙 $COLOREND"
systemctl disable firewalld.service
sleep 1 

#6版本关闭防火墙
echo -e "${COLOR}关闭6版本防火墙 $COLOREND"
chkconfig iptables off
sleep 1 

#配置阿里云YUM源适合7版本                                                            
echo -e "${COLOR}7版本阿里云repo源配置 $COLOREND"
#wget http://mirrors.aliyun.com/repo/Centos-7.repo
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
#mv Centos-7.repo /etc/yum.repos.d/
#touch /etc/yum.repos.d/mirrorlist
#cat > /etc/yum.repos.d/mirrorlist <<EOF
#https://mirrors.aliyun.com/epel/$releasever/$basearch/
#EOF
touch /etc/yum.repos.d/epel.repo
cat > /etc/yum.repos.d/epel.repo <<EOF
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
enabled=1
EOF
sleep 1 

echo -e "${COLOR}阿里云普通源配置 $COLOREND"
touch /etc/yum.repos.d/base.repo
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=file:///misc/cd
    https://mirrors.aliyun.com/centos/7/os/x86_64/                                                 
gpgcheck=0
EOF
sleep 1 

yum clean all

echo -e "${COLOR}自动下载软件 $COLOREND"
yum install tree -y
yum install ftp -y
yum install lftp -y
yum install telnet -y
yum install autofs gcc gcc-c++ glibc glibc-devel pcre pcre-devel
openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree screen lsof
tcpdump wget ntpdate net-tools iotop bc zip unzip nfs-utils -y

sleep 1 

echo -e "${COLOR}服务器基本信息 $COLOREND"
echo -e  "CPU type is ${COLOR}`cat /proc/cpuinfo|grep -im1 'model name'|cut -d: -f2|tr -s ' '`$COLOREND"
echo -e "Mem is ${COLOR}`cat /proc/meminfo |head -1 | tr -s " " |cut -d: -f2`$COLOREND"
echo -e "Disk size is ${COLOR}`cat /proc/partitions |grep "sda$" |tr -s " " |cut -d" " -f4` kB$COLOREND"

echo -e "OS version is ${COLOR}`cat /etc/redhat-release`$COLOREND"
echo -e "Kernel version is ${COLOR}`uname -r`$COLOREND"

自動的にスクリプトをインストール26.httpd2.4.25

#!/bin/bash
#
#********************************************************************
#Author:        zhangfeng
#QQ:            553645084
#Date:          2019-08-06
#FileName:      httpdaz.sh
#URL:           https://blog.51cto.com/14451122
#Description:       The test script
#Copyright (C):     2019 All rights reserved
#********************************************************************

#颜色配置
COLOR="\033[1;$[RANDOM%7+31]m"
COLOREND='\033[0m'
echo -e "${COLOR}httpd2.4.25安装脚本 适合centos7.6、7.5版本 ,其他未知 $COLOREND"

#前提必须要有/data目录才可以实现
#获取压缩包的2种方法
#scp [email protected]:/data/httpd-2.4.25.tar.bz2 /data/
wget http://archive.apache.org/dist/httpd/httpd-2.4.25.tar.bz2

#下载配置环境
yum install apr-devel -y 
yum install pcre-devel -y 
yum install openssl-devel -y
yum install gcc -y 
yum install apr-util-devel -y 

#编译安装
tar -xvf /data/httpd-2.4.25.tar.bz2 -C /data/
cd /data/httpd-2.4.25/
./configure  --prefix=/apps/httpd24 --sysconfdir=/etc/httpd --enable-ssl --enable-so
make
make install
echo $? &&  echo -e "${COLOR}httpd2.4.25安装完成 $COLOREND"
echo -e '\a'

#配置环境变量
echo 'PATH=/apps/httpd24/bin:$PATH' >> /etc/profile.d/env.sh
. /etc/profile.d/env.sh

#开启服务
cd /apps/httpd24/
apachectl restart

#开机自动启动配置
echo '/apps/httpd24/bin/apachectl start' >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
echo -e "${COLOR}httpd2.4.25安装完成,已启动。开机自动启动开启 $COLOREND"

27.アンインストールスクリプトhttpd2.4.25

#!/bin/bash
#
#********************************************************************
#Author:        zhangfeng
#QQ:            553645084
#Date:          2019-08-07
#FileName:      httpd2.4.25xz.sh
#URL:           https://blog.51cto.com/14451122
#Description:       The test script
#Copyright (C):     2019 All rights reserved
#********************************************************************

#颜色配置
COLOR="\033[1;$[RANDOM%7+31]m"
COLOREND='\033[0m'
echo -e "${COLOR}httpd2.4.25卸载脚本 适合centos7.6、7.5版本 ,只配合httpdaz.sh $COLOREND"

#删除安装目录、配置文件目录、解压包、压缩包。
rm -rf /etc/httpd
rm -rf /apps/httpd24
rm -rf /data/httpd-2.4.25.tar.bz2
rm -rf /data/httpd-2.4.25
echo -e "${COLOR}安装目录、配置文件目录、解压包、压缩包删除完成 $COLOREND"

sed -i '/PATH=\/apps\/httpd24\/bin:$PATH/d' /etc/profile.d/env.sh
sed -i '/\/apps\/httpd24\/bin\/apachectl start/d' /etc/rc.d/rc.local

echo -e "${COLOR}httpd2.4.25卸载完成 $COLOREND"

おすすめ

転載: blog.51cto.com/14451122/2428332