Linux 初始化文档

2020-05-28  本文已影响0人  程序员的自我修养

centos7_init.sh

#!/bin/env bash

# 说明

## 以root用户运行

# 设置SELinux

mkdir -p /etc/sysconfig/bak

cp -a /etc/sysconfig/selinux /etc/sysconfig/bak/

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

setenforce 0

# 设置防火墙

systemctl disable firewalld

systemctl stop firewalld

# 设置IP

mkdir -p /etc/sysconfig/network-scripts/bak

cp -a /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/bak/

tee /etc/sysconfig/network-scripts/ifcfg-enp0s3 <<EOF

TYPE=Ethernet

BOOTPROTO=none

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=no

IPV6_AUTOCONF=no

IPV6_DEFROUTE=no

IPV6_PEERDNS=no

IPV6_PEERROUTES=no

IPV6_FAILURE_FATAL=no

IPV6_ADDR_GEN_MODE="stable-privacy"

# UUID="d99e9723-518d-4258-8563-a83bcbde1c49"

ONBOOT=yes

MN_CONTROLLED=no

NAME=enp0s3

HWADDR='08:00:27:E9:DC:FE'

IPADDR0=192.168.1.11

PREFIX0=24

GATEWAY0=192.168.1.1

DNS1=202.96.134.133

DNS2=8.8.8.8

EOF

systemctl restart network

# 更新时间

yum -y install ntpdate

ntpdateus.pool.ntp.org

# 设置主机名

mkdir -p /etc/bak

cp -a /etc/hostname /etc/bak/

tee /etc/hostname <<EOF

CMe11

EOF

# 设置hosts

cp -a /etc/hosts /etc/bak/

tee -a /etc/hosts <<EOF

127.0.0.1    CMe11

172.17.0.1    CMe11

EOF

# 安装vim并修改其配置

yum -y install vim-enhanced

tee -a /etc/vimrc <<EOF

" los2 add

set nu

set encoding=utf-8

set fileencoding=utf-8

set fileencodings=ucs-bom,utf-8,gb2312,gbk,big5,ascii,latin1

syntax on

set tabstop=4

EOF

# 增加用户profile文件

tee /etc/profile.d/my_profile.sh <<EOF

alias grep='grep --color=auto'

alias egrep='egrep --color=auto'

alias vi='vim'

alias ll='ls -hl --color=auto'

EOF

source /etc/profile.d/my_profile.sh

# 创建定时任务,用于同步时间等

mkdir -p /var/lock/crontab

mkdir -p /data/app/crontab

# todo:这里手动执行类似如下命令的操作

# cp -a /mnt/notebook/linux/crontab/cnf/$crontab_file_example /data/app/crontab/$crontab_file

# 设置ssh

sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 60/g' /etc/ssh/sshd_config

sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 3/g' /etc/ssh/sshd_config

# 创建用户,并配置sudoer

useradd admin

useadd los

usermod -aG admin los

tee /etc/sudoers.d/admin <<EOF

%admin    ALL=(ALL)   NOPASSWD: ALL

EOF

上一篇下一篇

猜你喜欢

热点阅读