Chinaunix首页 | 论坛 | 博客
  • 博客访问: 239076
  • 博文数量: 37
  • 博客积分: 325
  • 博客等级: 一等列兵
  • 技术积分: 1199
  • 用 户 组: 普通用户
  • 注册时间: 2012-06-09 00:04
个人简介

坚持原创,虽然有些东西很简单,但也算是一种积累。

文章分类

全部博文(37)

文章存档

2013年(28)

2012年(9)

我的朋友

分类: Python/Ruby

2013-01-10 10:54:42

还没写完,是写给群体安装的,配置也没有完成。其它机器打算用expect来执行sh,也还不写。

点击(此处)折叠或打开

  1. #!/bin/bash
  2. #mysql安装(集群)
  3. main_path=/root/mysql/
  4. install_name=mysql-max-5.0.24-linux-i686.tar.gz
  5. install_path=/usr/local/mysql/
  6. env_fun() #环境
  7. {
  8. echo "-------检测本机环境,请稍等-------"
  9. username=`cat /etc/passwd|grep mysql|cut -c 1-5`
  10.         if [ $username = "mysql" ];then
  11.                 echo "用户检测:mysql已存在"
  12.                 return 10
  13.         else
  14.                 echo "用户检测:mysql用户不存在,添加"
  15.                 groupadd mysql
  16.                 useradd mysql -g mysql
  17.                 return 12
  18.         fi
  19. }
  20. #判断mysql是否安装(rpm、source)
  21. check_fun()
  22. {
  23. rpm_name=`rpm -aq |grep mysql-server`
  24.         if [ ! $rpm_name ];then
  25.                 echo "开始检测源码包是否安装,请稍等......"
  26.                         if [ -d $install_path ];then
  27.                                 echo "源码:$install_path目录已存在,退出本次安装."
  28.                                 exit 0
  29.                         else
  30.                                 echo "本机未安装任何mysql程序,将为您开始安装$install_name.请稍等......"
  31.                                 install_fun
  32.                         fi

  33.         else
  34.                 echo -n "rpm mysql已安装,是否删除?[yes|no]"
  35.                 read select
  36.                         if [ $select = yes ];then
  37.                                 rpm -ev $rpm_name --nodeps
  38.                                 rm -rf /var/log/mysqld.log
  39.                                 check_fun
  40.                         else
  41.                                 exit 0
  42.                         fi
  43.         fi
  44. }
  45. install_fun() #安装函数
  46. {
  47. cd $main_path
  48. echo "正在解压,请稍等......"
  49. tar zxvf $install_name
  50. echo "建立相应目录"
  51. echo "mkdir -p /usr/local/mysql/"
  52. mkdir -p /usr/local/mysql/
  53. echo "mkdir -p /usr/local/mysql/data/"
  54. mkdir -p /usr/local/mysql/data/
  55. cd mysql-max-5.0.24-linux-i686/bin/
  56. echo "cp ndb_mgm* /usr/local/mysql/"
  57. cp ndb_mgm* /usr/local/mysql/
  58. echo "chown -R mysql:mysql /usr/local/mysql/"
  59. chown -R mysql:mysql /usr/local/mysql/
  60. #配置
  61. }
  62. main()
  63. {
  64. echo "#***********************************#"
  65. echo "# 欢迎使用mysql集群安装脚本 #"
  66. echo "# Copyright 2013 by wanggy #"
  67. echo "#***********************************#"
  68. sleep 3
  69. #开始执行,调用检测函数
  70. env_fun
  71. re=$?
  72. if [ re = 10 ];then
  73.         check_fun
  74. else
  75.         check_fun
  76. fi
  77. }
  78. main
  79. exit 0

阅读(1401) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~