Alex的博客

本博客的文章均为原创,是本人从事行业多年来所遇见一些小问题的解决心得,希望可以帮助到大家!



centos6.5安装mysql5.6+nginx+php

下载页面:http://dev.mysql.com/downloads/mysql/

下载地址:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz

也可以直接下载下面的附件

在安装之前我先教大家一下源码安装的方法吧,这样就不用每次都百度上找教程了.其实源码里面基本都是有安装说明的,直接看说明文档就好了.

我们解开一个包后,进入解压包,一般都能发现README(或reame)和INSTALL( 或install);或doc(或DOC)目录;看名字就知道个差不多;

5.7的说明文档在解压目录的docs目录下

INSTALL-BINARY文件就是说明文档

虽然都是英文的但是基本上都能看懂,你可以忽略说明直接看安装步骤就好了

下面部分是说明文档里面的安装步骤,按照下面的步骤来做启动mysql是完全没问题的.

======================================================

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chmod 750 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql    # Before MySQL 5.7.6
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up
shell> chown -R root .
shell> chown -R mysql data mysql-files
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
=====================================================


1,创建组

groupadd mysql

2,创建用户并添加到组

useradd -r -g mysql -s /bin/false mysql

3,进入目录(这个位置可以随意,自己喜欢那里就装那里)

cd /usr/local

4,然后把下载好的数据库源码包copy到这个位置并解压

tar zxvf /path/to/mysql-VERSION-OS.tar.gz

5,然后我们可以做一个软链接到解压的数据库文件夹,(当然也可以直接重命名这个文件夹,这个步骤只是为了方便后面的操作非必要)

ln -s full-path-to-mysql-VERSION-OS mysql

6,然后进入mysql源码目录

cd mysql

7,然后创建mysql-files目录

mkdir mysql-files

8,修改目录权限.

chmod 750 mysql-files

9,修改目录所有者

chown -R mysql .

10,修改目录所属组

chgrp -R mysql .

11,执行安装脚本(但是好像会报错说这个版本已经不用了用下面的语句)

bin/mysql_install_db --user=mysql
12,继续执行


bin/mysqld --initialize --user=mysql

如果报下面的错误就是缺少库

bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

提示这个是因为缺少库

直接允许下面的命令安装就好了

yum install libaio*

再运行bin/mysqld --initialize --user=mysql

会提示一些警告信息,不用理会,

[Note] A temporary password is generated for root@localhost: QjqV+/oN+0tF

这一句话里面的临时密码记下来等会儿登录需要用的(每个人的密码不一样).

13,继续运行

bin/mysql_ssl_rsa_setup

14,修改当前目录所有者为root

chown -R root .

15,修改三个目录的所有者为mysql

chown -R mysql data mysql-files

16,运行mysql

bin/mysqld_safe --user=mysql &

17,登录mysql(cd到bin目录)

mysql -u root -p刚才的临时密码

登录后还没办法操作数据库如果运行mysql指令会提示下面的错误

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

提示是要求先设置一下密码才能够使用

执行:set password = password('新密码');

就可以正常使用了

18,copy服务文件到系统目录(否则没办法用server管理服务)

cp support-files/mysql.server /etc/init.d/mysqld

19,链接mysql到系统目录 以便直接使用mysql命令管理数据库(链接后就可以直接运行mysql命令了)


cd /usr/bin

ln -s /usr/local/mysql/bin/mysql mysql


=====================================================================================

也可以用yum安装最新的mysql

下载对应服务器版本的yum源包

http://dev.mysql.com/downloads/repo/yum/

centos的是这个

http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm

然后就是安抓这个rpm包如果不知道怎么安装可以看官方教程

http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

yum install mysql57-community-release-el6-7.noarch.rpm

当然你也可以用rpm安装


yum repolist all | grep mysql

执行成功后查看是否成功


下面是官方提供的安装其他版本的教程我就不自己写了直接贴出来

To install the latest release from the latest GA series, no configuration is needed. To install the latest release from a specific series other than the latest GA series, disable the subrepository for the latest GA series and enable the subrepository for the specific series before running the installation command. You can do that by editing manually the /etc/yum.repos.d/mysql-community.repo file. This is a typical entry for a release series' subrepository in the file:

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

Find the entry for the subrepository you want to configure, and edit the enabled option. Specify enabled=0 to disable a subrepository, or enabled=1 to enable a subrepository. For example, to install MySQl 5.6, make sure you have enabled=0 for the above subrepository entry for MySQL 5.7, and have enabled=1 for the entry for the 5.6 series:

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

You should only enable subrepository for one release series at any time. When subrepositories for more than one release series are enabled, the latest series will be used by Yum.

Verify that the correct subrepositories have been enabled and disabled by running the following command and checking its output (for dnf-enabled systems, replace yum in the command with dnf):

shell> yum repolist enabled | grep mysql 



  1. Installing MySQL

    Install MySQL by the following command (for dnf-enabled systems, replace yum in the command with dnf):

    shell> sudo yum install mysql-community-server 

    This installs the package for the MySQL server, as well as other required packages.

  2. Starting the MySQL Server

    Start the MySQL server with the following command:

    shell> sudo service mysqld start


    You can check the status of the MySQL server with the following command:

    shell> sudo service mysqld status

  3. For MySQL 5.7 only: At the initial start up of the server, the following happens, given that the data directory of the server is empty:

    • The server is initialized.

    • An SSL certificate and key files are generated in the data directory.

    • The validate_password plugin is installed and enabled.

    • A superuser account 'root'@'localhost' is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:

      shell> sudo grep 'temporary password' /var/log/mysqld.log 

      Change the root password as soon as possible by logging in with the generated, temporary password and set a custom password for the superuser account:

      shell> mysql -uroot -p  
      mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 
    Note

    MySQL's validate_password plugin is installed by default. This will require that passwords contain at least one upper case letter, one lower case letter, one digit, and one special character, and that the total password length is at least 8 characters.


到此数据库就已经安装完毕了


这里我再总结一下把:

==========================================================

yum -y update

yum -y install wget

wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm

yum install mysql57-community-release-el6-7.noarch.rpm

yum repolist all | grep mysql

yum install mysql-community-server

说明一下如果mysql启动不失败的话就关闭selinux

打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled

setenforce 0

这个时候已经可以启动mysql了

如果你根据官方文档里面说的没有找到临时密码那么就只能和我一样重置root密码了

重置流程:

service mysqld stop

mysqld_safe --skip-grant-tables &

了安全可以这样禁止远程连接:
mysqld_safe --skip-grant-tables --skip-networking &

mysql -u root -p

update mysql.user set authentication_string=password('newspassword') where user='root' and Host = 'localhost';

(newspassword)为新密码,特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了,而是将加密后的用户密码存储于authentication_string字段

flush privileges;

quit;

 killall mysqld

service mysqld start

mysql -u root -ppassword

这个也是重置mysql密码的流程

这个时候你如果执行mysql语句还是会提示你要重置用户密码.如下提示

(ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.)

这个时候我们重置一下就好了,命令如下:

set password = password('新密码');

==========================================================

安装完成



yum 安装nginx

vi  /etc/yum.repos.d/nginx.repo

写入:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1


下载key:

http://nginx.org/keys/nginx_signing.key

导入key

rpm --import nginx_signing.key
查看是否已经有nginx软件包,而且是稳定 版    


yum list | grep nginx


安装软件

yum -y install nginx


安装php

yum -y install php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator


=====================================

安装php5.6

=====================================

配置yum源

追加CentOS 6.5的epel及remi源。

# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
如果上面的无法访问可以使用本站的

rpm -Uvh http://www.btfw.org/linux/centos6_php5.6x64/epel-release-6-8.noarch.rpm

rpm -Uvh http://www.btfw.org/linux/centos6_php5.6x64/remi-release-6.rpm

以下是CentOS 7.0的源。

# yum install epel-release
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

使用yum list命令查看可安装的包(Packege)。

# yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

安装PHP5.6

yum源配置好了,下一步就安装PHP5.6。

# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof  php56-php-fpm php56-php-mysql php56-php-soap php56-php-mbstring php56-php-gd php56-php-xml  php56-php-xmlrpc


启动php-fmp

service php56-php-fpm start

开启gzip

vi /etc/nginx/nginx.conf

搜索gzip并去掉#


添加nginx 默认主页index.php
vim /etc/nginx/conf.d/default.conf
location / {
       root   /usr/share/nginx/html;
       index  index.html index.htm index.php;
   }

配置nginx支持php
[root@localhost ~]#vim /etc/nginx/conf.d/default.conf

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
   #
   location ~ \.php$ {
       root           /usr/share/nginx/html;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;
       include        fastcgi_params;

   }

如果出现file not found. 就说明 fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;  没有修改正确,并且没有指定正确php文件目录

配置php-fpm
[root@localhost ~]# vim /etc/php-fpm.d/www.conf

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx


php配置文件在:/opt/remi/php56/root/etc/php.ini





正在启动 nginx: 
service nginx start
正在启动 php-fpm:
/etc/rc.d/init.d/php-fpm start


收工线写到这里有空再改改

浏览632  评论0  Alex于 2016-3-22 16:28
发言