集群09-分离php和mysql安装部署lamp环境(在不同服务器上编译安装)
一、mysql服务器安装(ip:176.16.1.7)
1、下载mysql安装包wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.18.tar.gz
wget http://jaist.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
2、安装编译工具与插件
yum -y install gcc gcc-c++ make pcre-devel expat-devel perl ncurses ncurses-devel openssl* bison cmake
3、安装mysql
mkdir /usr/local/mysql
mkdir -p /data/mysqldata
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
chown -R mysql.mysql /data/mysqldata/
chown -R mysql.mysql mysql/
# 如果在CMAKE的过程中有报错,当报错解决后,需要把源码目录中的
#CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧)
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysqldata \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_BOOST=/usr/local/src/boost
make && make install
vim /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysqldata
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,
NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
chown mysql.mysql /etc/my.cnf
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
cd /usr/local/mysql/bin/
mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/data/mysqldata \
--explicit_defaults_for_timestamp=true
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysqld
添加:
chkconfig: 36 86 22
description: Mysql database
chkconfig --add mysqld
chkconfig mysqld on
chkconfig --list mysqld
grant all privileges on *.* to 'root'@'%'identified by '000000' with grant option;
flush privileges;
二、安装apache和php(ip:172.16.1.8)
1、安装apache(省略)
2、安装php(省略)
3、关联apache和php(省略)
4、安装mysql-devel(或者mariadb-devel)
5、编译安装mysql.so
cd /usr/local/src/php-5.6.35/ext/mysql/
/usr/local/php5/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql
make && make install
生成如下内容:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
为了方便,把.so文件集中放置:
mv /usr/local/php5/lib/php/extensions/no-debug-non-zts-20121212/mysql.so /usr/local/php5/lib/php/extensions/
修改php.ini文件:
找到 ;extension_dir = “./”这一行,去掉注释,并修改路径。
extension_dir = "/usr/local/php5/lib/php/extensions/"
extension=mysql.so