# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr-152
# make -j 4 && make install
2.编译安装apr-util
# tar xf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util-154 --with-apr=/usr/local/apr-152
# make -j 4 && make install
3.编译安装httpd
# tar xf httpd-2.4.27.tar.gz
# cd httpd-2.4.27
# ./configure --prefix=/usr/local/apache-2427 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-apr=/usr/local/apr-152 --with-apr-util=/usr/local/apr-util-154 --with-zlib --with-mpm=event --with-pcre
# make -j 4 && make install
4.安装后的收尾工作:
1) 导出二进制文件:
创建/etc/profile.d/httpd24.sh
export PATH=/usr/local/apache-2427/bin:$PATH
创建此文件后,使用source命令(.)来使其内容生效;
2) 导出帮助文档:
编辑/etc/man.config
在任意位置添加一条配置指令:
MANPATH /usr/local/apache-2427/man
3) 导出头文件:
# ln -sv /usr/local/apache-2427/include/ /usr/include/httpd
5.配置工作:
/etc/httpd24/httpd.conf
PidFile /var/run/httpd24.pid
6.提供sysv风格的服务管理脚本:/etc/init.d/httpd
#!/bin/bash
#
#
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd24 ]; then
. /etc/sysconfig/httpd24
fi
HTTPD_LANG=${HTTPD_LANG-"C"}
INITLOG_ARGS=""
apachectl=/usr/local/apache-2427/bin/apachectl
httpd=${HTTPD-/usr/local/apache-2427/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd24.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
上述脚本创建之后,需要完成下列操作:
# chmod +x /etc/init.d/httpd
# chkconfig --add httpd
# chkconfig httpd on
二、使用通用二进制格式的MariaDB包安装MariaDB:
1.解压缩二进制程序包到指定目录(/usr/local)
# tar xf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local
2.创建用于启动服务和管理数据的用户和组:
# groupadd -r -g 306 mysql
# useradd -r -u 306 -g mysql mysql
3.创建数据目录并修改相应文件的权限:
# mkdir -pv /mydata/data
# chown mysql. /mydata/data
# ln -sv /usr/local/mariadb-5.5.57-linux-x86_64 /usr/local/mysql
# cd /usr/local/mysql
# chown -R mysql. .
# cp support-files/my-large.cnf /etc/my.cnf
datadir = /mydata/data
innodb_file_per_table = ON
skip_name_resolve = ON
# cp support-files/mysql.server /etc/init.d/mysqld
4.导出二进制文件:
# vim /etc/profile.d/mariadb5557.sh
export PATH=/usr/local/mysql/bin:$PATH
5.导出帮助文档:
# vim /etc/man.config
MANPATH=/usr/local/mysql/man
6.导出头文件:
# ln -sv /usr/local/mysql/include /usr/include/mysql
7.导出库文件:
# vim /etc/ld.so.conf.d/mariadb5557.conf
/usr/local/mysql/lib
# ldconfig [-v]
8.初始化数据库:
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
9.启动服务并设置随机自动启动:
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld start
10.检查服务启动状态:
# service mysqld status
# ss -tnl
# netstat -ntl
三、编译安装php-5.6.31
想要正确的编译php-5.6.31,可能需要解决下列依赖关系:
libxml2-devel gd-devel freetype-devel libmcrypt-devel
# yum install libxml2-devel freetype-devel libmcrypt-devel
# yum install gd-devel-2.0.35-11.el6.x86_64.rpm
注意:gd-devel-2.0.35-11.el6.x86_64.rpm在DVD2光盘镜像中,可以拷贝出来,再挂载DVD1光盘镜像,完成安装;
编译安装:
# tar xf php-5.6.31.tar.gz
# cd php-5.6.31
# ./configure --prefix=/usr/local/php56 --enable-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-libxml-dir=/usr --with-zlib --with-apxs2=/usr/local/apache-2427/bin/apxs --with-config-file-path=/etc/php56.ini --with-config-file-scan-dir=/etc/php56.d --with-gd --with-jpeg-dir --with-png-dir --with-mcrypt
# make -j 4 && make install
安装后操作:
1.提供配置文件:
# cp php.ini-production /etc/php56.ini
# mkdir /etc/php56.d
# cp sapi/fpm/php-fpm.conf /etc/php56.d
# vim /etc/php56.d/php-fpm.conf
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
[www]
user = nobody
group = nobody
listen = 127.0.0.1:9000
;listen.backlog = 65535
;listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
;pm.max_requests = 500
;pm.status_path = /fpm-status
;pid = /usr/local/php56/var/run/php-fpm.pid
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php56/session
注意:最后两条语句需要手动添加至配置文件中;并且要创建出该目录且授权:
# mkdir -pv /var/lib/php56/session
# chown nobody. /var/lib/php56/session
2.为php-fpm服务程序提供一个sysv风格的脚本:
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
3.修改服务启动脚本中的内容:
1) 添加一个变量:
scan_confi_dir=/etc/php56.d
2) 修改一个变量定义:
php_fpm_CONF=${prefix}/etc/php-fpm.conf
改为:
php_fpm_CONF=${scan_conf_dir}/php-fpm.conf
4.启动php-fpm服务进程
# service php-fpm start
5.检查php-fpm进程状态:
# service php-fpm status
# ss -tnl
# netstat -tnl
四、编译安装xcache以加速php访问:
下载xcache的源代码:
http://xcache.lighttpd.net/
编译安装xcache:
# tar xf xcache-3.2.0.tar.gz
# cd xcache-3.2.0
# /usr/local/php56/bin/phpize //生成configure脚本文件
# ./configure --enable-xcache --with-php-config=/usr/local/php56/bin/php-config
# make -j 4 && make install
此步骤结束之后,需要注意xcache.so模块的安装路径;
/usr/local/php56/lib/php/extensions/no-debug-zts-20131226/
为xcache提供配置文件:
# cp xcache.ini /etc/php56.d
# vim /etc/php56.d/xcache.ini
extension = xcache.so
修改为:
extension = /usr/local/php56/lib/php/extensions/no-debug-zts-20131226/xcache.so
重启php-fpm服务进程:
# service php-fpm restart
补充材料:编译源代码的方式安装MariaDB
在RHEL/CentOS上编译MySQL/MariaDB源端需要用到cmake项目管理工具来实现;
cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台编译。
安装cmake
跨平台编译器
CentOS 6 编译安装mariadb-5.5
编译安装mariadb-5.5.46
1、使用cmake编译mariadb-5.5要点:
cmake指定编译选项的方式不同于make,其实现方式对比如下:
./configure cmake .
./configure --help cmake . -LH or ccmake .
指定安装文件的安装路径时常用的选项:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/data/mysql
-DSYSCONFDIR=/etc
默认编译的存储引擎包括:csv、myisam、myisammrg和heap。若要安装其它存储引擎,可以使用类似如下编译选项:
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
若要明确指定不编译某存储引擎,可以使用类似如下的选项:
-DWITHOUT_<ENGINE>_STORAGE_ENGINE=1
比如:
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
如若要编译进其它功能,如SSL等,则可使用类似如下选项来实现编译时使用某库或不使用某库:
-DWITH_READLINE=1
-DWITH_SSL=system
-DWITH_ZLIB=system
-DWITH_LIBWRAP=0
其它常用的选项:
-DMYSQL_TCP_PORT=3306
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DENABLED_LOCAL_INFILE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_DEBUG=0
-DENABLE_PROFILING=1
如果想清理此前的编译所生成的文件,则需要使用如下命令:
make clean
rm CMakeCache.txt
2、编译安装
# useradd -u 306 -g mysql -r -d /mydata/data mysql
# tar xf mariadb-5.5.46.tar.gz
# cd mariadb-5.5.46
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb-5.5.46 -DMYSQL_DATADIR=/mydata/data -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=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
# make -j #
# make install
安装之后的配置:
# cd /usr/local/mysql
# chown -R :mysql .
# scripts/mysql_install_db --user=mysql --datadir=/data/mydata
# cp support-files/my-large.cnf /etc/my.cnf
修改/etc/my.cnf,在其中添加datadir = /data/mydata (良心建议添加此行)
# cp support-files/mysql.server /etc/init.d/mysql
# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
CentOS 7编译安装MariaDB要点:
yum groupinstall "Development Tools" "Server Platform Development"
yum install ncurses-devel openssl-devel libevent-devel jemalloc-devel cmake
systemd service unit file
#
[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target
#
[Service]
Type=simple
User=mysql
Group=mysql
#
ExecStart=/usr/local/mysql/bin/mysqld_safe --basedir=/usr/local/mysql
#
TimeoutSec=300
#
PrivateTmp=false
#
[Install]
WantedBy=multi-user.target
原文地址:http://blog.51cto.com/13487800/2127024