Centos7.x二进制安装mysql8.0
系统Centos7.6

关闭THP
vi /etc/rc.local
在文件末尾添加如下指令:
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
	echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
	echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
	
添加可执行权限
		chmod +x /etc/rc.local
	
重启以后查看,和以下内容一样即可
[root@db-1 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[root@db-1 ~]# cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
		
系统层面参数优化
	更改文件句柄和进程数
内核优化 /etc/sysctl.conf
vim /etc/sysctl.conf
最后一行添加以下内容
vm.swappiness = 5
vm.dirty_ratio = 20
vm.dirty_background_ratio = 10
net.ipv4.tcp_max_syn_backlog = 819200
net.core.netdev_max_backlog = 400000
net.core.somaxconn = 4096
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_tw_recycle=0
修改好以后保存退出
		
让配置生效
[root@db-1 ~]# sysctl -p

解释:
	vm.swappiness = 5
		内核参数vm.swappiness控制换出运行时内存的相对权重,参数值大小对如何使用swap分区有很大联系。值越大,表示越积极使用swap分区,越小表示越积极使用物理内存。默认值swappiness=60,表示内存使用率超过100-60=40%时开始使用交换分区。swappiness=0的时候表示最大限度使用物理内存,而后才是 swap空间;swappiness=100的时候表示积极使用swap分区,并把内存上的数据及时搬运到swap空间。(网上有的说,对于3.5之后的内核和RedHat 2.6.32以后的内核,设置为0会禁止使用swap,从而引起out of memory,这种状况能够设置为1。)

	vm.dirty_ratio = 20
		在此示例中,当脏页超过vm.dirty_background_ratio=10 I / O启动时,即它们开始刷新/写入磁盘。当脏页总数超过vm.dirty_ratio=20时,所有写入都会被阻止,直到某些脏页写入磁盘。。
		如果是固态硬盘设置成20刷新的频率高一些
		如果是机械硬盘就需要把这个值往上调一下
		
	vm.dirty_background_ratio = 10
		是内存可以填充脏数据的百分比。这些脏数据稍后会写入磁盘
		
设置最大打开文件数	
vim /etc/security/limits.conf
最后一行添加以下内容
* soft nofile 65535
* hard nofile 65535
保存退出
			
			
防火墙
	禁用selinux : /etc/sysconfig/selinux 更改SELINUX=disabled.
		sed -i '/SELINUX/{s/enforcing/disabled/}' /etc/selinux/config
	
	iptables如果不使用可以关闭。可是需要打开MySQL需要的端口号
	Centos7是firewalld
		systemctl disable firewalld --now
	
	Centos6关闭防火墙
		chkconfig iptables off
		service iptables stop
		
!!!!系统配置优化以后,建议把系统重新启动一下再来安装mysql!!!
	
Mysql下载地址,下载8.0二进制版本
	https://downloads.mysql.com/archives/community/
	
我们这次的安装的版本。二进制版本
	mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz

移除掉系统自带的mariadb数据库软件包
	yum remove mariadb-libs -y

创建mysql用户
	useradd -s /sbin/nologin -M mysql
	
创建mysql数据库存放目录和binlog日志目录
	mkdir -pv /data/mysql/{data_3306,binlog_3306}
	
解压mysql二进制软件包,解压到/usr/local/下
	tar xf mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
	
创建软连接mysql,方便后期升级不用改变目录
	ln -s /usr/local/mysql-8.0.25-linux-glibc2.12-x86_64 /usr/local/mysql

添加mysql环境变量
	echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
	
让环境变量生效
	source /etc/profile.d/mysql.sh
	
授权mysql的属主和数组给mysql的数据库目录
	chown -R mysql.mysql /data/
	
授权mysql软件安装目录给mysql属主属组
	chown -R mysql.mysql /usr/local/mysql/
	
安装libaio软件包(异步IO),不然会mysql初始化的时候会报错
	yum install libaio libaio-devel -y
	
初始化mysql,指定mysql用户名,指定mysql安装目录,指定mysql数据库存放目录
	mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/data_3306
	返回结果:
	2021-10-26T06:18:31.580889Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
	2021-10-26T06:18:31.580990Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.25-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.25) initializing of server in progress as process 24590
	2021-10-26T06:18:31.587352Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
	2021-10-26T06:18:32.218291Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
	2021-10-26T06:18:32.947514Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option
	数据库是没有密码的可以直接使用mysql进入
	
准备数据库启动时的加载配置文件
vim /etc/my.cnf
写入以下内容
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql/data_3306
socket=/tmp/mysql.sock
server_id=1
log_bin=/data/mysql/binlog_3306
port=3306
secure_file_priv = /data
character-set-server=utf8mb4
[mysql]
socket=/tmp/mysql.sock
default-character-set=utf8mb4
保存退出
	
	解释:
	[mysqld]
		mysqld模块
	
	user=mysql
		指定mysql用户
	
	basedir=/usr/local/mysql
		指定mysql安装目录
	
	datadir=/data/mysql/data_3306
		指定mysql数据库目录存放目录
	
	sockek=/tmp/mysql.sock
		mysql套接字,用于连接mysql使用
	
	server_id=1
		mysql的serverid的唯一标识符
	
	log_bin=/data/mysql/binlog_3306
		mysql的logbin日志启动后的存放目录
	
	port=3306
		mysql的端口
	
	[mysql]
		客户端mysql模块
	
	sockek=/tmp/mysql.sock
		客户端连接的套接字
		
复制启动程序到/etc/init.d/下
	cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
	
添加mysqld开机自启动
	chkconfig --add mysqld
	
启动mysql
	service mysqld start
	
利用安全脚本初始化数据库
	mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:
这里是问你是否有数据库的密码,我初始化的时候密码为空可以直接回车

Please set the password for root here.

New password:
设置一个新的密码,输入密码时不显示

Re-enter new password: 
再输入一次密码
	
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
是否移除匿名用户这里选择y回车
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
这里问你是否禁用root用户远程登录,根据自己的需求选择可以n或者y我选择y

Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) :y
是否移除test测试数据库这里选择 y	
	 
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
是否刷新权限这里选择y	 
	
登录mysql
	mysql -u root -p123456	


本文 暂无 评论

Top