Linux系统环境自动化配置~init.sh分享

Posted yexuesong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux系统环境自动化配置~init.sh分享相关的知识,希望对你有一定的参考价值。

#!/bin/bash

#---Sysinit script by yxs---
#---email: [email protected]


if [[ "$(whoami)" != "root" ]]; 
then
    echo "please run this script as root ." >&2
    exit 1
fi

#yum source config
yum_config(){
    yum install wget epel-release -y
    cd /etc/yum.repos.d/ && mkdir bak && mv -f *.repo bak/
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    yum clean all && yum makecache
    yum -y groupinstall Development Tools
    yum -y install python-pip man lsof iotop iftop net-tools lrzsz gcc gcc-c++ make cmake libxml2-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel wget vim ncurses-devel autoconf automake zlib-devel  python-devel bash-completion
}

#firewalld config
iptables_config(){
    systemctl stop firewalld.service
    systemctl disable firewalld.service
    ifconfig | grep -q inet6
    if [ $? == 0 ]
    then
    echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf
    echo "net.ipv6.conf.default.disable_ipv6 = 1" >> /etc/sysctl.conf
    sed -i s/::1/#::1/ /etc/hosts
    fi
}

#system config
system_config(){
    yum update -y
    hostnamectl set-hostname yxs
    sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
    timedatectl set-local-rtc 1 && timedatectl set-timezone Asia/Shanghai
    yum -y install chrony && systemctl start chronyd.service && systemctl enable chronyd.service 
}

#app_config
app_config(){
    mkdir -p /usr/download/ && cd /usr/download
    wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
    tar -xvf Python-3.6.4.tgz -C /usr/local
    cd /usr/local/Python-3.6.4
    ./configure --prefix=/usr/local/python-3.6.4 --enable-shared
    make && make install
    ln -sv /usr/local/python-3.6.4/bin/python3 /usr/bin/python3 
    ln -sv /usr/local/python-3.6.4/bin/pip3 /usr/bin/pip3
    pip install --upgrade pip
    echo /usr/local/python-3.6.4/lib >> /etc/ld.so.conf
    /sbin/ldconfig -v
    mkdir -p /home/envs
    virtualenv -p /usr/bin/python3 /home/envs/py3env
    ln -s /home/envs/py3env/bin/activate /root/py3
    

}

main(){
    yum_config
    iptables_config
    system_config
    app_config
}
main
reboot

 

以上是关于Linux系统环境自动化配置~init.sh分享的主要内容,如果未能解决你的问题,请参考以下文章

Linux基本环境配置命令分享(持续更新中……)

Linux系统下安装jdk及环境配置(两种方法)

配置linux环境实现持续集成

dos批处理下自动给环境变量赋值的问题

redis配置读写分离以及利用哨兵sentinel进行自动主从切换

设置及查看Linux的环境变量详细教程