作业题:三台主机编译安装http、php,二进制源码安装mariadb 环境: A主机:192.166.0.161,编译安装httpd B主机:192.166.0.162,编译安装php-fpm C主机:192.166.0.163,二进制格式安装mariadb
三台主机均关闭了firewalld、selinux,软件存放目录均为/root/tools/
一:安装http 安装扩展组件
yum -y groupinstall "开发工具" "服务器平台开发"
yum install -y pcre-devel openssl-devel gcc
安装apr
wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.bz2
tar -jxvf apr-1.5.2.tar.bz2
cd apr-1.5.2/
./configure --prefix=/usr/local/apr
make -j 2 && make install
安装apr-util
null
null
null
null
wget http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
tar -zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make -j 2 && make install
安装 httpd-2.4
wget http://archive.apache.org/dist/httpd/httpd-2.4.23.tar.bz2
tar -jxvf httpd-2.4.23.tar.bz2
cd httpd-2.4.23/
./configure --help // 根据需要选择对应的模块
./configure \
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd \
--enable-so --enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib --with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=event //指定httpd的MPM方式,分别是prefork、event和worker
make -j 2 && make install
设置 开机启动
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
vim /etc/init.d/httpd
添加:
#chkconfig: 2345 70 30 //2345是运行级别,70是启动顺序,30是关闭顺序
chkconfig --add httpd //添加httpd服务
chkconfig --list httpd //查看httpd是否开机启动
添加环境变量:
vim /etc/profile.d/httpd.sh,添加以下内容
export PATH=/usr/local/apache/bin:$PATH
导出头文件
ln -sv /usr/local/apache/include /usr/include/apache
启动httpd服务
systemctl start httpd
systemctl status httpd
修改配置文件
vim /etc/httpd/httpd.conf
注释 #DocumentRoot "/usr/local/apache/htdocs"
并打开启用 include /etc/httpd/conf.d/*.conf
添加 ServerName www.200.com
同时定位 AddType;添加下面两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
并且定位至DirectoryIndex
<IfModule dir_module>
DirectoryIndex index.php index.html #添加index.php(最好添加在最前面)
</IfModule>
还要启用proxy_module proxy-fcgi_module等
LoadModule proxy_module modules/mod_proxy.so #开启
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so #开启
mkdir /etc/httpd/conf.d
vim /etc/httpd/conf.d/vhost.conf
添加两台虚拟主机
<VirtualHost *:80>
ServerAdmin wuqingcong@aliyun.com
ServerName www1.200.com
DocumentRoot '/var/www1'
ErrorLog '/var/log/httpd/www1_error_log'
CustomLog '/var/log/httpd/www1_access_log' combined
ProxyRequests off //关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://192.166.0.162:9000/var/www1/$1
<Directory '/var/www1'>
Options FollowSymLinks
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin wuqingcong@aliyun.com
ServerName www2.200.com
DocumentRoot '/var/www2'
ErrorLog '/var/log/httpd/www2_error_log'
CustomLog '/var/log/httpd/www1_access_log' combined
ProxyRequests off //关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://192.166.0.162:9000/var/www2/$1
<Directory '/var/www2'>
Options FollowSymLinks
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
mkdir -pv /var/www{1,2}
mkdir -pv /var/log/httpd
添加测试文件:
vim /var/www1/index.html
this is www1.200.com
vim /var/www2/index.html
this is www2.200.com
检查语法错误
/usr/local/apache/bin/apachectl -t`
二、安装php ``` yum -y groupinstall "开发工具" "服务器平台开发" yum -y install libxml2-devel libmcrypt-devel gcc tar -jxvf php-5.4.16.tar.bz2 cd php-5.4.16/
./configure
--prefix=/usr/local/php \
--enable-fpm \
--with-mysql=mysqlnd \
--with-openssl \
--with-mysqli=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--with-mcrypt=/usr/local/mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--enable-maintainer-zts
`make -j 2 && make install`
注意:
一、安装gcc 由于是独立的主机 需要配置环境 yum -y install gcc
二、 –with-mysql几个选项都要为mysqlnd;因为mysql服务器单独为另一台主机
三、为了支持apache的worker或event这两个MPM,编译时使用了–enable-maintainer-zts选项
配置php
cp php.ini-production /etc/php.ini
配置fpm
为php-fpm提供Sysv init脚本,并将其添加至服务列表:
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig –add php-fpm
chkconfig php-fpm on
chkconfig –list php-fpm
为php-fpm提供配置文件:
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
编辑php-fpm的配置文件:
vim /usr/local/php/etc/php-fpm.conf
修改配置php-fpm的文件vim /usr/local/php/etc/php-fpm
定位到listen =192.166.0.162:9000
配置fpm的相关选项为你所需要的值:
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
接下来就可以启动php-fpm了:
service php-fpm start
可以使用netstat -tunlp 查看 9000端口
安装Xchache
安装xcache
wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.gz
tar zxvf xcache-3.1.0.tar.gz
cd xcache-3.1.0/
/usr/local/php/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make && make install
/usr/local/php/bin/php -m //查看是否启用xcache,此时并未启用
cp ./xcache.ini /etc/php.d/
mkdir /etc/php.d
cp ./xcache.ini /etc/php.d/
systemctl restart php-fpm
/usr/local/php/bin/php -m
[Zend Modules]
XCache
XCache Cacher //表示已经启用xcache
三、二进制格式安装mariadb
groupadd -r mysql
useradd -r -g mysql mysql
tar -axf mariadb-10.1.13-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -s mariadb-10.1.13-linux-x86_64/ mysql
cd /usr/local/mysql
chown -R root:mysql ./*
mkdir /mydata //备注:数据库存放目录。
chown -R mysql.mysql /mysqldata
cp support-files/mysql.server /etc/init.d/mysqld
ll /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
mv /etc/my.cnf{,.bak}
mkdir /etc/mysql
cp support-files/my-large.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
datadir = /mydata
innodb_file_per_table = on
skip_name_resolve = on
vi /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile.d/mysql.sh
mysql_secure_installation //初始化安全设置
scripts/mysql_install_db --user=mysql --datadir=/mysqldata
mysql -uroot -hlocalhost -p
MariaDB [(none)]> create user 'test'@'192.166.%.%' identified by '123456';
MariaDB [(none)]> create database wordpress_db; //创建WordPress的数据库,为后面wp-config.php里面填入的数据库
MariaDB [(none)]> grant all privileges on *.* to 'test'@'192.166.%.%';
MariaDB [(none)]> grant all privileges on *.* to 'root'@'192.166.%.%'; //运行root用户在远程主机上登陆,即能在PhpMyadmin上登陆root账号
vi /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
ldconfig
ldconfig -p | grep mysql
ln -sv /usr/local/mysql/include/ /usr/include/mysql
四、安装WordPress和PhpMyAdmin
安装WordPress 在httpd主机和php主机上均安装一次,静态资源http主机之间响应,动态资源http服务器发送给php处理后响应
http主机上
unzip wordpress-4.9.1-zh_CN.zip -d /var/www1/
ls /var/www1/
cd /var/www1/
mv wordpress/* ./
cp wp-config-sample.php wp-config.php
vim wp-config.php
// define('DB_NAME', 'database_name_here');
define('DB_NAME', 'wordpress_db');
/** MySQL数据库用户名 */
define('DB_USER', 'test');
/** MySQL数据库密码 */
define('DB_PASSWORD', '123456');
/** MySQL主机 */
define('DB_HOST', '192.166.0.163');
scp wordpress-4.9.1-zh_CN.zip root@192.166.0.162:/root/tools/
在php主机上
unzip wordpress-4.9.1-zh_CN.zip -d /var/www1/
ls /var/www1/
cd /var/www1/
mv wordpress/* ./
cp wp-config-sample.php wp-config.php
vim wp-config.php
// define('DB_NAME', 'database_name_here');
define('DB_NAME', 'wordpress_db');
/** MySQL数据库用户名 */
define('DB_USER', 'test');
/** MySQL数据库密码 */
define('DB_PASSWORD', '123456');
/** MySQL主机 */
define('DB_HOST', '192.166.0.163');
安装PhpMyadmin
在httpd主机和php主机上均安装一次,静态资源http主机之间响应,动态资源http服务器发送给php处理后响应
unzip phpMyAdmin-4.4.14.1-all-languages.zip
mv phpMyAdmin-4.4.14.1-all-languages/* /var/www2/
cd /var/www2/
cp config.sample.inc.php config.inc.php
openssl rand -base64 15 //产生15位随机数
vim config.inc.php
$cfg['blowfish_secret'] = 'cG//9oBhIt/t2rfm6AVW'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '192.166.0.163';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
两台主机安装好后,访问测试,root用户和test用户均能登陆
mariadb二进制包安装详细参考:http://blog.51cto.com/wuqingcong/2059013