环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso
1.准备
1.1 显示系统版本
[root@centos ~]# yum install vim wget lsof gcc gcc-c++ bzip2 -y [root@centos ~]# yum install net-tools bind-utils -y
[root@centos ~]# ifconfig|grep inet inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
[root@centos ~]# vim /etc/selinux/config 屏蔽以下两行 #SELINUX=enforcing #SELINUXTYPE=targeted 添加以下一行 SELINUXTYPE=disabled 保存,退出
[root@centos ~]# shutdown -r now [root@centos ~]# getenforce Disabled
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf cmake-3.0.0.tar.gz [root@centos ~]# cd cmake-3.0.0 [root@centos ~]# ./bootstrap [root@centos ~]# make && make install
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf bison-3.0.tar.gz [root@centos ~]# cd bison-3.0 [root@centos ~]# ./configure [root@centos ~]# make && make install
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar xjf jemalloc-3.6.0.tar.bz2 [root@centos ~]# cd jemalloc-3.6.0 [root@centos ~]# ./configure [root@centos ~]# make && make install [root@centos ~]# echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf [root@centos ~]# ldconfig
[root@centos ~]# groupadd mysql [root@centos ~]# useradd -g mysql mysql -s /sbin/nologin [root@centos ~]# mkdir -p /data/mysql [root@centos ~]# chown -R mysql:mysql /data/mysql
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf mariadb-10.0.15.tar.gz [root@centos ~]# cd mariadb-10.0.15 [root@centos ~]# cmake -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_EXTRA_CHARSETS=all -DEXTRA_CHARSETS=all -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all
# 编译说明
[root@centos ~]# make install
[root@centos ~]# ln -s /opt/mysql/lib/lib* /usr/lib/ [root@centos ~]# ln -s /opt/mysql/bin/mysql /bin
[root@centos ~]# cd /opt/mysql [root@centos ~]# cp ./support-files/my-large.cnf /etc/my.cnf [root@centos ~]# vim /etc/my.cnf
在[client]下添加一行
在[mysqld]下添加一行 保存退出
[root@centos ~]# cp /usr/local/src/mariadb-10.0.15/packaging/rpm-oel/mysql-systemd-start /opt/mysql/bin/ [root@centos ~]# chmod 755 /opt/mysql/bin/mysql-systemd-start [root@centos ~]# vim ./bin/mysql-systemd-start
找到以下内容
保存退出 2.10 设置mysql开机自动启动服务
[root@centos ~]# systemctl enable mysqld.service [root@centos ~]# systemctl list-unit-files|grep enabled|grep mysql [root@centos ~]# vim /etc/systemd/system/mysql.service
找到以下内容
修改为
保存退出
[root@centos ~]# systemctl start mysqld.service [root@centos ~]# systemctl status mysqld.service -l [root@centos ~]# ps -ef|grep mysqld [root@centos ~]# lsof -n | grep jemalloc
2.12 数据库初始化、登录客户端 [root@centos ~]# cd /opt/mysql [root@centos ~]# ./bin/mysql_secure_installation 根据提示设置数据密码,及其它设置 [root@centos ~]# mysql -u root -p Mysql [(none)]>status; Mysql [(none)]>show engines; Mysql [(none)]>exit;
2.13 增加远程访问用户,并且打开防火墙3306端口(不远程连接数据,可省略) [root@centos ~]# mysql -u root -p Mysql [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; Mysql [(none)]> FLUSH PRIVILEGES; Mysql [(none)]> exit; (root是用户名,%是主机名或IP地址,这里的%代表任意主机或IP地址,也可指定唯一的IP地址;密码是MyPassword )
[root@centos ~]# iptables -L|grep ACCEPT [root@centos ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent [root@centos ~]# firewall-cmd --reload [root@centos ~]# iptables -L|grep ACCEPT
3.编译安装Nginx
3.1 下载包 [root@centos ~]# wget http://nginx.org/download/nginx-1.6.2.tar.gz [root@centos ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz [root@centos ~]# wget http://zlib.net/zlib-1.2.8.tar.gz [root@centos ~]# wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz [root@centos ~]# wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
3.3 安装Pcre [root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf pcre-8.36.tar.gz [root@centos ~]# cd pcre-8.36 [root@centos ~]# ./configure [root@centos ~]# make && make install
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf openssl-1.0.1j.tar.gz [root@centos ~]# cd openssl-1.0.1j [root@centos ~]# ./config [root@centos ~]# make && make install
3.5 安装zlib [root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf zlib-1.2.8.tar.gz [root@centos ~]# cd zlib-1.2.8 [root@centos ~]# ./configure [root@centos ~]# make && make install 3.6 创建www用户和组,创建www虚拟主机使用的目录,以及Nginx使用的日志目录,并且赋予他们适当的权限 [root@centos ~]# groupadd www [root@centos ~]# useradd -g www www -s /sbin/nologin [root@centos ~]# mkdir -p /data/www [root@centos ~]# chmod +w /data/www [root@centos ~]# chown -R www:www /data/www ***如果没法创建用户,需要检查SELinux状态是否关闭
3.7 安装nginx [root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf nginx-1.6.2.tar.gz [root@centos ~]# cd nginx-1.6.2 [root@centos ~]# ./configure --prefix=/opt/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36 --with-ld-opt="-ljemalloc" [root@centos ~]# make && make install
[root@centos ~]# vim /opt/nginx/conf/nginx.conf 修改前面几行为: user www www; worker_processes auto; error_log logs/error.log crit; pid logs/nginx.pid;
events{
[root@centos ~]# vim /data/www/index.html
<html> 保存,退出
[root@centos ~]# cd /opt/nginx [root@centos ~]# ldconfig [root@centos ~]# ./sbin/nginx -c /opt/nginx/conf/nginx.conf -t 如果显示下面信息,即表示配置没问题
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
[root@centos ~]# ./sbin/nginx -c /opt/nginx/conf/nginx.conf [root@centos ~]# lsof -n | grep jemalloc
ginx 2346 root mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
[root@centos ~]# iptables -L|grep ACCEPT [root@centos ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent [root@centos ~]# firewall-cmd --reload [root@centos ~]# iptables -L|grep ACCEPT
3.12 浏览器打开 http://192.168.1.10 显示出欢迎内容,则表示成功
3.13 作为服务,开机后启动 [root@centos ~]# vim /usr/lib/systemd/system/nginx.service 增加以下内容
[Unit]
[Service]
[Install] :wq 保存退出
[root@centos ~]# systemctl list-unit-files|grep enabled|grep nginx
[root@centos ~]# ./sbin/nginx -s stop [root@centos ~]# systemctl daemon-reload [root@centos ~]# systemctl start nginx.service [root@centos ~]# systemctl status nginx.service -l [root@centos ~]# ps -ef|grep nginx [root@centos ~]# lsof -n | grep jemalloc
4 安装PHP 4.1 准备安装 下载 php-5.5.19.tar.gz 到/usr/local/src 下载 libiconv-1.14.tar.gz 到/usr/local/src 下载 libmcrypt-2.5.8.tar.gz 到/usr/local/src 下载 mcrypt-2.6.8.tar.gz 到/usr/local/src 下载 mhash-0.9.9.9.tar.gz 到/usr/local/src 下载 memcache-3.0.8.tar.gz 到/usr/local/src 下载 zendopcache-7.0.3.tgz 到/usr/local/src
yum install autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libXpm* gcc gcc-c++ -y
[root@centos ~]# cd /usr/local/src [root@centos ~]# tar zvxf libiconv-1.14.tar.gz [root@centos ~]# cd libiconv-1.14 [root@centos ~]# ./configure --prefix=/usr/local [root@centos ~]# cd srclib [root@centos ~]# sed -i -e '/gets is a security/d' ./stdio.in.h [root@centos ~]# cd .. [root@centos ~]# make && make install [root@centos ~]# ln -sf /usr/local/lib/libiconv.so.2 /usr/lib64/ [root@centos ~]# ldconfig
4.4 安装libmcrypt,libltdl(加密算法库,PHP扩展mcrypt功能对此库有依耐关系,要使用mcrypt必须先安装此库) [root@centos ~]# cd /usr/local/src [root@centos ~]# tar zvxf libmcrypt-2.5.8.tar.gz [root@centos ~]# cd libmcrypt-2.5.8 [root@centos ~]# ./configure [root@centos ~]# make && make install [root@centos ~]# cd libltdl/ [root@centos ~]# ./configure --enable-ltdl-install [root@centos ~]# make && make install [root@centos ~]# ln -sf /usr/local/lib/libmcrypt.* /usr/lib64/ [root@centos ~]# ln -sf /usr/local/bin/libmcrypt-config /usr/lib64/ [root@centos ~]# ldconfig
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf mhash-0.9.9.9.tar.gz [root@centos ~]# cd mhash-0.9.9.9 [root@centos ~]# ./configure [root@centos ~]# make && make install [root@centos ~]# ln -sf /usr/local/lib/libmhash.* /usr/lib64/ [root@centos ~]# ldconfig 4.6 安装mcrypt [root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf mcrypt-2.6.8.tar.gz [root@centos ~]# cd mcrypt-2.6.8 [root@centos ~]# ./configure [root@centos ~]# make && make install
4.7 安装php (已经安装mariadb,nginx,ldap) 4.7.1 创建mysql软连接、ldap软连接 [root@centos ~]# mkdir -p /opt/mysql/include/mysql [root@centos ~]# ln -s /opt/mysql/include/* /opt/mysql/include/mysql/ [root@centos ~]# ln -s /usr/lib64/libldap* /usr/lib [root@centos ~]# ln -s /usr/lib64/liblber* /usr/lib
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf php-5.5.19.tar.gz [root@centos ~]# cd php-5.5.19 [root@centos ~]# ./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysql=/opt/mysql --with-mysqli=/opt/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap [root@centos ~]# make ZEND_EXTRA_LIBS='-liconv' [root@centos ~]# make install
4.7.3 复制配置文件 [root@centos ~]# cp php.ini-production /opt/php/etc/php.ini
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf memcache-3.0.8.tgz [root@centos ~]# cd memcache-3.0.8 [root@centos ~]# /opt/php/bin/phpize [root@centos ~]# ldconfig [root@centos ~]# ./configure --with-php-config=/opt/php/bin/php-config [root@centos ~]# make && make install
[root@centos ~]# vim /opt/php/etc/php.ini 在文件中搜索; extension_dir = "./" ,并在下面添加以下两行内容
extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20121212/"
4.7.5 安装ZendOpcache扩展(已经安装php) [root@centos ~]# cd /usr/local/src/ [root@centos ~]# tar zvxf zendopcache-7.0.3.tgz [root@centos ~]# cd zendopcache-7.0.3 [root@centos ~]# /opt/php/bin/phpize [root@centos ~]# ./configure --with-php-config=/opt/php/bin/php-config [root@centos ~]# make && make install
[root@centos ~]# vim /opt/php/etc/php.ini 在文件中搜索; extension_dir = "./" ,并在下面添加以下两行内容
zend_extension=/opt/php/lib/php/extensions/no-debug-non-zts-20121212/opcache.so
4.7.6 安装pdo_mysql扩展(已经安装PHP) [root@centos ~]# cd /usr/local/src/ [root@centos ~]# cd php-5.5.19/ext/pdo_mysql/ [root@centos ~]# /opt/php/bin/phpize [root@centos ~]# ./configure --with-php-config=/opt/php/bin/php-config --with-pdo-mysql=/opt/mysql [root@centos ~]# make && make install
[root@centos ~]# vim /opt/php/etc/php.ini 在文件中搜索; extension_dir = "./" ,并在下面添加以下两行内容(如果extension_dir已存在,只添加后面一行) extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20121212/" extension = "pdo_mysql.so"
4.7.7 安装php-fpm [root@centos ~]# cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf [root@centos ~]# vim /opt/php/etc/php-fpm.conf
[global] 保存,退出 # php-fpm.conf 重要参数详解
# pid = run/php-fpm.pid
# error_log = log/php-fpm.log
# log_level = notice
[root@centos ~]# vim /opt/nginx/conf/nginx.conf 找到并修改以下代码
location ~ \.php$ {
[root@centos ~]# cp /usr/local/src/php-5.5.19/sapi/fpm/php-fpm.service /lib/systemd/system/ [root@centos ~]# vim /lib/systemd/system/php-fpm.service 替换所有的${prefix}为/opt/php,${exec_prefix}为/opt/php,最终修改如下
[Unit]
[Service]
[Install] 保存,退出
[root@centos ~]# systemctl list-unit-files|grep enabled|grep php-fpm [root@centos ~]# systemctl daemon-reload [root@centos ~]# systemctl start php-fpm.service [root@centos ~]# systemctl status php-fpm.service -l
[root@centos ~]# vim /data/www/index.php 输入以下内容
<html> 保存,退出 (责任编辑:IT) |