编写日期:2016-09-19
编写作者:mtsbv110
部署环境
操作系统: :CentOS Linux release 7.2.1511 (Core) cat /etc/redhat-release
Mysql版本:mysql-5.6.26.tar.gz
操作用户: root
系统IP: 192.168.9.66
主机名: jetsen-analysis-01
系统IP: 192.168.9.67
主机名: jetsen-analysis-02
配置: 8核 8G cat/proc/cpuinfo |grep "name" |cut -f2 -d: |uniq –c
grepMemTotal /proc/meminfo
一、服务器配置
1、 设置主机名
[root@localhost /]# hostnamectl --static set-hostnamejetsen-analysis-01
2、 设置IP与主机名之间的映射
jetsen-analysis-01 192.168.9.66
3、 永久关闭vim/etc/selinux/config selinuxSELINUX=disabled
4、 同理修改192.168.9.67的服务器配置信息
5、 重启两台服务器reboot
二、源码安装MySQL 5.6.26
1、 使用命令检查是否安装Mysql
[root@jetsen-analysis-01 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.50-1.el7_2.x86_64
mariadb-5.5.50-1.el7_2.x86_64
mariadb-server-5.5.50-1.el7_2.x86_64
2、卸载CentOS7默认安装的mariadb
[root@jetsen-analysis-01 ~]# rpm -e--nodeps mariadb-libs-5.5.50-1.el7_2.x86_64
[root@jetsen-analysis-01 ~]# rpm -e--nodeps mariadb-5.5.50-1.el7_2.x86_64
[root@jetsen-analysis-01 ~]# rpm -e--nodeps mariadb-server-5.5.50-1.el7_2.x86_64
3、 新增mysql用户组:
[root@jetsen-analysis-01 ~]# groupadd mysql 如已存在,则不用创建或则删除重新创建userdel -rf mysql
4、 新增mysql用户,并添加到mysql用户组
[root@jetsen-analysis-01 ~]# useradd -r -g mysql mysql
5、 新建Mysql执行文件目录(后面会讲编译好的mysql程序安装到这个目录)
[root@jetsen-analysis-01 ~]# mkdir -p /usr/local/mysql
6、 新建MYSQL数据库数据文件目录
[root@jetsen-analysis-01 ~]# mkdir -p /home/mysql/data
[root@jetsen-analysis-01 ~]# mkdir -p /home/mysql/logs
[root@jetsen-analysis-01 ~]# mkdir -p /home/mysql/temp
以上文件的logs和temp目录是为了以后将Mysql的数据文件和执行程序文件分离。
7、 增加PATH环境变量搜索路径:
#mysqlenv param
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
[root@jetsen-analysis-01~]# source /etc/profile
8、安装编译Mysql需要的依赖包
[root@jetsen-analysis-01~]# yum install make cmake gcc gcc-c++ bison bison-devel ncurses ncurses-develautoconf automake
9、 进入/usr/local/src目录,将mysql源码上传到此目录,解压
[root@jetsen-analysis-01 ~]# cd /usr/local/src/
[root@jetsen-analysis-01 src]# tar -zxvfmysql-5.6.26.tar.gz
进入解压目录进行安装
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock\
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci\
-DWITH_MYISAM_STORAGE_ENGINE=1\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_ARCHIVE_STORAGE_ENGINE=1\
-DWITH_BLACKHOLE_STORAGE_ENGINE=1\
-DWITH_MEMORY_STORAGE_ENGINE=1\
-DWITH_READLINE=1\
-DENABLED_LOCAL_INFILE=1\
-DMYSQL_DATADIR=/home/mysql/data\
-DMYSQL_USER=mysql\
-DMYSQL_TCP_PORT=3306\
-DENABLE_DOWNLOADS=1
10、 Cmake结束之后进行make编译安装
[root@jetsen-analysis-01 mysql-5.6.26]# make
11、 安装编译好的程序
[root@jetsen-analysis-01 mysql-5.6.26]# make install
12、 清空安装临时文件
[root@jetsen-analysis-02 mysql-5.6.26]# make clean
13、 修改mysql目录拥有者为mysql用户
[root@jetsen-analysis-01mysql-5.6.26]# chown -Rf mysql:mysql /usr/local/mysql
[root@jetsen-analysis-01 mysql-5.6.26]# chown -Rf mysql:mysql/home/mysql
14、 进入mysql执行程序安装路径执行初始化脚本
[root@jetsen-analysis-01 mysql-5.6.26]# cd /usr/local/mysql/
[root@jetsen-analysis-01 mysql]# scripts/mysql_install_db--user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/data
15、 初始化脚本在/usr/local/mysql下生成配置文件my.cnf,需要更改该配置文件的所有者
[root@jetsen-analysis-01 mysql]# ls –lah
[root@jetsen-analysis-01 mysql]# chown -Rf mysql:mysql/usr/local/mysql/my.cnf
注意:在启动Mysql服务时,会按照一定次序搜索my.cnf,现在/etc目录下诏,找不到会搜索mysql程序目录中是否有my.cnf
16、 将/usr/local/mysql目录下的my.cnf移动到/etc/my.cnf,将/usr/local/mysql下的重命名
[root@jetsen-analysis-02 etc]# cp my.cnf /etc/
[root@jetsen-analysis-02 mysql]# mv my.cnf my.cnf.bak
17、 编辑/etc/my.cnf
[client] port = 3306 socket = /usr/local/mysql/mysql.sock
[mysqld] character-set-server = utf8 collation-server = utf8_general_ci
skip-external-locking skip-name-resolve
user = mysql port = 3306 basedir = /usr/local/mysql datadir = /home/mysql/data tmpdir = /home/mysql/temp # server_id = ..... socket = /usr/local/mysql/mysql.sock log-error = /home/mysql/logs/mysql_error.log pid-file = /home/mysql/mysql.pid
open_files_limit = 10240
back_log = 600 max_connections=500 max_connect_errors = 6000 wait_timeout=605800
#open_tables = 600 #table_cache = 650 #opened_tables = 630
max_allowed_packet = 32M
sort_buffer_size = 4M join_buffer_size = 4M thread_cache_size = 300 query_cache_type = 1 query_cache_size = 256M query_cache_limit = 2M query_cache_min_res_unit = 16k
tmp_table_size = 256M max_heap_table_size = 256M
key_buffer_size = 256M read_buffer_size = 1M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 64M
lower_case_table_names=1
default-storage-engine = INNODB
innodb_buffer_pool_size = 2G innodb_log_buffer_size = 32M innodb_log_file_size = 128M innodb_flush_method = O_DIRECT
##################### thread_concurrency = 32 long_query_time= 2 slow-query-log = on slow-query-log-file = /home/mysql/logs/mysql-slow.log
## replication server_id=66 #binlog-do-db=roncoo binlog-ignore-db=mysql log-bin=jetsen-mysql-bin binlog_cache_size=1M binlog_format=mixed expire_logs_days=7 slave_skip_errors=1062
log_bin_trust_function_creators=true [mysqldump] quick max_allowed_packet = 32M
[mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
|
18、 复制服务启动脚本:
root@jetsen-analysis-01 mysql]# cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
19、 启动mysql服务,设置自启动服务
[root@jetsen-analysis-01 mysql]# service mysql start
[root@jetsen-analysis-01 mysql]# chkconfig mysql on
20、 配置Mysql用户root的密码、远程登录密码以及安全脚本设置
设置mysql数据库root本地登录密码
[root@jetsen-analysis-01 mysql]# mysqladmin -u rootpassword 'jetsen123'
设置mysql允许root远程登录密码
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'www.jetsen123' WITH GRANT OPTION;
mysql> flush privileges;
mysql> exit;
运行安全设置脚本
[root@jetsen-analysis-01 mysql]# /usr/local/mysql/bin/mysql_secure_installation
NOTE:RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In orderto log into MySQL to secure it, we'll need the current
passwordfor the root user. If you've justinstalled MySQL, and
youhaven't set the root password yet, the password will be blank,
so youshould just press enter here.
Entercurrent password for root (enter for none):
OK,successfully used password, moving on...
Settingthe root password ensures that nobody can log into the MySQL
root userwithout the proper authorisation.
Youalready have a root password set, so you can safely answer 'n'.
Changethe root password? [Y/n] n
... skipping.
Bydefault, a MySQL installation has an anonymous user, allowing anyone
to loginto MySQL without having to have a user account created for
them. This is intended only for testing, and tomake the installation
go a bitsmoother. You should remove them beforemoving into a
productionenvironment.
Removeanonymous users? [Y/n] y
... Success!
Normally,root should only be allowed to connect from 'localhost'. This
ensuresthat someone cannot guess at the root password from the network.
Disallowroot login remotely? [Y/n] n
... skipping.
Bydefault, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, andshould be removed
beforemoving into a production environment.
Removetest database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloadingthe privilege tables will ensure that all changes made so far
will takeeffect immediately.
Reloadprivilege tables now? [Y/n] y
... Success!
21、 以下操作全部在jetsen-analysis-02操作,方便使用主从复制。