Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write centos7 system initialization script

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to write the initialization script of the centos7 system, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

#! / bin/bash

While:

Do

Cat / dev/null

If [$?-eq 0]

Then

Echo "your network is in good condition"

Else

Echo "your network is not working and needs to be reconfigured"

Read-p "Please enter your network card name" name

Read-p "Please enter your IP address:" ip1

Ip2=echo $ip1 | awk-F "." 'BEGIN {FS= "."; OFS= "."} {print $1, 2, 2, 3}'.

Cat > ${network-dir} ifcfg-$ {name} / dev/null

If [$?-eq 0]

Then

Echo "Network restored"

Else

Echo is "hopeless"

Fi

Fi

}

Eth ()

{

Echo "- configuring, please wait a moment -"

Mv ${network_dir} ifcfg-$ {network_name} ${network_dir} ifcfg-eth0

Sed-I'/ ^ NAME/c NAME=eth0' ${network_dir} ifcfg-eth0

Sed-I'/ ^ DEVICE/c DEVICE=eth0' ${network_dir} ifcfg-eth0

Echo 'GRUB_CMDLINE_LINUX= ".net.ifnames=0" > / etc/sysconfig/grub

Grub2-mkconfig-o / boot/grub2/grub.cfg & > / dev/null

Echo "Please restart to make the Nic name effective"

}

Ssh_tools ()

{

Sed-I'/\ bPort\ b Port=22' c Port=22' ${sshd_dir} sshd_config

While:

Do

Read-p "decide not to allow root users to remotely log in to yapaan" login

Case $login in

y)

Sed-I'/ # PermitRootLogin/c PermitRootLogin = NO' ${sshd_dir} sshd_config

n)

Exit

)

Echo "Please follow the prompts to enter the content!"

Esac

Done

}

Yum_install ()

{

Echo "- yum source warehouse is being deployed, please have a sip of water and wait patiently -"

Rm-rf / etc/yum.repos.d/

Curl-o / etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo & > / dev/null

Yum-y install wget & > / dev/null

If [$?-eq 0]

Then

Echo is "almost there"

Else

Echo "Network error, please check the network"

Exit

Fi

Wget-O / etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo & > / dev/null

Echo "- clearing cache, please be patient! -"

Yum clean all & > / dev/null

Echo "- reloading, please wait patiently!"

Yum makecache & > / dev/null

Echo "- yum configuration successed-"

}

User () {

Read-p "Please enter the user name you want to create:" n

Read-p "Please enter the password for the user name" mima

Useradd $n & & echo "$mima" | passwd-- stdin $n & > / dev/null

Usermod-aG wheel $n

If [$?-eq 0]

Then

Echo "user created and rights granted successfully"

Else

Echo "user creation failed"

Exit

Fi

}

Root_power_off () {

Sed-I'/ HISTSIZE=/a\ TMOUT=300' / etc/profile & & echo "- successful-"

# 300s automatic logout of root account without operation

}

Time_ntp () {

# copy / usr/share/zoneinfo/Asia/Shanghai to / etc/localtime

# it is said that I am not allowed to write a copy order because of a forbidden word

# cp-f / usr/share/zoneinfo/Asia/Shanghai / etc/localtime

Yum-y install ntpdate & > / dev/null

Ntpdate 10.180.4.204

Echo "time synchronization successful"

}

Read-p "Please enter the parameter you want to select:" a

Case $an in

a)

Stop_firewalld

b)

Username

c)

Network_tools

d)

Eth

e)

Ssh_tools

f)

Yum_install

g)

User

h)

Root_power_off

i)

Time_ntp

q)

Exit

*)

Echo "Please follow the prompts above to enter!!"

Esac

Done

On how to write the centos7 system initialization script to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report