当前位置: 首页 > 工具软件 > bsd-cloudinit > 使用案例 >

【Linux】Alibaba Cloud Linux 3 中第二硬盘、MySQL8.*、MySQL7.*、Redis、Nginx、Java 系统安装

单于浩邈
2023-12-01

一、操作系统说明

兼容CentOS/RHEL生态,CentOS/RHEL中的大多数软件无需或仅需少量改造即可在Alibaba Cloud Linux中运行。

- Alibaba Cloud Linux 3基于Anolis OS 8打造,兼容CentOS 8、RHEL 8生态。

- Alibaba Cloud Linux 2基于Aonlis OS 7打造,兼容CentOS 7、RHEL 7生态

安装系统为:Alibaba Cloud Linux 3

二、安装第二硬盘

1. 查看机器情况

[root@Q!XtcaykhuMd62GD ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    253:0    0   40G  0 disk 
└─vda1 253:1    0   40G  0 part /
vdb    253:16   0  500G  0 disk 

2.硬盘分区

使用fdisk分区

[root@Q!XtcaykhuMd62GD ~]# fdisk  vdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

fdisk: cannot open vdb: No such file or directory
[root@Q!XtcaykhuMd62GD ~]# fdisk  /dev/vdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x591cb8fe.

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-1048575999, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-1048575999, default 1048575999): 

Created a new partition 1 of type 'Linux' and of size 500 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

3. 格式化已经分好区的硬盘

[root@Q!XtcaykhuMd62GD ~]# fdisk  -l
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6f37da4d

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83886046 83883999  40G 83 Linux


Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x591cb8fe

Device     Boot Start        End    Sectors  Size Id Type
/dev/vdb1        2048 1048575999 1048573952  500G 83 Linux
[root@Q!XtcaykhuMd62GD ~]# mkfs -t ext4 /dev/vdb1
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 131071744 4k blocks and 32768000 inodes
Filesystem UUID: 7cb056cd-3501-4bdb-89be-d41f8d526d2f
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done     

4. 挂载到系统中

[root@Q!XtcaykhuMd62GD ~]# mkdir /data
[root@Q!XtcaykhuMd62GD ~]# ls
[root@Q!XtcaykhuMd62GD ~]# vim /etc/fstab
[root@Q!XtcaykhuMd62GD ~]# 

/dev/vdb1                                 /data                   ext4    defaults        0 0

安装Redis

[root@Q!XtcaykhuMd62GD ~]# yum install -y redis-6.0.5
Last metadata expiration check: 2:55:29 ago on Tue 20 Sep 2022 07:28:01 PM CST.
Dependencies resolved.
===============================================================================================================================================================================
 Package                                  Architecture                        Version                                       Repository                                    Size
===============================================================================================================================================================================
Installing:
 redis                                    x86_64                              6.0.5-1.11.al8                                alinux3-updates                              1.2 M
Installing dependencies:
 daxctl-libs                              x86_64                              71.1-3.al8                                    alinux3-updates                               42 k

Transaction Summary
===============================================================================================================================================================================
Install  2 Packages

Total download size: 1.3 M
Installed size: 4.4 M
Downloading Packages:
(1/2): daxctl-libs-71.1-3.al8.x86_64.rpm                                                                                                       433 kB/s |  42 kB     00:00    
(2/2): redis-6.0.5-1.11.al8.x86_64.rpm                                                                                                         2.7 MB/s | 1.2 MB     00:00    
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                          2.8 MB/s | 1.3 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                       1/1 
  Installing       : daxctl-libs-71.1-3.al8.x86_64                                                                                                                         1/2 
  Running scriptlet: daxctl-libs-71.1-3.al8.x86_64                                                                                                                         1/2 
  Running scriptlet: redis-6.0.5-1.11.al8.x86_64                                                                                                                           2/2 
  Installing       : redis-6.0.5-1.11.al8.x86_64                                                                                                                           2/2 
  Running scriptlet: redis-6.0.5-1.11.al8.x86_64                                                                                                                           2/2 
  Verifying        : daxctl-libs-71.1-3.al8.x86_64                                                                                                                         1/2 
  Verifying        : redis-6.0.5-1.11.al8.x86_64                                                                                                                           2/2 

Installed:
  daxctl-libs-71.1-3.al8.x86_64                                                           redis-6.0.5-1.11.al8.x86_64                                                          

Complete!
[root@Q!XtcaykhuMd62GD ~]# systemctl start  redis
[root@Q!XtcaykhuMd62GD ~]# ps -ef |grep  redis
redis      16519       1  0 22:28 ?        00:00:00 /usr/bin/redis-server 127.0.0.1:6379
root       16524    5124  0 22:28 pts/0    00:00:00 grep --color=auto redis

安装 Java

[root@Q!XtcaykhuMd62GD ~]# yum list installed |grep java
[root@Q!XtcaykhuMd62GD ~]# yum -y list java*

[root@Q!XtcaykhuMd62GD ~]# yum  install  -y java-1.8.0-alibaba-dragonwell.x86_64  

安装 MySQL 8.0

https://blog.csdn.net/zhouweijia777/article/details/126526034

1. 查找可MySQL版本

yum -y list mysql*
Last metadata expiration check: 0:51:25 ago on Sun 02 Oct 2022 03:26:40 PM CST.
Installed Packages
mysql-community-client.x86_64                                          5.7.39-1.el7                                        @mysql57-community        
mysql-community-common.x86_64                                          5.7.39-1.el7                                        @mysql57-community        
mysql-community-libs.x86_64                                            5.7.39-1.el7                                        @mysql57-community        
mysql-community-server.x86_64                                          5.7.39-1.el7                                        @mysql57-community        
mysql57-community-release.noarch                                       el7-8                                               @System                   
Available Packages
MySQL-zrm.noarch                                                       3.0-23.el8                                          epel                      
mysql.x86_64                                                           8.0.26-1.1.al8                                      alinux3-updates           
mysql-common.x86_64                                                    8.0.26-1.1.al8                                      alinux3-updates           
mysql-community-client.i686                                            5.7.39-1.el7                                        mysql57-community         
mysql-community-common.i686                                            5.7.39-1.el7                                        mysql57-community         
mysql-community-devel.i686                                             5.7.39-1.el7                                        mysql57-community         
mysql-community-devel.x86_64                                           5.7.39-1.el7                                        mysql57-community         
mysql-community-embedded.i686                                          5.7.39-1.el7                                        mysql57-community         
mysql-community-embedded.x86_64                                        5.7.39-1.el7                                        mysql57-community         
mysql-community-embedded-compat.i686                                   5.7.39-1.el7                                        mysql57-community         
mysql-community-embedded-compat.x86_64                                 5.7.39-1.el7                                        mysql57-community         
mysql-community-embedded-devel.i686                                    5.7.39-1.el7                                        mysql57-community         
mysql-community-embedded-devel.x86_64                                  5.7.39-1.el7                                        mysql57-community         
mysql-community-libs.i686                                              5.7.39-1.el7                                        mysql57-community         
mysql-community-libs-compat.i686                                       5.7.39-1.el7                                        mysql57-community         
mysql-community-libs-compat.x86_64                                     5.7.39-1.el7                                        mysql57-community         
mysql-community-release.noarch                                         el7-5                                               mysql-connectorQ!XtcaykhuMd62GD
mysql-community-release.noarch                                         el7-5                                               mysql-toolQ!XtcaykhuMd62GD     
mysql-community-test.x86_64                                            5.7.39-1.el7                                        mysql57-community         
mysql-connector-c++.x86_64                                             8.0.30-1.el7                                        mysql-connectorQ!XtcaykhuMd62GD
mysql-connector-c++-devel.x86_64                                       8.0.30-1.el7                                        mysql-connectorQ!XtcaykhuMd62GD
mysql-connector-c++-jdbc.x86_64                                        8.0.30-1.el7                                        mysql-connectorQ!XtcaykhuMd62GD
mysql-connector-java.noarch                                            1:8.0.30-1.el7                                      mysql-connectorQ!XtcaykhuMd62GD
mysql-connector-odbc.x86_64                                            8.0.30-1.el7                                        mysql-connectorQ!XtcaykhuMd62GD
mysql-connector-odbc-setup.x86_64                                      8.0.30-1.el7                                        mysql-connectorQ!XtcaykhuMd62GD
mysql-connector-python.noarch                                          2.0.4-1.el7                                         mysql-connectorQ!XtcaykhuMd62GD
mysql-connector-python.x86_64                                          8.0.23-1.el7                                        mysql-connectorQ!XtcaykhuMd62GD
mysql-connector-python-cext.x86_64                                     8.0.21-1.el7                                        mysql-connectorQ!XtcaykhuMd62GD
mysql-connector-python3.x86_64                                         8.0.30-1.el7                                        mysql-connectorQ!XtcaykhuMd62GD
mysql-connector-python3-cext.x86_64                                    8.0.21-1.el7                                        mysql-connectorQ!XtcaykhuMd62GD
mysql-devel.x86_64                                                     8.0.26-1.1.al8                                      alinux3-updates           
mysql-errmsg.x86_64                                                    8.0.26-1.1.al8                                      alinux3-updates           
mysql-libs.x86_64                                                      8.0.26-1.1.al8                                      alinux3-updates           
mysql-mmm.noarch                                                       2.2.1-25.el8                                        epel                      
mysql-mmm-agent.noarch                                                 2.2.1-25.el8                                        epel                      
mysql-mmm-monitor.noarch                                               2.2.1-25.el8                                        epel                      
mysql-mmm-tools.noarch                                                 2.2.1-25.el8                                        epel                      
mysql-ref-manual-5.5-en-html-chapter.noarch                            1-20170320                                          mysql57-community         
mysql-ref-manual-5.5-en-pdf.noarch                                     1-20170320                                          mysql57-community         
mysql-ref-manual-5.7-en-html-chapter.noarch                            1-20220613                                          mysql57-community         
mysql-ref-manual-5.7-en-pdf.noarch                                     1-20220613                                          mysql57-community         
mysql-router.x86_64                                                    8.0.12-1.el7                                        mysql-toolQ!XtcaykhuMd62GD     
mysql-router-community.x86_64                                          8.0.30-1.el7                                        mysql-toolQ!XtcaykhuMd62GD     
mysql-selinux.noarch                                                   1.0.5-1.al8                                         alinux3-updates           
mysql-server.x86_64                                                    8.0.26-1.1.al8                                      alinux3-updates           
mysql-shell.x86_64                                                     8.0.30-1.el7                                        mysql-toolQ!XtcaykhuMd62GD     
mysql-test.x86_64                                                      8.0.26-1.1.al8                                      alinux3-updates           
mysql-utilities.noarch                                                 1.6.5-1.el7                                         mysql-toolQ!XtcaykhuMd62GD     
mysql-utilities-extra.noarch                                           1.5.6-1.el7                                         mysql-toolQ!XtcaykhuMd62GD     
mysql-workbench-community.x86_64                                       8.0.22-1.el7                                        mysql-toolQ!XtcaykhuMd62GD     
mysqltuner.noarch                                                      1.8.3-1.git.1333ea9.el8                             epel                      
[root@Q!XtcaykhuMd62GD giteeMicroCommunityWeb]# 

2. 安装MySQL

yum  install -y  mysql-server.x86_64

Last metadata expiration check: 1:34:25 ago on Wed 21 Sep 2022 06:42:39 AM CST.
Dependencies resolved.
=========================================================================================
 Package                         Arch      Version              Repository          Size
=========================================================================================
Installing:
 mysql-server                    x86_64    8.0.26-1.1.al8       alinux3-updates     28 M
Installing dependencies:
 checkpolicy                     x86_64    2.9-1.2.al8          alinux3-os         348 k
 libaio                          x86_64    0.3.112-1.2.al8      alinux3-os          33 k
 mecab                           x86_64    0.996-1.2.al8.9      alinux3-os         387 k
 mysql                           x86_64    8.0.26-1.1.al8       alinux3-updates     13 M
 mysql-errmsg                    x86_64    8.0.26-1.1.al8       alinux3-updates    598 k
 policycoreutils-python-utils    noarch    2.9-14.1.al8         alinux3-updates    252 k
 protobuf-lite                   x86_64    3.5.0-13.1.al8       alinux3-os         154 k
 python3-audit                   x86_64    3.0.7-2.al8.2        alinux3-updates     86 k
 python3-libsemanage             x86_64    2.9-6.1.al8          alinux3-updates    127 k
 python3-policycoreutils         noarch    2.9-14.1.al8         alinux3-updates    2.2 M
 python3-setools                 x86_64    4.3.0-3.al8          alinux3-updates    651 k

Transaction Summary
=========================================================================================
Install  12 Packages

Total download size: 46 M
Installed size: 209 M
Downloading Packages:
(1/12): libaio-0.3.112-1.2.al8.x86_64.rpm                346 kB/s |  33 kB     00:00    
(2/12): checkpolicy-2.9-1.2.al8.x86_64.rpm               2.0 MB/s | 348 kB     00:00    
(3/12): protobuf-lite-3.5.0-13.1.al8.x86_64.rpm          1.4 MB/s | 154 kB     00:00    
(4/12): mysql-errmsg-8.0.26-1.1.al8.x86_64.rpm           5.5 MB/s | 598 kB     00:00    
(5/12): mecab-0.996-1.2.al8.9.x86_64.rpm                 889 kB/s | 387 kB     00:00    
(6/12): mysql-8.0.26-1.1.al8.x86_64.rpm                   36 MB/s |  13 MB     00:00    
(7/12): python3-audit-3.0.7-2.al8.2.x86_64.rpm           1.2 MB/s |  86 kB     00:00    
(8/12): policycoreutils-python-utils-2.9-14.1.al8.noarch 1.3 MB/s | 252 kB     00:00    
(9/12): python3-libsemanage-2.9-6.1.al8.x86_64.rpm       2.3 MB/s | 127 kB     00:00    
(10/12): python3-setools-4.3.0-3.al8.x86_64.rpm           14 MB/s | 651 kB     00:00    
(11/12): mysql-server-8.0.26-1.1.al8.x86_64.rpm           43 MB/s |  28 MB     00:00    
(12/12): python3-policycoreutils-2.9-14.1.al8.noarch.rpm 3.3 MB/s | 2.2 MB     00:00    
-----------------------------------------------------------------------------------------
Total                                                     36 MB/s |  46 MB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                 1/1 
  Installing       : python3-setools-4.3.0-3.al8.x86_64                             1/12 
  Installing       : python3-libsemanage-2.9-6.1.al8.x86_64                         2/12 
  Installing       : python3-audit-3.0.7-2.al8.2.x86_64                             3/12 
  Installing       : mysql-errmsg-8.0.26-1.1.al8.x86_64                             4/12 
  Installing       : mysql-8.0.26-1.1.al8.x86_64                                    5/12 
  Installing       : protobuf-lite-3.5.0-13.1.al8.x86_64                            6/12 
  Installing       : mecab-0.996-1.2.al8.9.x86_64                                   7/12 
  Running scriptlet: mecab-0.996-1.2.al8.9.x86_64                                   7/12 
  Installing       : libaio-0.3.112-1.2.al8.x86_64                                  8/12 
  Installing       : checkpolicy-2.9-1.2.al8.x86_64                                 9/12 
  Installing       : python3-policycoreutils-2.9-14.1.al8.noarch                   10/12 
  Installing       : policycoreutils-python-utils-2.9-14.1.al8.noarch              11/12 
  Running scriptlet: mysql-server-8.0.26-1.1.al8.x86_64                            12/12 
  Installing       : mysql-server-8.0.26-1.1.al8.x86_64                            12/12 
  Running scriptlet: mysql-server-8.0.26-1.1.al8.x86_64                            12/12 


ValueError: File context for /var/log/mysql(/.*)? already defined

  Running scriptlet: mysql-server-8.0.26-1.1.al8.x86_64                                                       12/12 
  Verifying        : checkpolicy-2.9-1.2.al8.x86_64                                                            1/12 
  Verifying        : libaio-0.3.112-1.2.al8.x86_64                                                             2/12 
  Verifying        : mecab-0.996-1.2.al8.9.x86_64                                                              3/12 
  Verifying        : protobuf-lite-3.5.0-13.1.al8.x86_64                                                       4/12 
  Verifying        : mysql-8.0.26-1.1.al8.x86_64                                                               5/12 
  Verifying        : mysql-errmsg-8.0.26-1.1.al8.x86_64                                                        6/12 
  Verifying        : mysql-server-8.0.26-1.1.al8.x86_64                                                        7/12 
  Verifying        : policycoreutils-python-utils-2.9-14.1.al8.noarch                                          8/12 
  Verifying        : python3-audit-3.0.7-2.al8.2.x86_64                                                        9/12 
  Verifying        : python3-libsemanage-2.9-6.1.al8.x86_64                                                   10/12 
  Verifying        : python3-policycoreutils-2.9-14.1.al8.noarch                                              11/12 
  Verifying        : python3-setools-4.3.0-3.al8.x86_64                                                       12/12 

Installed:
  checkpolicy-2.9-1.2.al8.x86_64                                libaio-0.3.112-1.2.al8.x86_64                      
  mecab-0.996-1.2.al8.9.x86_64                                  mysql-8.0.26-1.1.al8.x86_64                        
  mysql-errmsg-8.0.26-1.1.al8.x86_64                            mysql-server-8.0.26-1.1.al8.x86_64                 
  policycoreutils-python-utils-2.9-14.1.al8.noarch              protobuf-lite-3.5.0-13.1.al8.x86_64                
  python3-audit-3.0.7-2.al8.2.x86_64                            python3-libsemanage-2.9-6.1.al8.x86_64             
  python3-policycoreutils-2.9-14.1.al8.noarch                   python3-setools-4.3.0-3.al8.x86_64                 

Complete!


3. 启动MySQL

systemctl enable --now mysqld

#设置自动启动MySQL
systemctl enable mysqld

#启动MySQL 
systemctl start  mysqld

安装MySql 5.7

1. 官网:http://dev.mysql.com/downloads/repo/yum/


[root@Q!XtcaykhuMd62GD data]# rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
warning: /var/tmp/rpm-tmp.jTMWaN: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-8  ################################# [100%]

2. 查看5.7版本是否已经启用

[root@Q!XtcaykhuMd62GD data]# yum repolist all | grep mysql
mysql-connectorQ!XtcaykhuMd62GD        MySQL Connectors Community            enabled
mysql-connectorQ!XtcaykhuMd62GD-source MySQL Connectors Community - Source   disabled
mysql-toolQ!XtcaykhuMd62GD             MySQL Tools Community                 enabled
mysql-toolQ!XtcaykhuMd62GD-source      MySQL Tools Community - Source        disabled
mysql-tools-preview               MySQL Tools Preview                   disabled
mysql-tools-preview-source        MySQL Tools Preview - Source          disabled
mysql55-community                 MySQL 5.5 Community Server            disabled
mysql55-community-source          MySQL 5.5 Community Server - Source   disabled
mysql56-community                 MySQL 5.6 Community Server            disabled
mysql56-community-source          MySQL 5.6 Community Server - Source   disabled
mysql57-community                 MySQL 5.7 Community Server            enabled
mysql57-community-source          MySQL 5.7 Community Server - Source   disabled

3. 安装MySQL

yum -y install mysql-community-server --nogpgcheck


4. 修改配置文件 /etc/my.cnf

根据配置文件修改相应的文件和目录

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0

#log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid

# MySql5.7配置文件my.ini设置
[client]
port = 3306
socket = /data/mysql/mysql.sock
 
[mysqld]
###############################基础设置#####################################
#Mysql服务的唯一编号 每个mysql服务Id需唯一
server-id = 1
 
#服务端口号 默认3306
port = 3306
 
#mysql安装根目录
#basedir = /opt/mysql
 
#mysql数据文件所在位置
datadir = /data/mysql
 
#临时目录 比如load data infile会用到
tmpdir  = /tmp
 
#设置socke文件所在目录
socket  = /tmp/mysql.sock
 
#主要用于MyISAM存储引擎,如果多台服务器连接一个数据库则建议注释下面内容
skip-external-locking
 
#只能用IP地址检查客户端的登录,不用主机名
skip_name_resolve = 1
#数据库默认字符集,主流字符集支持一些特殊表情符号(特殊表情符占用4个字节)
character-set-server = utf8mb4
 
#数据库字符集对应一些排序等规则,注意要和character-set-server对应
collation-server = utf8mb4_general_ci
 
#设置client连接mysql时的字符集,防止乱码
init_connect='SET NAMES utf8mb4'
 
#是否对sql语句大小写敏感,1表示不敏感
lower_case_table_names = 1
 
#最大连接数
max_connections = 400
#最大错误连接数
max_connect_errors = 1000
 
#TIMESTAMP如果没有显示声明NOT NULL,允许NULL值
explicit_defaults_for_timestamp = true
 
#SQL数据包发送的大小,如果有BLOB对象建议修改成1G
max_allowed_packet = 128M
 
#MySQL连接闲置超过一定时间后(单位:秒)将会被强行关闭
#MySQL默认的wait_timeout  值为8个小时, interactive_timeout参数需要同时配置才能生效
interactive_timeout = 1800
wait_timeout = 1800
 
#内部内存临时表的最大值 ,设置成128M。
#比如大数据量的group by ,order by时可能用到临时表,
#超过了这个值将写入磁盘,系统IO压力增大
tmp_table_size = 134217728
max_heap_table_size = 134217728


 
##----------------------------用户进程分配到的内存设置BEGIN-----------------------------##
##每个session将会分配参数设置的内存大小
#用于表的顺序扫描,读出的数据暂存于read_buffer_size中,当buff满时或读完,将数据返回上层调用者
#一般在128kb ~ 256kb,用于MyISAM
#read_buffer_size = 131072
#用于表的随机读取,当按照一个非索引字段排序读取时会用到,
#一般在128kb ~ 256kb,用于MyISAM
#read_rnd_buffer_size = 262144
#order by或group by时用到
#建议先调整为2M,后期观察调整
sort_buffer_size = 2097152
#一般数据库中没什么大的事务,设成1~2M,默认32kb
binlog_cache_size = 524288
 
############################日  志 设置##########################################
#数据库错误日志文件
log_error = /data/mysql/error.log
 
#慢查询sql日志设置
slow_query_log = 1
slow_query_log_file = /data/mysql/slow.log
#检查未使用到索引的sql
log_queries_not_using_indexes = 1
#针对log_queries_not_using_indexes开启后,记录慢sql的频次、每分钟记录的条数
log_throttle_queries_not_using_indexes = 5
#作为从库时生效,从库复制中如何有慢sql也将被记录
log_slow_slave_statements = 1
#慢查询执行的秒数,必须达到此值可被记录
long_query_time = 2
#检索的行数必须达到此值才可被记为慢查询
min_examined_row_limit = 100
 
#mysql binlog日志文件保存的过期时间,过期后自动删除
expire_logs_days = 5
 
############################主从复制 设置########################################
#开启mysql binlog功能
log-bin=mysql-bin
#binlog记录内容的方式,记录被操作的每一行
binlog_format = ROW

#作为从库时生效,想进行级联复制,则需要此参数
log_slave_updates
 
#作为从库时生效,中继日志relay-log可以自我修复
relay_log_recovery = 1
 
#作为从库时生效,主从复制时忽略的错误
slave_skip_errors = ddl_exist_errors
 
##---redo log和binlog的关系设置BEGIN---##
#(步骤1) prepare dml相关的SQL操作,然后将redo log buff中的缓存持久化到磁盘
#(步骤2)如果前面prepare成功,那么再继续将事务日志持久化到binlog
#(步骤3)如果前面成功,那么在redo log里面写上一个commit记录
#当innodb_flush_log_at_trx_commit和sync_binlog都为1时是最安全的,
#在mysqld服务崩溃或者服务器主机crash的情况下,binary log只有可能丢失最多一个语句或者一个事务。
#但是都设置为1时会导致频繁的io操作,因此该模式也是最慢的一种方式。
#当innodb_flush_log_at_trx_commit设置为0,mysqld进程的崩溃会导致上一秒钟所有事务数据的丢失。
#当innodb_flush_log_at_trx_commit设置为2,只有在操作系统崩溃或者系统掉电的情况下,上一秒钟所有事务数据才可能丢失。
#commit事务时,控制redo log buff持久化磁盘的模式 默认为1
innodb_flush_log_at_trx_commit = 2
#commit事务时,控制写入mysql binlog日志的模式 默认为 0
#innodb_flush_log_at_trx_commit和sync_binlog都为1时,mysql最为安全但性能上压力也是最大
sync_binlog = 1
##---redo log 和 binlog的关系设置END---##
 
############################Innodb设置##########################################
#数据块的单位8k,默认是16k,16kCPU压力稍小,8k对select的吞吐量大
#innodb_page_size的参数值也影响最大索引长度,8k比16k的最大索引长度小
#innodb_page_size = 8192
#一般设置物理存储的60% ~ 70%
innodb_buffer_pool_size = 1G
 
#5.7.6之后默认16M
#innodb_log_buffer_size = 16777216
#该参数针对unix、linux,window上直接注释该参数.默认值为NULL
#O_DIRECT减少操作系统级别VFS的缓存和Innodb本身的buffer缓存之间的冲突
innodb_flush_method = O_DIRECT
 
#此格式支持压缩, 5.7.7之后为默认值
innodb_file_format = Barracuda
 
#CPU多核处理能力设置,假设CPU是2颗4核的,设置如下
#读多,写少可以设成2:6的比例
innodb_write_io_threads = 4
innodb_read_io_threads = 4
 
#提高刷新脏页数量和合并插入数量,改善磁盘I/O处理能力
#默认值200(单位:页)
#可根据磁盘近期的IOPS确定该值
innodb_io_capacity = 500
 
#为了获取被锁定的资源最大等待时间,默认50秒,超过该时间会报如下错误:
# ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
innodb_lock_wait_timeout = 30
 
#调整buffer pool中最近使用的页读取并dump的百分比,通过设置该参数可以减少转储的page数
innodb_buffer_pool_dump_pct = 40

#设置redoLog文件所在目录, redoLog记录事务具体操作内容
innodb_log_group_home_dir = /data/mysql/
 
#设置undoLog文件所在目录, undoLog用于事务回滚操作
innodb_undo_directory = /data/mysql/
 
#在innodb_log_group_home_dir中的redoLog文件数, redoLog文件内容是循环覆盖写入。
innodb_log_files_in_group = 3
 
#MySql5.7官方建议尽量设置的大些,可以接近innodb_buffer_pool_size的大小
#之前设置该值较大时可能导致mysql宕机恢复时间过长,现在恢复已经加快很多了
#该值减少脏数据刷新到磁盘的频次
#最大值innodb_log_file_size * innodb_log_files_in_group <= 512GB,单文件<=256GB
innodb_log_file_size = 1024M
 
#设置undoLog文件所占空间可以回收
#5.7之前的MySql的undoLog文件一直增大无法回收
innodb_undo_log_truncate = 1
innodb_undo_tablespaces = 3
innodb_undo_logs = 128
 
#5.7.7默认开启该参数 控制单列索引长度最大达到3072
#innodb_large_prefix = 1
 
#5.7.8默认为4个, Inodb后台清理工作的线程数
#innodb_purge_threads = 4
 
innodb_file_per_table=1

#通过设置配置参数innodb_thread_concurrency来限制并发线程的数量,
#一旦执行线程的数量达到这个限制,额外的线程在被放置到对队列中之前,会睡眠数微秒,
#可以通过设定参数innodb_thread_sleep_delay来配置睡眠时间
#该值默认为0,在官方doc上,对于innodb_thread_concurrency的使用,也给出了一些建议:
#(1)如果一个工作负载中,并发用户线程的数量小于64,建议设置innodb_thread_concurrency=0;
#(2)如果工作负载一直较为严重甚至偶尔达到顶峰,建议先设置innodb_thread_concurrency=128,
###并通过不断的降低这个参数,96, 80, 64等等,直到发现能够提供最佳性能的线程数
#innodb_thread_concurrency = 0
############################其他内容 设置##########################################

#屏蔽ONLY_FULL_GROUP_BY 否则报错

#sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


[mysqldump]
quick
max_allowed_packet = 128M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 256k
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
#增加每个进程的可打开文件数量.
open-files-limit = 28192

5. 启动MySQL

#启动MySQL
systemctl start mysqld

#自动启动MySQL
systemctl enable mysqld

6.设置密码

grep "temporary password"  /data/mysql/error.log 
SET PASSWORD = PASSWORD('你的新密码');

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword'

SSH 端口号修改

1. 修改配置文件

vim /etc/ssh/sshd_config

2、重启ssh:

systemctl restart sshd

3、查看ssh端口

netstat -ntlp

安装 Nginx

1. 查看Nginx是否配置成功

#yum list nginx

Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
nginx                              | 2.9 kB     00:00     
nginx/primary_db                   |  36 kB     00:00     
Available Packages
nginx.x86_64                        1.14.0-1.el6.ngx                                                                nginx

#yum list |grep nginx
[root@MiWiFi-R1D yum.repos.d]# yum list |grep nginx
nginx.x86_64                               1.14.0-1.el6.ngx              nginx  
nginx-debug.x86_64                         1.8.0-1.el6.ngx               nginx  
nginx-debuginfo.x86_64                     1.14.0-1.el6.ngx              nginx  
nginx-module-geoip.x86_64                  1.14.0-1.el6.ngx              nginx  
nginx-module-geoip-debuginfo.x86_64        1.14.0-1.el6.ngx              nginx  
nginx-module-image-filter.x86_64           1.14.0-1.el6.ngx              nginx  
nginx-module-image-filter-debuginfo.x86_64 1.14.0-1.el6.ngx              nginx  
nginx-module-njs.x86_64                    1.14.0.0.2.0-1.el6.ngx        nginx  
nginx-module-njs-debuginfo.x86_64          1.14.0.0.2.0-1.el6.ngx        nginx  
nginx-module-perl.x86_64                   1.14.0-1.el6.ngx              nginx  
nginx-module-perl-debuginfo.x86_64         1.14.0-1.el6.ngx              nginx  
nginx-module-xslt.x86_64                   1.14.0-1.el6.ngx              nginx  
nginx-module-xslt-debuginfo.x86_64         1.14.0-1.el6.ngx              nginx  
nginx-nr-agent.noarch                      2.0.0-12.el6.ngx              nginx  
pcp-pmda-nginx.x86_64                      3.10.9-9.el6                  base   

2. 安装

直接安装nginx

#yum -y install nginx

3. 开机启动设置

#systemctl enable nginx
#systemctl daemon-reload

4.添加www用户

#adduser  www 
#passwd   www
[root@MiWiFi-R1D nginx]# passwd www
Changing password for user www.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

5. 修改Nginx用户为www

vim  /etc/nginx/nginx.conf 


# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user www;
worker_processes auto;
error_log /data/www/logs/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /data/www/logs/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;


    fastcgi_intercept_errors on;	


    #Gzip Compression
    gzip on;
    gzip_buffers 16 8k;
    gzip_comp_level 6;
    gzip_http_version 1.1;
    gzip_min_length 256;
    gzip_proxied any;
    gzip_vary on;
    gzip_types
        text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
        text/javascript application/javascript application/x-javascript
        text/x-json application/json application/x-web-app-manifest+json
        text/css text/plain text/x-component
        font/opentype application/x-font-ttf application/vnd.ms-fontobject
        image/x-icon;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    # disable IP access to the web.
    # server {   
    #     listen 80 default; 
    #     server_name _;
    #     return 500;  
    # } 





    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}


6.修改相应的Nginx目录权限


cd  /var/cache/nginx
chown www.root  -R  * 

7.新启动Nginx

systemctl stop nginx 
systemctl restart nginx 
 类似资料: