生产环境 xfs filesystem 上安装Mariadb
2025-07-22 09:56 点击:1
规划/dev/sda 安装Linux操作系统,CentOS-6.6/dev/sdb Mysql数据文件和二进制文件单独放在一块硬盘,磁盘做成LVM逻辑卷方便以后扩充+--------------------------------------------------------------------------+| 1、查看磁盘 |+--------------------------------------------------------------------------+root@nginx1 ~ > fdisk -l /dev/sdb 数据盘,大小为300GDisk /dev/sdb: 300.0 GB, 300000000000 bytes255 heads, 63 sectors/track, 36472 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xe562e562 Device Boot Start End Blocks Id Systemroot@nginx1 ~ >+--------------------------------------------------------------------------+|2、进行分区,并配置LVM|+----------------------------------------------------------- ---------------+1) 进行分区root@nginx1 ~ > fdisk /dev/sdbWARNING: DOS-compatible mode is deprecated. It's strongly recommended toswitch off the mode (command 'c') and change display units tosectors (command 'u').Command (m for help): pDisk /dev/sdb: 300.0 GB, 300000000000 bytes255 heads, 63 sectors/track, 36472 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xe562e562 Device Boot Start End Blocks Id SystemCommand (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 1First cylinder (1-36472, default 1):Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-36472, default 36472):Using default value 36472Command (m for help): tSelected partition 1Hex code (type L to list codes): 8eChanged system type of partition 1 to 8e (Linux LVM)Command (m for help): p Disk /dev/sdb: 300.0 GB, 300000000000 bytes255 heads, 63 sectors/track, 36472 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xe562e562 Device Boot Start End Blocks Id System/dev/sdb1 1 36472 292961308+ 8e Linux LVMCommand (m for help):Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.root@nginx1 ~ > partprobe /dev/sdbroot@nginx1 ~ > cat /proc/partitionsmajor minor #blocks name 80 143374740 sda 81 204800 sda1 828388608 sda2 83 107315200 sda3 84 1 sda4 85 20971520 sda5 8 16 292968750 sdb 8 17 292961308 sdb1root@nginx1 ~ >2) 配置LVMroot@nginx1 ~ > pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully createdroot@nginx1 ~ > vgcreate mysql-vg /dev/sdb1 Volume group "mysql-vg" successfully createdroot@nginx1 ~ > lvcreate -L 250G -n mysql-lv mysql-vg Logical volume "mysql-lv" createdroot@nginx1 ~ > lvs LV VG Attr LSize Pool Origin Data% meta% Move Log Cpy%Sync Convert mysql-lv mysql-vg -wi-a----- 250.00groot@nginx1 ~ >+--------------------------------------------------------------------------+|3、进行格式化===> 格式化为xfs 文件系统|+--------------------------------------------------------------------------+1) 由于默认CentOS内核就支持xfs文件系统,只需要加载模块即可root@nginx1 ~ > lsmod |grep xfsroot@nginx1 ~ > modprobe xfsroot@nginx1 ~ > lsmod |grep xfsxfs 1124960 0exportfs4236 1 xfsroot@nginx1 ~ >2) 安装客户端工具包root@nginx1 ~ > yum -y install xfsprogs3) 进行格式化root@nginx1 ~ > mkfs.xfs /dev/mysql-vg/mysql-lvmeta-data=/dev/mysql-vg/mysql-lv isize=256agcount=4, agsize=16384000 blks= sectsz=512 attr=2, projid32bit=0data = bsize=4096 blocks=65536000, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0log =internal log bsize=4096 blocks=32000, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0root@nginx1 ~ >4) 修改磁盘调度策略为 deadlineroot@nginx1 ~ > echo 'deadline' > /sys/block/sdb/queue/schedulerroot@nginx1 ~ > cat /sys/block/sdb/queue/schedulernoop anticipatory [deadline] cfqroot@nginx1 ~ >5) 挂载,挂载时禁止atimeroot@nginx1 ~ > mkdir /JYroot@nginx1 ~ > mount -o noatime /dev/mysql-vg/mysql-lv /JY/root@nginx1 ~ > df -HPTFilesystem Type Size Used Avail Use% Mounted on/dev/sda5 ext422G 1.5G 19G 8% /tmpfs tmpfs 984M 0 984M 0% /dev/shm/dev/sda1 ext4 199M 36M 154M 19% /boot/dev/sda3 ext4 109G 2.3G 101G 3% /usr/dev/mapper/mysql--vg-mysql--lv xfs269G 34M 269G 1% /JYroot@nginx1 ~ > mount/dev/sda5 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)/dev/sda3 on /usr type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)/dev/mapper/mysql--vg-mysql--lv on /JY type xfs (rw,noatime)6) 写入fstabroot@nginx1 ~ > echo -e '/dev/mapper/mysql--vg-mysql--lv \t /JY \t xfs \t defaults,noatime \t 0 0' >> /etc/fstab+--------------------------------------------------------------------------+| 4、安装Mysql数据库 |+--------------------------------------------------------------------------+1) 创建Mysql用户root@nginx1 ~ > useradd -r mysql -s /sbin/nologin2) 准备数据目录和二进制存放目录root@nginx1 ~ > mkdir /JY/{data,binlog}root@nginx1 ~ > chown -R mysql:mysql /JY/root@nginx1 ~ > ll /JY/total 0drwxr-xr-x 2 mysql mysql 6 Oct 22 10:44 binlogdrwxr-xr-x 2 mysql mysql 6 Oct 22 10:44 dataroot@nginx1 ~ >3) 安装cmkaeroot@nginx1 ~ > tar xf cmake-3.0.1.tar.gzroot@nginx1 ~ > cd cmake-3.0.1root@nginx1 ~/cmake-3.0.1 > ./configureroot@nginx1 ~/cmake-3.0.1 > make && make install4) 安装数据库root@nginx1 ~ > tar xf mariadb-10.0.21.tar.gzroot@nginx1 ~ > cd mariadb-10.0.21root@nginx1 ~/mariadb-10.0.21 > cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/JY/data \-DSYSConFDIR=/etc \-DWITH_INNObase_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DWITH_SSL=system \-DWITH_ZLIB=system \-DWITH_LIBWRAP=0 \-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ciroot@nginx1 ~/mariadb-10.0.21 > make && make installroot@nginx1 ~/mariadb-10.0.21 > cd /usr/local/mysql/root@nginx1 /usr/local/mysql > chown -R mysql:mysql ./*root@nginx1 /usr/local/mysql >root@nginx1 /usr/local/mysql > scripts/mysql_install_db --user=mysql --datadir=/JY/data/root@nginx1 /usr/local/mysql > cp support-files/my-large.cnf /etc/my.cnfroot@nginx1 /usr/local/mysql > cp support-files/mysql.server /etc/init.d/mysqldroot@nginx1 /usr/local/mysql > chkconfig mysqld --addroot@nginx1 /usr/local/mysql > chkconfig mysqld onroot@nginx1 /usr/local/mysql > echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.shroot@nginx1 /usr/local/mysql > chmod +x /etc/profile.d/mysql.shroot@nginx1 /usr/local/mysql > source /etc/profile.d/mysql.shroot@nginx1 /usr/local/mysql > echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.confroot@nginx1 /usr/local/mysql > ldconfigroot@nginx1 /usr/local/mysql > ldconfig -v |grep mysql/usr/local/mysql/lib:libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0/usr/lib64/mysql:libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0libmysqlclient.so.16 -> libmysqlclient.so.16.0.0root@nginx1 /usr/local/mysql >root@nginx1 /usr/local/mysql > ln -s /usr/local/mysql/include /usr/include/mysqlroot@nginx1 ~ > /etc/init.d/mysqld startStarting MySQL.[ OK ]root@nginx1 ~ >5) 配置Mysql配置文件root@nginx1 ~ > vi /etc/my.cnfroot@nginx1 ~ > grep -v ^# /etc/my.cnf |grep -v ^$[client]port= 3306socket = /tmp/mysql.sock[mysqld]port= 3306socket = /tmp/mysql.sockskip-external-lockingkey_buffer_size = 256Mmax_allowed_packet = 1Mtable_open_cache = 256sort_buffer_size = 1Mread_buffer_size = 1Mread_rnd_buffer_size = 4Mmyisam_sort_buffer_size = 64Mthread_cache_size = 8query_cache_size= 16Mthread_concurrency = 4datadir = /JY/datainnodb_file_per_table = 1log_error = /JY/data/jy.errgeneral_log = ON general_log_file = /JY/data/general.logslow_query_log = ONslow_query_log_file = /JY/data/jy_slow.loginnodb_buffer_pool_size = 1024Minnodb_log_file_size = 512Minnodb_buffer_pool_instances=4innodb_read_io_threads = 8innodb_write_io_threads = 8max_allowed_packet = 128Minnodb_flush_method=O_DIRECTmax_connections = 1000max_user_connections = 1000skip_name_resolve = ONtransaction_isolation = READ-COMMITTEDlog-bin=/JY/binlog/jy-binbinlog_format=mixedserver-id = 1[mysql]no-auto-rehash[myisamchk]key_buffer_size = 128Msort_buffer_size = 128Mread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeout6) 重启Mysqlroot@nginx1 ~ > /etc/init.d/mysqld restartShutting down MySQL... [ OK ]Starting MySQL.............. [ OK ]root@nginx1 ~ >7) 设置Mysql密码MariaDB [mysql]> drop user ''@'localhost';Query OK, 0 rows affected (0.00 sec)MariaDB [mysql]> drop user ''@'nginx1.tianxiang';Query OK, 0 rows affected (0.00 sec)MariaDB [mysql]> select user,password,host from user;+------+----------+----------------------+| user | password | host |+------+----------+----------------------+| root | | localhost|| root | | nginx1.tianxiang || root | | 127.0.0.1|| root | | ::1 |+------+----------+----------------------+4 rows in set (0.00 sec)MariaDB [mysql]> grant all privileges on *.* to 'root'@'192.168.6.%' identified by 'fangyu421';Query OK, 0 rows affected (0.05 sec)MariaDB [mysql]> flush privileges;Query OK, 0 rows affected (0.00 sec)MariaDB [mysql]>