- 关于Nginx的编译安装参照
( “Nginx的编译安装以及简单配置”)
[http://blog.csdn.net/qq_36294875/article/details/79344943]
- 操作系统环境
操作系统版本:
rhel6.5
内核版本:2.6.32-431.el6.x86_64
主机名称:server6.com
主机IP:172.25.23.6/24
MySQl软件包:mysql-boost-5.7.11.tar.gz
Cmake软件包:cmake-2.8.12.2-4.el6.x86_64.rpm
使用KVM虚拟机进行编译
编译安装需要注意的几项
- 需要确保虚拟机的内存在20G以上,空闲内存需要在10G以上;
- 编译需要的内存在
2G
以上; - 由于是在 虚拟机中进行编译,,即使虚拟机的CPU数目大于
2
,不建议使用make -j #
的选项; - 编译安装之前,系统上面,如果有通过
rpm
软件包安装的Mysql
,建议卸载; rhel6.5
提供的cmake
软件包,过于早,这里使用制作好的RPM
软件包;
编译过程中可能出现的错误,以及解决办法
- 错误1:
CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
This CMake script will look for boost in <directory>. If it is not there,
it will download and unpack it (in that directory) for you.
If you are inside a firewall, you may need to use an http proxy:
export http_proxy=http://example.com:80
Call Stack (most recent call first):
cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
CMakeLists.txt:443 (INCLUDE)
- 解决1
在
Mysql5.5.*
系列之后,Mysql
必须和Boost
一起进行编译安装,在上述的软件包里面,提供了boost
,需要指定路径;-DWITH_BOOST=boot/boost_1_59_0/ 增加编译选项
错误2:
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: Internal CMake error, TryCompile configure of cmake failed
CMake Error at cmake/readline.cmake:64 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:107 (FIND_CURSES)
cmake/readline.cmake:181 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:471 (MYSQL_CHECK_EDITLINE)
- 解决2
[root@server6 mysql-5.7.11]# yum install ncurses-devel gcc-c++ -y
- 错误3
CMake Warning at cmake/bison.cmake:20 (MESSAGE):
Bison executable not found in PATH
Call Stack (most recent call first):
sql/CMakeLists.txt:514 (INCLUDE)
CMake Warning at cmake/bison.cmake:20 (MESSAGE):
Bison executable not found in PATH
Call Stack (most recent call first):
libmysqld/CMakeLists.txt:142 (INCLUDE)
- 解决3
[root@server6 mysql-5.7.11]# yum install -y bison -y
- 根据编译的选项不同,出现的错误可能不同,在每次修改错误重新进行cmake时,建议删除
[root@server6 mysql-5.7.11]# rm -f CMakeCache.txt
- 编译的过程
- 解压软件包并且使用
cmake
进行安装
[root@server6 local]# tar zxf mysql-boost-5.7.11.tar.gz
[root@server6 local]# yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y
//上面的cmake不是系统自带的;
使用cmake
进行编译安装- 编译安装的选项
-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNODBASE_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BOOST=boot/boost_1_59_0/ 增加编译选项
- 执行编译安装
[root@server6 mysql-5.7.11]# cmake
> -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql\
> -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \
> -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNODBASE_STORAGE_ENGINE=1 \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DEXTRA_CHARSETS=all \
> -DWITH_BOOST=boot/boost_1_59_0/ 增加编译选项
- 确认
cmake
执行过程中没有Error
,以及Warning
- 接下来执行
make
操作
[root@server6 ~]# make
- 确认
make
完成之后,执行make install
[root@server6 ~]# make install
- 复制
Mysql
的文件
[root@server6 mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@server6 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
- 修改环境变量
[root@server6 mysql]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin/
- 添加
Mysql
用户
[root@server6 mysql]# useradd -u 27 -M -d /usr/local/lnmp/mysql/ -s /sbin/nologin mysql
[root@server6 mysql]# id mysql
uid=27(mysql) gid=1001(mysql) groups=1001(mysql)
[root@server6 mysql]# groupmod -g 27 mysql
[root@server6 mysql]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
- 更改文件的权限,数据目录的属主是
Mysql
,配置文件目录的属主是root
[root@server6 mysql]# chown mysql.mysql ./ -R
[root@server6 mysql]# chown root . -R
[root@server6 mysql]# chown mysql data/ -R
[root@server6 mysql]# ll
total 60
drwxr-xr-x. 2 root mysql 4096 2月 23 10:54 bin
-rw-r--r--. 1 root mysql 17987 2月 2 2016 COPYING
drwxr-xr-x. 2 mysql mysql 4096 2月 23 12:33 data
drwxr-xr-x. 2 root mysql 4096 2月 23 10:52 docs
drwxr-xr-x. 3 root mysql 4096 2月 23 10:52 include
drwxr-xr-x. 4 root mysql 4096 2月 23 10:54 lib
drwxr-xr-x. 4 root mysql 4096 2月 23 10:53 man
drwxr-xr-x. 10 root mysql 4096 2月 23 10:55 mysql-test
-rw-r--r--. 1 root mysql 2478 2月 2 2016 README
drwxr-xr-x. 28 root mysql 4096 2月 23 10:55 share
drwxr-xr-x. 2 root mysql 4096 2月 23 10:55 support-files
- 数据库的初始化
[root@server6 bin]# mysqld --initialize --user=root
2018-02-23T05:05:51.878670Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-02-23T05:05:51.878713Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-02-23T05:05:51.878717Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2018-02-23T05:05:55.784047Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-02-23T05:05:56.750108Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-02-23T05:05:57.082715Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3b4b8706-1857-11e8-8ec0-525400a98e38.
2018-02-23T05:05:57.176949Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-02-23T05:05:57.177741Z 1 [Note] A temporary password is generated for root@localhost: )hX;&9frfhy:
需要记住下图中关于密码的内容
启动
mysql
服务器
[root@server6 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@server6 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
- 检查端口
[root@server6 mysql]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1011/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1087/master
tcp 0 0 172.25.23.6:22 172.25.23.250:53574 ESTABLISHED 1159/sshd
tcp 0 0 :::22 :::* LISTEN 1011/sshd
tcp 0 0 ::1:25 :::* LISTEN 1087/master
tcp 0 0 :::3306 :::* LISTEN 4283/mysqld
- 使用临时密码进行登录,并且修改密码
[root@server6 mysql]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.11
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
er version: 5.7.11
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
# mysql> alter user root@localhost identified by 'westos';
Query OK, 0 rows affected (0.00 sec)
- 如果需要配置面密登录
[root@server6 mysql]# vim /root/.mysql_secret
westos(新的密码);
[root@server6 mysql]# chmod 600 /root/.mysql_secret
不建议采用上面的方法
* Mysql提供的安全环境配置脚本 建议执行
[root@server6 mysql]# mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL server using password in '/root/.mysql_secret'
VALIDATE PASSWORD PLUGIN 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 plugin?
Press y|Y for Yes, any other key for No: Yes
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Using existing password for root.
Estimated strength of the password: 25
Change the password for root ? ((Press y|Y for Yes, any other key for No) : No
... skipping.
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
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) : No
... skipping.
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
- 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) : No
... skipping.
All done!
- 上述脚本根据实际需求进行选择
- Make过程中出现的错误
- 错误1
- 这是我在虚拟机里面进行编译出现的情况,不要采用
make -j #
,只使用make
- 错误2
- 这个虽然只是一个
Warining
,但是出现的次数过多,会导致Make Error
出错; - 建议更新
cmake版本
,或者编译安装cmake
;