shell脚本
初始化虚拟机+安装mysql+安装jdk
mac_init(){
hostnamectl set-hostname $1
echo $2" "$1 >> /etc/hosts
sed -i 's/dhcp/static/g' /etc/sysconfig/network-scripts/ifcfg-ens33
echo 'IPADDR="'$2'"' >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo 'NETMASK="255.255.255.0"' >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo 'GATEWAY="'$3'"' >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo 'DNS1="114.114.114.114"' >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo 'DNS2="8.8.8.8"' >> /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network
yum install -y wget vim gcc
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo_bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
systemctl stop firewalld
systemctl disable firewalld
}
setup_mysql(){
marlst=`rpm -qa | grep mariadb`
for fl in $marlst
do
rpm -e --nodeps $fl
done
cd /opt/
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server -y
chown -R root:root /var/lib/mysql
chown root /var/lib/mysql/
service mysqld restart
mysql -uroot -e "use mysql;update user set Password = password('123456') where User='root';GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '123456';flush privileges;"
sed -i "/\[mysqld\]/a character-set-server=utf8" /etc/my.cnf
service mysqld restart
}
setup_jdk(){
if [ ! -d "/opt/soft" ];then
mkdir -p /opt/soft
fi
if [ ! -d "/opt/soft/jdk180" ];then
cd /opt/
mkdir -p /opt/soft/jdk180
tar -zxf /opt/jdk-8u111-linux-x64.tar.gz -C /opt/soft/jdk180 --strip-components 1
if [ "$JAVA_HOME" == "" ];then
echo "#java environment" >> /etc/profile
echo "export JAVA_HOME=/opt/soft/jdk180" >> /etc/profile
echo "export CLASSPATH=.:\${JAVA_HOME}/jre/lib/rt.jar:\${JAVA_HOME}/lib/dt.jar:\${JAVA_HOME}/lib/tools.jar" >> /etc/profile
echo "export PATH=\$PATH:\${JAVA_HOME}/bin" >> /etc/profile
fi
else
echo "jdk180 is exist"
fi
}
mac_init $1 $2 $3
setup_mysql
setup_jdk