还没写完,是写给群体安装的,配置也没有完成。其它机器打算用expect来执行sh,也还不写。
- #!/bin/bash
- #mysql安装(集群)
- main_path=/root/mysql/
- install_name=mysql-max-5.0.24-linux-i686.tar.gz
- install_path=/usr/local/mysql/
- env_fun() #环境
- {
- echo "-------检测本机环境,请稍等-------"
- username=`cat /etc/passwd|grep mysql|cut -c 1-5`
- if [ $username = "mysql" ];then
- echo "用户检测:mysql已存在"
- return 10
- else
- echo "用户检测:mysql用户不存在,添加"
- groupadd mysql
- useradd mysql -g mysql
- return 12
- fi
- }
- #判断mysql是否安装(rpm、source)
- check_fun()
- {
- rpm_name=`rpm -aq |grep mysql-server`
- if [ ! $rpm_name ];then
- echo "开始检测源码包是否安装,请稍等......"
- if [ -d $install_path ];then
- echo "源码:$install_path目录已存在,退出本次安装."
- exit 0
- else
- echo "本机未安装任何mysql程序,将为您开始安装$install_name.请稍等......"
- install_fun
- fi
- else
- echo -n "rpm mysql已安装,是否删除?[yes|no]"
- read select
- if [ $select = yes ];then
- rpm -ev $rpm_name --nodeps
- rm -rf /var/log/mysqld.log
- check_fun
- else
- exit 0
- fi
- fi
- }
- install_fun() #安装函数
- {
- cd $main_path
- echo "正在解压,请稍等......"
- tar zxvf $install_name
- echo "建立相应目录"
- echo "mkdir -p /usr/local/mysql/"
- mkdir -p /usr/local/mysql/
- echo "mkdir -p /usr/local/mysql/data/"
- mkdir -p /usr/local/mysql/data/
- cd mysql-max-5.0.24-linux-i686/bin/
- echo "cp ndb_mgm* /usr/local/mysql/"
- cp ndb_mgm* /usr/local/mysql/
- echo "chown -R mysql:mysql /usr/local/mysql/"
- chown -R mysql:mysql /usr/local/mysql/
- #配置
- }
- main()
- {
- echo "#***********************************#"
- echo "# 欢迎使用mysql集群安装脚本 #"
- echo "# Copyright 2013 by wanggy #"
- echo "#***********************************#"
- sleep 3
- #开始执行,调用检测函数
- env_fun
- re=$?
- if [ re = 10 ];then
- check_fun
- else
- check_fun
- fi
- }
- main
- exit 0
阅读(1401) | 评论(0) | 转发(1) |