Chinaunix首页 | 论坛 | 博客
  • 博客访问: 58835
  • 博文数量: 28
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-18 16:54
个人简介

处于初期技术人员,故只转载,而没有动笔写作,慢慢的就会自己去写一些的,前提是熟悉了这个行业,熟悉了这门技术之后,现在还是在不断的学习和探讨中。。。。。。

文章分类
文章存档

2013年(28)

我的朋友

分类: Python/Ruby

2013-12-20 16:40:55

还没写完,是写给群体安装的,配置也没有完成。其它机器打算用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

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