标签:baidu 索引 sso ocs 一个用户 store work 增加 byte
模拟生成环境的MySQL安装方法-通用二进制方式安装
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
1 [root@yinzhengjie ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.54-linux2.6-x86_64.tar.gz 2 [root@yinzhengjie ~]# tar xf mysql-5.5.54-linux2.6-x86_64.tar.gz -C /usr/local/ 3 [root@yinzhengjie ~]#
1 [root@yinzhengjie ~]# groupadd -r mysql 2 [root@yinzhengjie ~]# useradd -g mysql -r -s /sbin/nologin mysql 3 [root@yinzhengjie ~]# id mysql 4 uid=496(mysql) gid=493(mysql) groups=493(mysql) 5 [root@yinzhengjie ~]#
1 [root@yinzhengjie ~]# cd /usr/local/ 2 [root@yinzhengjie local]# ls 3 bin etc games include lib lib64 libexec mysql-5.5.54-linux2.6-x86_64 sbin share src 4 [root@yinzhengjie local]# ln -sv mysql-5.5.54-linux2.6-x86_64 mysql 5 `mysql‘ -> `mysql-5.5.54-linux2.6-x86_64‘ 6 [root@yinzhengjie local]# ls 7 bin etc games include lib lib64 libexec mysql mysql-5.5.54-linux2.6-x86_64 sbin share src 8 [root@yinzhengjie local]# cd mysql 9 [root@yinzhengjie mysql]# chown -R mysql.mysql ./* 10 [root@yinzhengjie mysql]# ll 11 total 72 12 drwxr-xr-x. 2 mysql mysql 4096 Nov 9 14:00 bin 13 -rw-r--r--. 1 mysql mysql 17987 Nov 28 2016 COPYING 14 drwxr-xr-x. 3 mysql mysql 4096 Nov 9 14:00 data 15 drwxr-xr-x. 2 mysql mysql 4096 Nov 9 14:00 docs 16 drwxr-xr-x. 3 mysql mysql 4096 Nov 9 14:00 include 17 -rw-r--r--. 1 mysql mysql 301 Nov 28 2016 INSTALL-BINARY 18 drwxr-xr-x. 3 mysql mysql 4096 Nov 9 14:00 lib 19 drwxr-xr-x. 4 mysql mysql 4096 Nov 9 14:00 man 20 drwxr-xr-x. 10 mysql mysql 4096 Nov 9 14:00 mysql-test 21 -rw-r--r--. 1 mysql mysql 2496 Nov 28 2016 README 22 drwxr-xr-x. 2 mysql mysql 4096 Nov 9 14:00 scripts 23 drwxr-xr-x. 27 mysql mysql 4096 Nov 9 14:00 share 24 drwxr-xr-x. 4 mysql mysql 4096 Nov 9 14:00 sql-bench 25 drwxr-xr-x. 2 mysql mysql 4096 Nov 9 14:00 support-files 26 [root@yinzhengjie mysql]#
1 [root@yinzhengjie ~]# cat /proc/partitions 2 major minor #blocks name 3 4 8 0 10485760 sda 5 8 1 307200 sda1 6 8 2 9128960 sda2 7 8 3 1048576 sda3 8 8 16 10485760 sdb 9 [root@yinzhengjie ~]# 10 [root@yinzhengjie ~]# 11 [root@yinzhengjie ~]# fdisk /dev/sdb 12 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel 13 Building a new DOS disklabel with disk identifier 0xfd32a610. 14 Changes will remain in memory only, until you decide to write them. 15 After that, of course, the previous content won‘t be recoverable. 16 17 Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 18 19 WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to 20 switch off the mode (command ‘c‘) and change display units to 21 sectors (command ‘u‘). 22 23 Command (m for help): p 24 25 Disk /dev/sdb: 10.7 GB, 10737418240 bytes 26 255 heads, 63 sectors/track, 1305 cylinders 27 Units = cylinders of 16065 * 512 = 8225280 bytes 28 Sector size (logical/physical): 512 bytes / 512 bytes 29 I/O size (minimum/optimal): 512 bytes / 512 bytes 30 Disk identifier: 0xfd32a610 31 32 Device Boot Start End Blocks Id System 33 34 Command (m for help): n 35 Command action 36 e extended 37 p primary partition (1-4) 38 p 39 Partition number (1-4): 1 40 First cylinder (1-1305, default 1): 41 Using default value 1 42 Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +9G 43 44 Command (m for help): w 45 The partition table has been altered! 46 47 Calling ioctl() to re-read partition table. 48 Syncing disks. 49 [root@yinzhengjie ~]# 50 [root@yinzhengjie ~]# partx -a /dev/sdb 51 BLKPG: Device or resource busy 52 error adding partition 1 53 [root@yinzhengjie ~]# 54 [root@yinzhengjie ~]# cat /proc/partitions 55 major minor #blocks name 56 57 8 0 10485760 sda 58 8 1 307200 sda1 59 8 2 9128960 sda2 60 8 3 1048576 sda3 61 8 16 10485760 sdb 62 8 17 9446188 sdb1 63 [root@yinzhengjie ~]# [root@yinzhengjie ~]# pvcreate /dev/sdb1 64 Physical volume "/dev/sdb1" successfully created 65 [root@yinzhengjie ~]# 66 [root@yinzhengjie ~]# vgcreate mydata /dev/sdb1 67 Volume group "mydata" successfully created 68 [root@yinzhengjie ~]# 69 [root@yinzhengjie ~]# 70 [root@yinzhengjie ~]# lvcreate -L 5G -n MySQLdata mydata 71 Logical volume "MySQLdata" created 72 [root@yinzhengjie ~]# 73 [root@yinzhengjie ~]# mke2fs -t ext4 /dev/mydata/MySQLdata 74 mke2fs 1.41.12 (17-May-2010) 75 Filesystem label= 76 OS type: Linux 77 Block size=4096 (log=2) 78 Fragment size=4096 (log=2) 79 Stride=0 blocks, Stripe width=0 blocks 80 327680 inodes, 1310720 blocks 81 65536 blocks (5.00%) reserved for the super user 82 First data block=0 83 Maximum filesystem blocks=1342177280 84 40 block groups 85 32768 blocks per group, 32768 fragments per group 86 8192 inodes per group 87 Superblock backups stored on blocks: 88 32768, 98304, 163840, 229376, 294912, 819200, 884736 89 90 Writing inode tables: done 91 Creating journal (32768 blocks): done 92 Writing superblocks and filesystem accounting information: done 93 94 This filesystem will be automatically checked every 28 mounts or 95 180 days, whichever comes first. Use tune2fs -c or -i to override. 96 [root@yinzhengjie ~]#
1 [root@yinzhengjie ~]# mkdir /data 2 [root@yinzhengjie ~]# echo "/dev/mydata/MySQLdata /data ext4 defaults,noatime 0 0" >> /etc/fstab #定义开机自动挂载 3 [root@yinzhengjie ~]# 4 [root@yinzhengjie ~]# more /etc/fstab 5 6 # 7 # /etc/fstab 8 # Created by anaconda on Thu Nov 9 12:26:01 2017 9 # 10 # Accessible filesystems, by reference, are maintained under ‘/dev/disk‘ 11 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info 12 # 13 UUID=bcf1bee0-1904-40fb-85a5-5bb99223105b / ext4 defaults 1 1 14 UUID=c317aa92-86be-4214-acee-0862611e0241 /boot ext4 defaults 1 2 15 UUID=e41daebb-aa45-4751-916f-58cead33fcdd swap swap defaults 0 0 16 tmpfs /dev/shm tmpfs defaults 0 0 17 devpts /dev/pts devpts gid=5,mode=620 0 0 18 sysfs /sys sysfs defaults 0 0 19 proc /proc proc defaults 0 0 20 /dev/mydata/MySQLdata /data ext4 defaults,noatime 0 0 21 [root@yinzhengjie ~]# 22 [root@yinzhengjie ~]# mount -a #重读挂载信息 23 [root@yinzhengjie ~]# 24 [root@yinzhengjie ~]# mount 25 /dev/sda2 on / type ext4 (rw) 26 proc on /proc type proc (rw) 27 sysfs on /sys type sysfs (rw) 28 devpts on /dev/pts type devpts (rw,gid=5,mode=620) 29 tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") 30 /dev/sda1 on /boot type ext4 (rw) 31 none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) 32 vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other) 33 /dev/mapper/mydata-MySQLdata on /data type ext4 (rw,noatime) 34 [root@yinzhengjie ~]#
5.初始化MySQL数据库
1 [root@yinzhengjie ~]# cd /usr/local/mysql 2 [root@yinzhengjie mysql]# 3 [root@yinzhengjie mysql]# scripts/mysql_install_db --datadir=/data/mydata --user=mysql #指定数据库目录 以及启动服务用户名称 4 WARNING: The host ‘yinzhengjie‘ could not be looked up with resolveip. 5 This probably means that your libc libraries are not 100 % compatible 6 with this binary MySQL version. The MySQL daemon, mysqld, should work 7 normally with the exception that host name resolving will not work. 8 This means that you should use IP addresses instead of hostnames 9 when specifying MySQL privileges ! 10 Installing MySQL system tables... 11 171109 14:50:15 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 12 171109 14:50:15 [Note] ./bin/mysqld (mysqld 5.5.54) starting as process 2484 ... 13 OK 14 Filling help tables... 15 171109 14:50:17 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 16 171109 14:50:17 [Note] ./bin/mysqld (mysqld 5.5.54) starting as process 2492 ... 17 OK 18 19 To start mysqld at boot time you have to copy 20 support-files/mysql.server to the right place for your system 21 22 PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! 23 To do so, start the server, then issue the following commands: 24 25 ./bin/mysqladmin -u root password ‘new-password‘ 26 ./bin/mysqladmin -u root -h yinzhengjie password ‘new-password‘ 27 28 Alternatively you can run: 29 ./bin/mysql_secure_installation 30 31 which will also give you the option of removing the test 32 databases and anonymous user created by default. This is 33 strongly recommended for production servers. 34 35 See the manual for more instructions. 36 37 You can start the MySQL daemon with: 38 cd . ; ./bin/mysqld_safe & 39 40 You can test the MySQL daemon with mysql-test-run.pl 41 cd ./mysql-test ; perl mysql-test-run.pl 42 43 Please report any problems at http://bugs.mysql.com/ 44 45 [root@yinzhengjie mysql]# 46 [root@yinzhengjie mysql]# ls /data/mydata/ #查看是否有文件生成,如果你也有者三个目录那么久说明你也安装成功啦! 47 mysql performance_schema test 48 [root@yinzhengjie mysql]#
1 [root@yinzhengjie mysql]# chown -R root ./* 2 [root@yinzhengjie mysql]# ll 3 total 72 4 drwxr-xr-x. 2 root mysql 4096 Nov 9 14:00 bin 5 -rw-r--r--. 1 root mysql 17987 Nov 28 2016 COPYING 6 drwxr-xr-x. 3 root mysql 4096 Nov 9 14:00 data 7 drwxr-xr-x. 2 root mysql 4096 Nov 9 14:00 docs 8 drwxr-xr-x. 3 root mysql 4096 Nov 9 14:00 include 9 -rw-r--r--. 1 root mysql 301 Nov 28 2016 INSTALL-BINARY 10 drwxr-xr-x. 3 root mysql 4096 Nov 9 14:00 lib 11 drwxr-xr-x. 4 root mysql 4096 Nov 9 14:00 man 12 drwxr-xr-x. 10 root mysql 4096 Nov 9 14:00 mysql-test 13 -rw-r--r--. 1 root mysql 2496 Nov 28 2016 README 14 drwxr-xr-x. 2 root mysql 4096 Nov 9 14:00 scripts 15 drwxr-xr-x. 27 root mysql 4096 Nov 9 14:00 share 16 drwxr-xr-x. 4 root mysql 4096 Nov 9 14:00 sql-bench 17 drwxr-xr-x. 2 root mysql 4096 Nov 9 14:00 support-files 18 [root@yinzhengjie mysql]#
1 [root@yinzhengjie mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld 2 [root@yinzhengjie mysql]# chkconfig --add mysqld 3 [root@yinzhengjie mysql]# chkconfig mysqld on 4 [root@yinzhengjie mysql]# chkconfig mysqld --list 5 mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off 6 [root@yinzhengjie mysql]#
1 [root@yinzhengjie mysql]# cp support-files/my-large.cnf /etc/my.cnf 2 cp: overwrite `/etc/my.cnf‘? y 3 [root@yinzhengjie mysql]# 4 [root@yinzhengjie mysql]# cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l #查看物理CPU个数 5 1 6 [root@yinzhengjie mysql]# cat /proc/cpuinfo| grep "cpu cores"| uniq # 查看每个物理CPU中core的个数(即核数) 7 cpu cores : 1 8 [root@yinzhengjie mysql]# cat /proc/cpuinfo| grep "processor"| wc -l # 查看逻辑CPU的个数 9 1 10 [root@yinzhengjie mysql]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c #查看CPU信息(型号) 11 1 Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz 12 [root@yinzhengjie mysql]# 13 [root@yinzhengjie mysql]# grep thread_concurrency /etc/my.cnf | grep -v ^# 14 thread_concurrency = 2 ----------->这个参数我们建议设置成上面查看CPU核心数的2倍。由于我们看到的核心数是1,因此这个值设置为2即可,写大了也没有意义。 15 [root@yinzhengjie mysql]# 16 [root@yinzhengjie mysql]# grep datadir /etc/my.cnf 17 datadir = /data/mydata/ ----------->这个参数就是我们的MySQL数据库目录。 18 [root@yinzhengjie mysql]#
9.启动MySQL
1 [root@yinzhengjie mysql]# ll /data/mydata/ #在没有启动之前,只有以下3个目录 2 total 12 3 drwx------. 2 mysql mysql 4096 Nov 9 14:50 mysql 4 drwx------. 2 mysql mysql 4096 Nov 9 14:50 performance_schema 5 drwx------. 2 mysql mysql 4096 Nov 9 14:50 test 6 [root@yinzhengjie mysql]# 7 [root@yinzhengjie mysql]# service mysqld start #启动数据库,如果出现了以下的错误,一开始我也蒙圈,然后我看了一下启动脚本,发现脚本写的有问题,不知道是搜狐改过官方的二进制包还是官方自身的脚本就有bug。我们不去纠结这个问题了 8 Starting MySQL.171109 15:25:37 mysqld_safe error: log-error set to ‘/data/mydata//yinzhengjie.err‘, however file don‘t exists. Create writable for user ‘mysql‘. 9 ERROR! The server quit without updating PID file (/data/mydata//yinzhengjie.pid). 10 [root@yinzhengjie mysql]# 11 [root@yinzhengjie mysql]# touch /data/mydata//yinzhengjie.err #看了上面的问题时缺少pid文件而已,于是我们就手动创建一个它需要那个文件。然后再次启动就会启动成功。 12 [root@yinzhengjie mysql]# service mysqld start 13 Starting MySQL.... SUCCESS! 14 [root@yinzhengjie mysql]# 15 [root@yinzhengjie mysql]# ll /data/mydata/ #启动成功后,你会发现目录的下多了几个文件。不仅仅是之前的3个目录啦。 16 total 28696 17 -rw-rw----. 1 mysql mysql 18874368 Nov 9 15:26 ibdata1 #innodb存储的数据 18 -rw-rw----. 1 mysql mysql 5242880 Nov 9 15:26 ib_logfile0 #该文件和下面的ib_logfile1都是事物日志 19 -rw-rw----. 1 mysql mysql 5242880 Nov 9 15:26 ib_logfile1 20 drwx------. 2 mysql mysql 4096 Nov 9 14:50 mysql 21 -rw-rw----. 1 mysql mysql 107 Nov 9 15:26 mysql-bin.000001 #这是二进制日志滚动文件,也就是说每次重启服务,都会自动生成一个新的文件。 22 -rw-rw----. 1 mysql mysql 19 Nov 9 15:26 mysql-bin.index #二进制的索引文件。 23 drwx------. 2 mysql mysql 4096 Nov 9 14:50 performance_schema 24 drwx------. 2 mysql mysql 4096 Nov 9 14:50 test 25 -rw-r--r--. 1 root root 0 Nov 9 15:25 yinzhengjie.err #这是错误日志,注意日志的名称是以主机名定义的哟,pid文件也是。 26 -rw-rw----. 1 mysql mysql 5 Nov 9 15:26 yinzhengjie.pid #这个是pid文件 27 [root@yinzhengjie mysql]#
标签:baidu 索引 sso ocs 一个用户 store work 增加 byte
原文地址:http://www.cnblogs.com/yinzhengjie/p/7811884.html