标签:关系数据库 web服务器 数据库管理 解决方案 应用软件
Lnmp架构之MYSQL:关系型数据库管理系统
MySQL 是一个关系型数据库,由瑞典MySQL AB 公司开发,目前属于Oracle旗下公司。MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面 MySQL 是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件之一。MySQL 是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。MySQL 所使用的 SQL 语言是用于访问数据库的最常用标准化语言。MySQL 软件采用了双授权政策(本词条"授权政策"),它分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择 MySQL 作为网站数据库。由于其社区版的性能卓越,搭配php ,Linux和 Apache可组成良好的开发环境,经过多年的web技术发展,在业内被广泛使用的一种web服务器解决方案之一,称之为LAMP。
CMake是一个比make更高级的编译配置工具,它可以根据不同平台、不同的编译器,生成相应的Makefile或者vcproj项目。通过编写CMakeLists.txt,可以控制生成的Makefile,从而控制编译过程。CMake自动生成的Makefile不仅可以通过make命令构建项目生成目标文件,还支持安装(make install)、测试安装的程序是否能正确执行(make test,或者ctest)、生成当前平台的安装包(make package)、生成源码包(make package_source)、产生Dashboard显示数据并上传等高级功能,只要在CMakeLists.txt中简单配置,就可以完成很多复杂的功能,包括写测试用例。如果有嵌套目录,子目录下可以有自己的CMakeLists.txt。总之,CMake是一个非常强大的编译自动配置工具,支持各种平台。
系统环境: RHEL6.5 x86-64
准备:lscpu ##查看cpu,了解该虚拟机的硬件配置,通过查看将进程Processor里的cpu调为2(运行更为稳定),将内存memory调为2048M,并添加一块20G的虚拟磁盘Virtual disk(防止在编译时报错)。
1.逻辑卷拉伸,为编译留够空间
fdisk -cu /dev/vdb ##分区
n ##新建
p ##指定划分设备的分区类型为primary
1 ##指定使用的分区表号
##分区起始快,选择默认
##设备大小指定,由于只分一个区,故可选默认
t ##改变分区功能标签
8e ##将分区功能标签类型改为LVM
w ##保存更改的分区表
pvcreate /dev/vdb1 ##创建物理卷
vgextend VolGroup /dev/vdb1 ##物理卷组拉伸
lvextend -L +20g /dev/VolGroup/lv_root ##逻辑卷拉伸到20G
lvextend -l +5119 /dev/VolGroup/lv_root
resize2fs /dev/VolGroup/lv_root ##设定文件系统大小和设备同步
2.mysql源码编译
yum install -y gcc gcc-c++ make ncurses-devel bison openssl-devel zlib-devel
rpm -Uvh cmake-2.8.12.2-4.el6.x86_64.rpm ##升级cmake并显示安装信息
yum update -y cmake ##更新
[root@server2 ~]# cmake -version
cmake version 2.8.12.2 ##注意一定要将cmake 升级到2.8的版本以上,否则下一步就会报错
tar zxf mysql-boost-5.7.11.tar.gz
cd 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 \ ##安装myisam存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ ##安装 innodb 存储引擎
-DDEFAULT_CHARSET=utf8 \ ##使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci \ ##校验字符
-DEXTRA_CHARSETS=all \ ##安装所有扩展字符集
-DWITH_BOOST=boost/boost_1_59_0/ ##boost路径
注意:
rm -fr CMakeCache.txt ##若报错 每次都要删除已经存在的CMakeCache.txt
make -j2 ##用2个cpu完成编译
make install ##没报错的话再安装
[root@server2 mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS! ##能启动数据库说明源码编译和安装成功
netstat -antple ##监听网络端口,若3306开启,说明数据库开启成功
如图:
3.mysql基本设置
useradd -u 27 -s /bin/false mysql ##添加mysql用户
groupmod -g 27 mysql ##更改所有组
cp /usr/local/lnmp/mysql/support-files/mysql.server /etc/init.d/mysqld
mv /etc/my.cnf /etc/my.cnf.bak
cp /usr/local/lnmp/mysql/support-files/my-default.cnf /etc/my.cnf
vim ~/.bash_profile ##设置环境变量
PATH=$PATH:$HOME/bin:/usr/local/lnmp/nginx/sbin:/usr/local/lnmp/mysql/bin
export PATH
source ~/.bash_profile ##生效
chown -R mysql.mysql /usr/local/lnmp/mysql ##将mysql目录下的所有人所有组都变成mysql
[root@server2 mysql]# mysqld --initialize --user=mysql ##密码为空,用户为mysql
2016-07-29T03:39:44.445188Z 1 [Note] A temporary password is generated for root@localhost: 3i5M7wiW=+aR ##系统随机产生的密码,用于首次登陆数据库和数据库安全初始化
[root@server2 mysql]# mysql_secure_installation ##数据库安全初始化
Securing the MySQL server deployment.
Enter password for user root: 3i5M7wiW=+aR
The existing password for the user account root has expired. Please set a new password.
New password: GAOfag123+++ ##注意这里设置的密码一定要大于八位,必须符合大小写均涵盖的字母组合以及数字与特殊符号,密码强度很高
Re-enter new password: GAOfag123+++
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: y
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: 2
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
New password: GAOfag123+++
Re-enter new password: GAOfag123+++
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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) : 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
- 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
Success.
All done!
[root@server2 mysql]# mysql -p
Enter password: GAOfag123+++
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.11 Source distribution
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 owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> quit
Bye
本文出自 “jeffrey13” 博客,谢绝转载!
标签:关系数据库 web服务器 数据库管理 解决方案 应用软件
原文地址:http://jeffrey13.blog.51cto.com/8875406/1831892