linux text processing sed, package management, disk storage and file system

linux text processing sed, package management, disk storage and file system

1. Take group name and file name

[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. Network modified 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. You might need to download the front of the pack before they can open the magic folder, you can automatically mount the 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. The bill validator introduced 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. Local and Ali YUM source configuration. Clear the cache yum clean all

[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

Configuring Ali cloud repo source, pay attention to the working directory.

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

The source to build the network 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. Remove centos7 /etc/grub2.cfg file system all starts with a blank white space character of the first trekking

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

7. Delete the / etc / fstab file in the first line of all begin with #, followed by at least one blank character lines and whitespace characters #

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

8. /root/install.log each trekking in centos6 system first increase number #

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

9. Processing / etc / fstab path, remove it with sed command directory names and group names

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

10. The use of the ifconfig command sed extracted IPv4 address in the machine

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

With repeated frequency divider 11. The penultimate field of statistics centos rpm to install all the files in the directory CD Package

[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 do not know it came from. . .

[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. Statistical /etc/init.d/functions the number of occurrences of each word in the file, and sort (realized respectively with grep and sed two methods)

This feeling should be no problems

[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

This seems not allowed, sed or not to take the word function

[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

This should be wrong. . .

[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. The n and n + 1 rows of the text file as a single line, line n is odd

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

sed advanced usage is sick, bald hair easily, not play not play

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

14. himself with some of the yum repository

[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 

Later compiled script

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. Compile a small thing

[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

Backup and restore partition table 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 partition
by cylinder

Up to four partitions, three primary partitions, an extended partition, extended partition can have multiple logical partitions.

Management of up to 2T space

GPT partition

By sector

128 partitions

Manage up of space 8Z

128 UUID

Partition table backup

17.parted command

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. The simulation file system fails

破坏
[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. The increase swap partition, the process did not write. Files can not use UUID, otherwise restart will be lost, write the file name.

[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. File Mounting File

创建一个大文件
[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. Migration / home data to a new place, in the maintenance state. That is, single-user mode. 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. Create a 2G file system block size of 2048 bytes, reserved 1% of the available space, file system ext4, the volume label TEST, required to automatically mount the partition / test directory boot, and acl mount options have default

[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

23. ⼀ write a script, the following functions: (1) lists the current system identifies all disk devices (2) as the number of disks is one, it is displayed Use spatial information. Otherwise, it displays the last spaces on the disk Use information.

#颜色配置
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% 

Description linux under 24. Frequently used files system which, what are their differences?

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. Personal configuration like a simple script.

#!/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 automatically install script

#!/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. The uninstall script 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"

Guess you like

Origin blog.51cto.com/14451122/2428332