设为首页 收藏本站
查看: 800|回复: 0

用shell脚本实现通用二进制格式mysql 5.5.28 x86_64的安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-12-8 13:17:09 | 显示全部楼层 |阅读模式
首先在网上用gfsoso.com来搜索下载mysql软件包mysql-5.5.28-linux2.6-x86_64.tar.gz,再用
winSCP把mysql上传到服务器上,上传位置可根据个人喜好,我个人一般放在服务器的/usr/local/src目录下。
此处我们是先命令行下实现一次,而后所有操作全部用shell脚本自动实现。
个人环境 centos 6.5 X86-64  所用空闲空间都做成了LVM。
准备工作:
  • 1.    为mysql服务器创建mysql用户和组,此处我们创建一个用户id和组id都是306 的mysql名。mysql不能登陆系统。

[iyunv@localhost src]# groupadd -g 306 mysql
[iyunv@localhost src]# useradd -g306 -u 306 -r -s /bin/nologin mysql
[iyunv@localhost src]# tail -1 /etc/passwd
mysql:x:306:306::/home/mysql:/bin/nologin
2.Mysql数据库管理软件是用来存放数据的,因此需要为mysql创建一个存放数据的位置,此处我们就把数据存放在/mysql/data目录中。/mysql挂载到一个逻辑卷上。
  a.查看服务器中卷组信息,根据卷组中剩余空间我们来给定mysql数据指定空间。
[iyunv@localhostsrc]# vgdisplay
  --- Volume group ---
  VG Name               vg_lvm
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               49.97 GiB
  PE Size               32.00 MiB
  Total PE              1599
  Alloc PE / Size       800 / 25.00 GiB
  Free PE / Size       799 / 24.97 GiB  发现可用空间有25G左右
  VG UUID              3kConY-xNOG-sHdX-xopC-Ndee-toj1-zzdIVA
我们来给mysql存放的数据空间容量为5G
[iyunv@localhostsrc]# lvcreate -n data -L 5G /dev/vg_lvm
  Logical volume "data" created
[iyunv@localhostsrc]# mkdir /mysql
使用lvdisplay查看逻辑卷是否创建成功
[iyunv@localhostsrc]# lvdisplay
。。。。。。。。。。。。。。。。。。。
--- Logical volume---
  LV Path                /dev/vg_lvm/data
  LV Name                data
  VG Name                vg_lvm
  LV UUID               nYkURv-67Av-ST1L-05EL-rhGA-Dt1V-Rfl1cA
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain,2014-12-01 22:15:26 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             160
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
我们发现创建成功了,此时我们来格式化创建的逻辑卷
[iyunv@localhostsrc]# mkfs -t ext4 /dev/vg_lvm/data
mke2fs 1.41.12(17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096(log=2)
Fragment size=4096(log=2)
Stride=0 blocks,Stripe width=0 blocks
327680 inodes,1310720 blocks
65536 blocks(5.00%) reserved for the super user
First data block=0
Maximum filesystemblocks=1342177280
40 block groups
32768 blocks pergroup, 32768 fragments per group
8192 inodes pergroup
Superblock backupsstored on blocks:
        32768, 98304, 163840, 229376, 294912,819200, 884736

Writing inodetables: done                           
Creating journal(32768 blocks): done
Writingsuperblocks and filesystem accounting information: done

This filesystemwill be automatically checked every 21 mounts or
180 days,whichever comes first.  Use tune2fs -c or-i to override.
格式化成功
注意:此处写脚本时,应该让其睡眠一会
把创建的逻辑卷挂载到/mysql上,并让其开机后可以自动挂载,我们把挂载信息放到/etc/fstab文件上。
[iyunv@localhostsrc]# mount /dev/vg_lvm/data /mysql
[iyunv@localhostsrc]# vim /etc/fstab

/dev/vg_lvm             /mysql                  ext4    defaults        0  0添加到尾部
让系统读取/etc/fstab文件
[iyunv@localhostsrc]# mount -a
mount: /dev/vg_lvmis not a block device
挂载设备写错了修改
/dev/vg_lvm/data             /mysql                  ext4    defaults        0 0
此时在执行Mount  -a
[iyunv@localhostsrc]# ls /mysql/
lost+found
创建数据目录
[iyunv@localhostsrc]# mkdir /mysql/data
因此目录是给mysql用的,所以把权限改为mysql用户和组,由于是mysql使用,其他用户应该不给予任何权限操作。
[iyunv@localhostsrc]# chown -R mysql.mysql /mysql/data
[iyunv@localhostsrc]# chmod o=- /mysql/data
[iyunv@localhostsrc]# ls -ld /mysql/data/
drwxr-x---. 2mysql mysql 4096 Dec  1 22:34/mysql/data/

此时就可以进入操作mysql了
  • 1.    解压下载的mysql通用二进制格式的包到/usr/local目录下(是官方的要求)

[iyunv@localhost src]# ls
mysql-5.5.28-linux2.6-x86_64.tar.gz
[iyunv@localhost src]# tar xf mysql-5.5.28-linux2.6-x86_64.tar.gz -C /usr/local/
我们来为解压的mysql创建软连接
[iyunv@localhostlocal]#ln -sv mysql-5.5.28-linux2.6-x86_64/ mysql
`mysql' ->`mysql-5.5.28-linux2.6-x86_64/'
2.初始化mysql,需要使用mysql用户,在解压的目录下有一个INSTALL-BINARY文件,里面介绍了完整的安装mysql的说明
查看一下此文件
[iyunv@localhost~]# vim INSTALL-BINARY
。。。。。。。。。。。。。。。
shell> groupaddmysql
shell> useradd-r -g mysql mysql
shell> cd/usr/local
shell> tar zxvf/path/to/mysql-VERSION-OS.tar.gz
shell> ln -sfull-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -Rmysql .
shell> chgrp -Rmysql .
shell>scripts/mysql_install_db --user=mysql
shell> chown -Rroot .
shell> chown -Rmysql data
# Next command isoptional
shell> cpsupport-files/my-medium.cnf /etc/my.cnf
shell>bin/mysqld_safe --user=mysql &
# Next command isoptional
shell> cpsupport-files/mysql.server /etc/init.d/mysql.server

   A more detailed version of the precedingdescription for
   installing a binary distribution follows.
   Note

   This procedure assumes that you have root(administrator) access
   to your system. Alternatively, you canprefix each command using
   the sudo (Linux) or pfexec (OpenSolaris)command.

   The procedure does not set up any passwordsfor MySQL accounts.
   After following the procedure, proceed toSection 2.10,
   "Postinstallation Setup andTesting."
。。。。。。。。。。。。。。。
更多信息可以自己去查看
[iyunv@localhostlocal]# chown -R mysql.mysql /usr/local/mysql/*
[iyunv@localhostlocal]# ls -l mysql/
total 76
drwxr-xr-x.  2 mysql mysql 4096 Dec  1 22:41 bin
-rw-r--r--.  1 mysql mysql 17987 Aug 29  2012 COPYING
drwxr-xr-x.  4 mysql mysql 4096 Dec  1 22:41 data
drwxr-xr-x.  2 mysql mysql 4096 Dec  1 22:41 docs
drwxr-xr-x.  3 mysql mysql 4096 Dec  1 22:41 include
-rw-r--r--.  1 mysql mysql 7604 Aug 29  2012 INSTALL-BINARY
drwxr-xr-x.  3 mysql mysql 4096 Dec  1 22:41 lib
drwxr-xr-x.  4 mysql mysql 4096 Dec  1 22:41 man
drwxr-xr-x. 10mysql mysql  4096 Dec  1 22:41 mysql-test
-rw-r--r--.  1 mysql mysql 2552 Aug 29  2012 README
drwxr-xr-x.  2 mysql mysql 4096 Dec  1 22:41 scripts
drwxr-xr-x. 27mysql mysql  4096 Dec  1 22:41 share
drwxr-xr-x.  4 mysql mysql 4096 Dec  1 22:41 sql-bench
drwxr-xr-x.  2 mysql mysql 4096 Dec  1 22:41 support-files
在scripts目录下有mysql的初始化脚本
查看有什么选项
[iyunv@localhostmysql]# scripts/mysql_install_db --help
Usage:scripts/mysql_install_db [OPTIONS]
  --basedir=path       The path to the MySQL installationdirectory.
  --builddir=path      If using --srcdir with out-of-directorybuilds, you
                       will need to set this tothe location of the build
                       directory where builtfiles reside.
  --cross-bootstrap    For internal use.  Used when building the MySQL system
                       tables on a differenthost than the target.
  --datadir=path       The path to the MySQL data directory.
  --defaults-extra-file=name
                       Read this file after theglobal files are read.
  --defaults-file=name Only read defaultoptions from the given file name.
  --force              Causes mysql_install_db to runeven if DNS does not
                       work.  In that case, grant table entries thatnormally
                       use hostnames will useIP addresses.
  --help               Display this help and exit.                     
  --ldata=path         The path to the MySQL data directory.Same as --datadir.
  --no-defaults        Don't read default options from anyoption file.
  --rpm                For internal use.  This option is used by RPM files
                       during the MySQLinstallation process.
  --skip-name-resolve  Use IP addresses rather than hostnames whencreating
                       grant tableentries.  This option can be useful if
                       your DNS does not work.
  --srcdir=path        The path to the MySQL sourcedirectory.  This option
                       uses the compiledbinaries and support files within the
                       source tree, useful forif you don't want to install
                       MySQL yet and just wantto create the system tables.
  --user=user_name     The login username to use for runningmysqld.  Files
                       and directories createdby mysqld will be owned by this
                       user.  You must be root to use this option.  By default
                       mysqld runs using yourcurrent login name and files and
                       directories that itcreates will be owned by you.

All other optionsare passed to the mysqld program
此处我们使用
[iyunv@localhostmysql]# scripts/mysql_install_db --user=mysql --datadir=/mysql/data/
Installing MySQLsystem tables...
OK
Filling helptables...
OK

To start mysqld atboot time you have to copy
support-files/mysql.serverto the right place for your system

PLEASE REMEMBER TOSET A PASSWORD FOR THE MySQL root USER !
To do so, startthe server, then issue the following commands:

./bin/mysqladmin-u root password 'new-password'
./bin/mysqladmin-u root -h localhost.localdomain password 'new-password'

Alternatively youcan run:
./bin/mysql_secure_installation

which will alsogive you the option of removing the test
databases andanonymous user created by default.  Thisis
stronglyrecommended for production servers.

See the manual formore instructions.

You can start theMySQL daemon with:
cd . ;./bin/mysqld_safe &

You can test theMySQL daemon with mysql-test-run.pl
cd ./mysql-test ;perl mysql-test-run.pl

Please report anyproblems with the ./bin/mysqlbug script!
初始化过程非常详细,且接下来操作也都显示出来了
初始化完成后,记住mysql的安装目录/usr/local/mysql下各文件的属组不应该给mysql用户,如果出现mysql被人攻破时,将获得整个文件的权限,所以一般把此目录改为root.
[iyunv@localhostmysql]# chown -R root.root /usr/local/mysql/*
下mysql.server是mysql的启动脚本,把它复制到/etc/init.d/目录下即可
[iyunv@localhostmysql]# cp support-files/mysql.server /etc/init.d/mysqld
加入到启动列表中
[iyunv@localhostmysql]# chkconfig --add mysqld
查看开机是否自动启动
[iyunv@localhostmysql]# chkconfig --list mysqld
mysqld          0:off   1:off  2:on    3:on    4:on   5:on    6:off
此时还不能启动mysql,我们来为mysql提供配置文件,其配置文件在/etc/my.cnf,在安装目录support-files下给我们提供了
MySQL:配置文件格式, 是集中式配置文件,可以为多个程序提供配置
[mysql] 客户端全局配置
。。。。

[mysqld] 服务器端全局配置
。。。。

[client] 对于所有的客户端程序都生效配置
。。。。

配置文件路径可以有多个路径
查找顺序依次为:
/etc/my.cnf -->/etc/mysql/my.cnf --> $BASEDIR/my.cnf --> ~/.my.cnf
$BASEDIR  mysql实例的运行目录,一般为安装目录
是以最后查找到的配置为标准的。还有就算没有配置文件mysql也可以运行,因为mysql的很多配置都是默认定义的
[iyunv@localhostmysql]# ls support-files/
binary-configure   magic                   my-medium.cnf        mysql.server
config.huge.ini    my-huge.cnf             my-small.cnf         ndb-config-2-node.ini
config.medium.ini  my-innodb-heavy-4G.cnf  mysqld_multi.server
config.small.ini   my-large.cnf            mysql-log-rotate
有多种格式 my-medium|huge|small....conf是以内存大小来分的,有兴趣可以自己查看
[iyunv@localhostmysql]# cp support-files/my-huge.cnf /etc/my.cnf
在[mysqld]添加一项,指定mysql的数据目录
datadir =/sqldata/data
把执行路径添加到PATH
[iyunv@localhostmysql]# echo "PATH=$PATH:/usr/local/mysql/bin" >/etc/profile.d/mysql.sh
执行此脚本
[iyunv@localhostmysql]# .  /etc/profile.d/mysql.sh
启动mysql
[iyunv@localhostmysql]# service mysqld start
Starting MySQL...SUCCESS!
[iyunv@localhostmysql]# mysql
Welcome to theMySQL monitor.  Commands end with ; or\g.
Your MySQLconnection id is 1
Server version:5.5.28-log MySQL Community Server (GPL)

Copyright (c)2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is aregistered trademark of Oracle Corporation and/or its
affiliates. Othernames may be trademarks of their respective
owners.

Type 'help;' or'\h' for help. Type '\c' to clear the current input statement.

mysql> \q
Bye

导出二进制文件、导出库文件、导出头文件、导出man文件不是一定要做的,可以根据需要自己系统环境要求选择导出相应的目录
mysql帮助文档目录
[iyunv@localhostmysql]# ls /usr/local/mysql/man/
man1  man8
输出mysql的帮助文件,编辑/etc/man.config
在MANPATH那行添加mysql的man路径
#
# Everyautomatically generated MANPATH includes these fields
#
MANPATH /usr/man
MANPATH/usr/share/man
MANPATH/usr/local/man
MANPATH/usr/local/share/man
MANPATH/usr/X11R6/man
添加MANPATH /usr/local/mysql/man
输出mysql的库文件
[iyunv@localhostmysql]# ls /usr/local/mysql/lib/
在/etc/ld.so.conf.d/下面新增一个mysql.conf文件,把mysql的库文件路径添加到mysql.conf中。
再执行ldconfig -v使其生效  -v是显示过程的,让系统重新读取库文件到缓存中,系统的缓存文件
为/etc/ld.so.cache
[iyunv@localhostmysql]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[iyunv@localhostmysql]# ldconfig -v
输出头文件,用创建连接的方式实现
[iyunv@localhostmysql]# ln -sv /usr/local/mysql/include /usr/include/mysql
`/usr/include/mysql'-> `/usr/local/mysql/include'
[iyunv@localhostmysql]# ls /usr/include/mysql/
decimal.h       my_compiler.h  my_net.h         mysql.h            plugin.h
errmsg.h        my_config.h    my_pthread.h     mysql_time.h       sql_common.h
。。。。。。
完成了
脚本实现
#!/bin/bash
#current derectoryis /usr/local/
#Automation mysqlinstallation
groupadd -g 306mysql
useradd -g 306 -u306 -r -s /sbin/nologin mysql

lvcreate -n data-L 10G /dev/vg_lvm > /dev/null
mkdir /mysql
mkfs -t ext4/dev/vg_lvm/data >/dev/null
sleep 3
mount/dev/vg_lvm/data /mysql
echo"/dev/vg_lvm/data   /mysql    ext4  defaults  00">>/etc/fstab
mount -a

mkdir /mysql/data
chown -Rmysql.mysql /mysql/data
chmod -R o=-/mysql/data

tar xf/usr/local/src/mysql-5.5.28-linux2.6-x86_64.tar.gz -C /usr/local/
sleep 10

ln -sv/usr/local/mysql-5.5.28-linux2.6-x86_64/ /usr/local/mysql >/dev/null
chown -Rmysql.mysql /usr/local/mysql/*

/usr/local/mysql/scripts/mysql_install_db--user=mysql --datadir=/mysql/data/ --basedir=/usr/local/mysql >/dev/null
sleep 3



chown -R root/usr/local/mysql/*

cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --addmysqld
[ -e /etc/my.cnf ]&& rm -f /etc/my.cnf ] && cp /usr/local/mysql/support-files/my-huge.cnf/etc/my.cnf -f

sed -i'/^\[mysqld\]/a datadir=/mysql/data' /etc/my.cnf
echo"PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
./etc/profile.d/mysql.sh
service mysqldstart >/dev/null
sleep 2
mysql
有什么漏掉了,希望可以帮忙指正   谢谢




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-37594-1-1.html 上篇帖子: shell基础及流程控制语句之一case判断 下篇帖子: 使用shell脚本实现自动化部署hadoop集群 二进制 通用 mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表