搭建纯净LAPM环境:CentOS7.3 + Apache2.4.29 + Php5.6.35 + MySQL5.6.24 (1-MySQL5.6.24安装)

LAPM的环境一年内我已经搭建过很多次了。

每次总会出现很多坑,然后再一点点解决掉。

最终好不容易全部搞完了,可是真心累瘫。累了就想:幸亏搭建好了,以后估计也不会搭建了。

于是整个过程的记录也没有用文章记录下来。以至于下次再次搭建,又忘记了之前遇到的各种坑是怎么填平的,还得从头再趟一遍!

这不,昨天服务器供应商告诉我,因为老板觉得云服务器又麻烦又不挣钱,准备关掉云服务器的所有业务。提前通知我说,

兄弟,实在抱歉,老板准备关掉云服务器了。你的服务器数据赶紧迁移吧。

真几把坑爹啊。宝宝心里苦啊。我的十几项业务都跑在云主机上啊!但是问题总要面对的,总得去解决,抱怨没有用。

于是,这次痛定思痛,下定决心一定要把LAPM的环境搭建过程全部记录下来。

这样下次哥们儿再次搭建LAPM的环境就可以手到擒来,分分钟恢复各项业务了。

1、先装MySQL

官网安装指导页面:https://dev.mysql.com/doc/refman/5.6/en/installing.html

安装步骤页面:https://dev.mysql.com/doc/refman/5.6/en/binary-installation.html

贴出安装步骤:

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> scripts/mysql_install_db --user=mysql
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

坑1:在执行 scripts/mysql_install_db 脚本时出错:

-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory

    原因:这是因为没有装perl。

    解决方法:

yum install perl

    安装完以后继续 scripts/mysql_install_db

    还是报错:

FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
Data::Dumper

    原因:缺少Data:Dumper模块 

    解决方法:yum -y install autoconf //此包安装时会安装Data:Dumper模块 

    安装完以后继续 scripts/mysql_install_db

    还是报错:

linux libaio.so.1: cannot open shared object file: No such file or directory

    原因:缺少安装包libaio和libaio-devel.

    解决方法:yum install libaio*

    安装完以后继续 scripts/mysql_install_db

    安装成功!一下是安装完成后的提示:

2018-08-30 23:56:35 14859 [Note] InnoDB: Starting shutdown...
2018-08-30 23:56:36 14859 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h jade-server1 password 'new-password'

Alternatively you can run:

  ./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

 大公司大产品就是人性化!安装完以后的提示彻底体现了这一点,翻译成中文就是:

 如果你想让你安装的MySQL随着系统开机启动,那么请把安装目录下的support-files/mysql.server文件拷贝 
 到你的系统的合适的位置,因系统而异。

 记得给你的MySQL的root用户设置密码!方法是启动server,然后执行如下命令:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h jade-server1 password 'new-password'
另外,你还可以通过以下方式来进行安全安装:

./bin/mysql_secure_installation

这种安全安装的方式可以使得你安装以后的MySQL中不会默认创建test库和anonymous这个匿名用户,
这一点,对于生产用的服务器来说,是强烈推荐的!

你还可以阅读以下更多的说明:

你可以通过以下命令来启动MySQL实例

  cd . ; ./bin/mysqld_safe &

你可以通过mysql-test-run.pl来测试MySQL:

  cd mysql-test ; perl mysql-test-run.pl

如果你有任何问题请报告给:http://bugs.mysql.com/

最新版本的MySQL信息都在我们的官网:

  http://www.mysql.com

想要得到MySQL的相关技术支持,请去这里购买技术支持证书:http://shop.mysql.com

警告:在当前系统中发现了已经存在的MySQL配置文件:./my.cnf。

      因为这个文件有可能是在使用中,所以本次安装没有强制把它替换(覆盖)掉。

      但是这个配置文件会在下次MySQL的启动中被使用而生效。除非你用--defaults-file

      参数强制指明了要使用默认的配置文件。

      本次安装产生的新的配置文件被创建在这里:安装目录下的./my-new.cnf

      请把它和你已经存在的配置文件进行比较,如果有必要的话请做出你自己的修改。


警告:默认的配置文件/etc/my.cnf已经存在

     这个文件会在下次MySQL server启动时被使用。

     如果你不希望使用这个已有配置文件,请把它移走,

     或者带参数--defaults-file运行mysqld_safe来启动server。

  提示真的很重要:很多我关心的事情就在里面。因此成功安装以后还需要修改配置并启动server。

  首先,选择并修改配置文件my.cnf。

  直接备份/etc/my.cnf为/etc/my.cnf.bak,然后把 /usr/local/my.cnf 拷贝到 /etc/my.cnf。(经过对比,/etc/my.cnf 和 /etc/my-              new.cnf相同)

  先试试能不能用默认的配置文件成功启动server:

[root@jade-server1 bin]# ./mysqld_safe &
[1] 15429
[root@jade-server1 bin]# 180831 00:57:38 mysqld_safe Logging to '/usr/local/mysql/data/jade-server1.err'.
180831 00:57:38 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
180831 00:57:39 mysqld_safe mysqld from pid file /usr/local/mysql/data/jade-server1.pid ended

 果不其然,进程终止了!我就知道会这样。查日志,没有。。。因为都没有配置日志目录呢。索性直接换回系统之前自带的配置   文件。继续启动,仍然报错,不过这次有提示了:

[root@jade-server1 bin]# ./mysqld_safe &
[1] 15793
[root@jade-server1 bin]# 180831 01:09:08 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory
chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory
chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
180831 01:09:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
./mysqld_safe: line 129: /var/log/mariadb/mariadb.log: No such file or directory
./mysqld_safe: line 166: /var/log/mariadb/mariadb.log: No such file or directory
touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory
chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
180831 01:09:08 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
./mysqld_safe: line 129: /var/log/mariadb/mariadb.log: No such file or directory

 文件路径不存在,又经过一番折腾,把/etc/my.cnf中这两项配置的目录路径确保存在,不存在则创建,然后把/var/run/mariadb目录的用户和用户 组改为mysql,否则没有权限访问。

  log-error=/var/log/mariadb/mariadb.log
  pid-file=/var/run/mariadb/mariadb.pid

chown -R mysql:mysql mariadb

 再次运行server

[root@jade-server1 bin]# ./mysqld_safe &
[1] 16349
[root@jade-server1 bin]# 180831 01:17:30 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
180831 01:17:30 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
^C

启动成功,直至 Ctrl+C 强制退出。

赶紧查看端口(默认3306):

[root@jade-server1 bin]# netstat -ano | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      off (0.00/0/0)

成功监听!OK!

其次,通过本地root用户直接连本地server看是否可以使用MySQL。命令:./mysql -h127.0.0.1 -uroot -p

[root@jade-server1 bin]# ./mysql -h127.0.0.1 -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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.

OK!root用户成功登陆连接MySQL server。

最后,设置开机启动。

先写个自己的启动脚本:jade-start.sh  位置任意:如:/root/jade-scripts 内容如下:

#/bin/bash
mkdir /var/run/mariadb
chown -R mysql:mysql /var/run/mariadb
/usr/local/mysql/bin/mysqld_safe &

然后编辑/etc/rc.d/rc.local (需要保证rc.local具有执行权限),最后一行加入:/root/jade-scripts/jade-start.sh

如下:

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
sh /virt/swfix.sh
/root/jade-scripts/jade-start.sh

重启机器验证,3306端口正在被监听。至此,所有工作结束。

下次再安装MySQL,只需要看此文即可。

猜你喜欢

转载自blog.csdn.net/crazy22222/article/details/82251975