Linux环境准备
Posted zhouwanchun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux环境准备相关的知识,希望对你有一定的参考价值。
#!/bin/bash #----------------------------------------------------------# # Date : 2018-xx-xx # # Author : Created by zhouwanchun. # # Wechat : loveoracle11g # # Function: This scripts function is install linux OS. # # Version : 1.1 # #----------------------------------------------------------# # 查看系统版本 cat /etc/redhat-release # 查看系统内核 uname -rm # 关闭防火墙 systemctl stop firewalld systemctl disable firewalld # 关闭SELinux sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/sysconfig/selinux sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config # 确保NetworkManager服务是开着的 systemctl stop NetworkManager systemctl disable NetworkManager # 修改Linux终端提示符颜色 # echo "PS1=‘[\[\033[1;31m\]\u\[\033[0m\]@\[\033[1;32m\]\h \[\033[1;36m\]\w\[\033[0m\]]\\$ ‘" >> ~/.bashrc echo "PS1=‘[\[\033[1;32m\]\u\[\033[0m\]@\[\033[1;35m\]\h \[\033[1;36m\]\w\[\033[0m\]]\\$ ‘" >> ~/.bashrc source ~/.bashrc # 设置主机名 cat > /etc/hostname <<EOF mysql-db01 EOF # 主机名解析 cat >> /etc/hosts <<EOF 10.0.0.11 mysql-db01 10.0.0.12 mysql-db02 10.0.0.13 mysql-db03 EOF # 连接镜像并挂载 mkdir /media/cdrom mount /dev/cdrom /media/cdrom df -Th # 配置本地yum仓库 cd /etc/yum.repos.d/ ls -l mkdir repo mv CentOS-* repo/ ls -l cat >> local.repo <<EOF [base] name=CentOS-localhost-iso baseurl=file:///media/cdrom enabled=1 gpgcheck=0 EOF cd ~ # 查看yum仓库 yum repolist all # 刷包 yum list all | wc -l # 安装Linux常用的rpm工具包 yum -y install bash-completion bash-completion-extras vim vim-enhanced net-tools wget screen mtr nc nmap ntp ntpdate tree lrzsz lsof gcc gcc-c++ glibc make zip unzip dos2unix sysstat telnet tcpdump htop iftop iotop nethogs psmisc iptraf dstat OpenIPMI-tools openssl-devel zlib-devel ncurses-devel libaio-devel bind-utils xorg-x11-server-utils # 配置网卡网络 cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak cp /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth1.bak cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF TYPE=Ethernet BOOTPROTO=static NAME=eth0 DEVICE=eth0 ONBOOT=yes DEFROUTE=yes PEERDNS=no PEERROUTES=yes IPV4_FAILURE_FATAL=no IPADDR=10.0.0.11 NETMASK=255.255.255.0 GATEWAY=10.0.0.2 EOF cat > /etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF TYPE=Ethernet BOOTPROTO=static NAME=eth1 DEVICE=eth1 ONBOOT=yes IPADDR=192.168.10.11 NETMASK=255.255.255.0 EOF # 重启网卡 //etc/init.d/network restart # 查看网络 ifconfig # 查看DNS客户端配置文件 cat >> /etc/resolv.conf <<EOF nameserver 10.0.0.2 nameserver 223.5.5.5 nameserver 223.6.6.6 EOF # 使用dig验证 dig www.taobao.com +short # 测试网络能不能和外网ping通 ping -c 4 www.baidu.com # 创建常用目录 mkdir -p /disk/soft,tools chmod -R 777 /disk mkdir /app mkdir /data mkdir /backup # 配置网络阿里云yum源 umount /dev/cdrom /media/cdrom ping -c 4 opsx.alibaba.com cd /etc/yum.repos.d/ mv local.repo local.repo.bak wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo sed -i ‘s#\$releasever#7#g‘ /etc/yum.repos.d/CentOS-Base.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo ls -l cd ~ yum clean all yum makecache yum repolist all yum list all | wc -l # yum -y update # example.sh touch /root/example.sh cat > /root/example.sh <<EOF #!/bin/bash #----------------------------------------------------------# # Date : xxxx-xx-xx # # Author : Created by zhouwanchun. # # Wechat : loveoracle11g # # Function: This scripts function is ... # # Version : 1.1 # #----------------------------------------------------------# EOF # 清空命令历史 > ~/.bash_history history -c # 重启 reboot # 完成 #----------------------------------------------------------# # Date : 2018-xx-xx # # Author : Created by zhouwanchun. # # Wechat : loveoracle11g # # Function: This scripts function is install linux OS. # # Version : 1.1 # #----------------------------------------------------------#
以上是关于Linux环境准备的主要内容,如果未能解决你的问题,请参考以下文章