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

[经验分享] 二进制格式安装mariadb-5.5.36

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-1-8 09:42:46 | 显示全部楼层 |阅读模式
1、下载到Linux中
     mariadb 二进制分发版(类似于windows上的下载解压后可直接运行的绿色软件)的文件名格式为 mariadb-VERSION-OS.tar.gz,其中 VERSION 是版本号,OS表示分发版安装的操作系统类型
     可到官网下载:
        https://downloads.mariadb.org

2、解压到指定目录,并为解压后的目录创建一个名为mysql的链接
     tar xf mysql-5.5.42-linux2.6-x86_64.tar.gz -C /usr/local/     
     cd /usr/local
     ln -s mariadb-5.5.36-linux-x86_64 mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[iyunv@node1 ~]# tar -xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local
[iyunv@node1 ~]# cd /usr/local
[iyunv@node1 local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mariadb-5.5.36-linux-x86_64  sbin  share  src
[iyunv@node1 local]# ln -s mariadb-5.5.36-linux-x86_64/ mysql
[iyunv@node1 local]# cd mysql
[iyunv@node1 mysql]# ls
bin  COPYING  COPYING.LESSER  data  docs  include  INSTALL-BINARY  lib  man  mysql-test  README  scripts  share  sql-bench  support-files
[iyunv@node1 mysql]# less INSTALL-BINARY    #查看安装说明
...
   The basic commands that you must execute to install and use a
   MariaDB binary distribution are:

shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &

Note
...



3、添加mysql用户和mysql组
     mariadb(mysql)是以系统用户mysql的身份运行的,因此这里首先创建一个系统用户mysql
       groupadd mysql
       useradd -r -g mysql mysql
1
2
3
[iyunv@node1 ~]# useradd -r mysql
[iyunv@node1 ~]# id mysql
uid=496(mysql) gid=493(mysql) groups=493(mysql)



4、更改目录属主属组
     chown -R root:mysql /usr/local/mysql (mysql目录的属主、属组分别设为root和mysql,注意,mysql目录下有个data目录,如果欲将其作为数据目录,其属主应修改为mysql)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[iyunv@node1 mysql]# ll
total 212
drwxr-xr-x  2 root         root           4096 Jan  3 11:08 bin
-rw-r--r--  1 wittgenstein wittgenstein  17987 Feb 24  2014 COPYING
-rw-r--r--  1 wittgenstein wittgenstein  26545 Feb 24  2014 COPYING.LESSER
drwxr-xr-x  3 root         root           4096 Jan  3 11:08 data
drwxr-xr-x  2 root         root           4096 Jan  3 11:08 docs
drwxr-xr-x  3 root         root           4096 Jan  3 11:08 include
-rw-r--r--  1 wittgenstein wittgenstein   8694 Feb 24  2014 INSTALL-BINARY
drwxr-xr-x  3 root         root           4096 Jan  3 11:08 lib
drwxr-xr-x  4 root         root           4096 Jan  3 11:08 man
drwxr-xr-x 11 root         root           4096 Jan  3 11:08 mysql-test
-rw-r--r--  1 wittgenstein wittgenstein 108813 Feb 24  2014 README
drwxr-xr-x  2 root         root           4096 Jan  3 11:08 scripts
drwxr-xr-x 27 root         root           4096 Jan  3 11:08 share
drwxr-xr-x  4 root         root           4096 Jan  3 11:08 sql-bench
drwxr-xr-x  4 root         root           4096 Jan  3 11:08 support-files
[iyunv@node1 mysql]# chown -R root.mysql .
[iyunv@node1 mysql]# ll
total 212
drwxr-xr-x  2 root mysql   4096 Jan  3 11:08 bin
-rw-r--r--  1 root mysql  17987 Feb 24  2014 COPYING
-rw-r--r--  1 root mysql  26545 Feb 24  2014 COPYING.LESSER
drwxr-xr-x  3 root mysql   4096 Jan  3 11:08 data
drwxr-xr-x  2 root mysql   4096 Jan  3 11:08 docs
drwxr-xr-x  3 root mysql   4096 Jan  3 11:08 include
-rw-r--r--  1 root mysql   8694 Feb 24  2014 INSTALL-BINARY
drwxr-xr-x  3 root mysql   4096 Jan  3 11:08 lib
drwxr-xr-x  4 root mysql   4096 Jan  3 11:08 man
drwxr-xr-x 11 root mysql   4096 Jan  3 11:08 mysql-test
-rw-r--r--  1 root mysql 108813 Feb 24  2014 README
drwxr-xr-x  2 root mysql   4096 Jan  3 11:08 scripts
drwxr-xr-x 27 root mysql   4096 Jan  3 11:08 share
drwxr-xr-x  4 root mysql   4096 Jan  3 11:08 sql-bench
drwxr-xr-x  4 root mysql   4096 Jan  3 11:08 support-files



5、通常应将mariadb(mysql)数据存储于逻辑卷上,易于扩展

     先创建两个分区/dev/sda3,4
     创建pv:
          pvcreate /dev/sda{3,4}
     创建vg:
          vgcreate myvg /dev/sda{3,4}
     创建lv:
          lvcreate -L 20G -n mydata myvg
     格式化:
          mke2fs -t ext4 -L MYDATA -b 4096 -m 3 /dev/myvg/mydata
     修改/etc/fstab文件,使其能够自动挂载
          LABEL=MYDATA(或UUID或/dev/mapper/myvg-lvdata)    /mydata   ext4   defaults  0  0
     创建挂载点
          mkdir /mydata
          mount -a     
     在/mydata下创建data目录,并修改其属主属组
          mkdir /mydata/data
          chown -R mysql.mysql /mydata/data
          这样,mariadb的数据目录就创建好了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
[iyunv@node1 mysql]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f3804

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1332    10485760   83  Linux
/dev/sda3            1332        1593     2097152   82  Linux swap / Solaris

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First cylinder (1593-3916, default 1593):
Using default value 1593
Last cylinder, +cylinders or +size{K,M,G} (1593-3916, default 3916):
Using default value 3916

Command (m for help): n
First cylinder (1593-3916, default 1593):
Using default value 1593
Last cylinder, +cylinders or +size{K,M,G} (1593-3916, default 3916): +10G

Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f3804

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1332    10485760   83  Linux
/dev/sda3            1332        1593     2097152   82  Linux swap / Solaris
/dev/sda4            1593        3916    18666534    5  Extended
/dev/sda5            1593        2898    10489417+  8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[iyunv@node1 mysql]# partx -a /dev/sda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
[iyunv@node1 mysql]# partx -a /dev/sda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
[iyunv@node1 mysql]# pvcreate /dev/sda5
  Physical volume "/dev/sda5" successfully created
[iyunv@node1 mysql]# vgcreate myvg /dev/sda5
  Volume group "myvg" successfully created
[iyunv@node1 mysql]# lvcreate -L 5G -n lvdata myvg
  Logical volume "lvdata" created
[iyunv@node1 mysql]# lvremove /dev/myvg/lvdata
Do you really want to remove active logical volume lvdata? [y/n]: y
  Logical volume "lvdata" successfully removed
[iyunv@node1 mysql]# lvcreate -L 5G -n mydata myvg
  Logical volume "mydata" created
[iyunv@node1 mysql]# mke2fs -t ext4 -L MYDATA -b 4096 -m 3 /dev/myvg/mydata
mke2fs 1.41.12 (17-May-2010)
Filesystem label=MYDATA
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
39321 blocks (3.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[iyunv@node1 mysql]# vim /etc/fstab
...
LABEL=MYDATA            /mydata                 ext4    defaults        0 0
[iyunv@node1 mysql]# mkdir -p /mydata/data
[iyunv@node1 mysql]# mount -a
[iyunv@node1 mysql]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mydata on /mydata type ext4 (rw)
[iyunv@node1 mysql]# chown -R mysql.mysql /mydata/data
[iyunv@node1 mysql]# ls -ld /mydata/data
drwxr-xr-x 2 mysql mysql 4096 Jan  3 11:36 /mydata/data



6、配置文件
     mv /etc/my.cnf /etc/my.cnf.bak(若存在其它版本的配置文件,则将其屏蔽)
     cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
1
2
3
4
[iyunv@node1 mysql]# ls support-files/    #support-files目录下存放着适用于各种内存大小的配置文件及服务脚本等
binary-configure  config.medium.ini  magic        my-innodb-heavy-4G.cnf  my-medium.cnf  mysqld_multi.server  mysql.server           SELinux
config.huge.ini   config.small.ini   my-huge.cnf  my-large.cnf            my-small.cnf   mysql-log-rotate     ndb-config-2-node.ini  solaris
[iyunv@node1 mysql]# cp support-files/my-large.cnf /etc/my.cnf



7、修改数据目录
     vim /etc/my.cnf
       其中datadir = /mydata/data(你所指定的数据目录)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[iyunv@node1 mysql]# vim /etc/my.cnf
...
# The MariaDB server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
datadir = /mydata/data     #添加这一项




8、初始化数据库      
     cd/usr/local/mysql
     scripts/mysql_install_db --user=mysql--datadir=/mydata/data/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[iyunv@node1 mysql]# ls scripts/
mysql_install_db
[iyunv@node1 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
Installing MariaDB/MySQL system tables in '/mydata/data' ...
OK
Filling help tables...
OK

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

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h node1 password 'new-password'

Alternatively you can run:
'./bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/mydata/data'

You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Support MariaDB development by buying support/new features from
SkySQL Ab. You can contact us about this at sales@skysql.com.
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

[iyunv@node1 mysql]# ls /mydata/data/
aria_log.00000001  aria_log_control  mysql  mysql-bin.000001  mysql-bin.000002  mysql-bin.index  performance_schema  test



9、服务脚本
     cp support-files/mysql.server /etc/rc.d/init.d/mysql (服务脚本)
     chkconfig --add mysqld
     chkconfig mysqld on
1
2
3
4
5
[iyunv@node1 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql
[iyunv@node1 mysql]# chkconfig --add mysql
[iyunv@node1 mysql]# chkconfig mysql on
[iyunv@node1 mysql]# chkconfig --list mysql
mysql             0:off   1:off   2:on    3:on    4:on    5:on    6:off



10、启动mysqld服务,并查看3306端口是否已处于监听状态
     service mysqld start
     ss -tnl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[iyunv@node1 mysql]# service mysqld start
Starting MySQL... SUCCESS!
[iyunv@node1 mysql]# ss -tnl
State       Recv-Q Send-Q                                                     Local Address:Port                                                       Peer Address:Port
LISTEN      0      128                                                                   :::58351                                                                :::*     
LISTEN      0      128                                                                   :::111                                                                  :::*     
LISTEN      0      128                                                                    *:111                                                                   *:*     
LISTEN      0      128                                                                   :::22                                                                   :::*     
LISTEN      0      128                                                                    *:22                                                                    *:*     
LISTEN      0      128                                                            127.0.0.1:631                                                                   *:*     
LISTEN      0      128                                                                  ::1:631                                                                  :::*     
LISTEN      0      128                                                                    *:50903                                                                 *:*     
LISTEN      0      10                                                             127.0.0.1:25                                                                    *:*     
LISTEN      0      128                                                            127.0.0.1:6011                                                                  *:*     
LISTEN      0      128                                                                  ::1:6011                                                                 :::*     
LISTEN      0      50                                                                     *:3306                                                                  *:*




11、设置PATH环境变量
     vim /etc/profile.d/mysql.sh
        export PATH=/usr/local/mysql/bin:$PATH
     source/etc/profile
1
2
3
4
[iyunv@node1 mysql]# vim /etc/profile.d/mysql.sh

export PATH=/usr/local/mysql/bin:$PATH
export PATH=/usr/local/mysql/bin:$PATH



12、导出帮助文件   
     vim /etc/man.config
     MANPATH /usr/local/mysql/man
1
2
3
[iyunv@node1 mysql]# vim /etc/man.config

MANPATH /usr/local/mysql/man



13、导出头文件
     ln -sv /usr/local/mysql/include/usr/include/mysql
1
[iyunv@node1 mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql



14、导出lib库
     vim /etc/ld.so.conf.d/mysql.conf
       /usr/local/mysql/lib
1
2
3
[iyunv@node1 mysql]# vim /etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib



运维网声明 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-161738-1-1.html 上篇帖子: Mariadb复制过滤与监控维护 下篇帖子: mysql 主从,双主简单配置 二进制
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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