设为首页 收藏本站
查看: 1520|回复: 0

CentOS 6.0(X64)下编译安装LNMP平台( Nginx1.0.10 + PHP5.3.8 + Mysql5.5.18 )

[复制链接]

尚未签到

发表于 2015-8-21 13:57:18 | 显示全部楼层 |阅读模式
  一、CentOS 6安装
  1.1 使用VMware 虚拟机进行安装,进行安装界面
  (分配内存必须大于1G,否则不会显示图型安装界面,网络设置使用“桥接模式” 即"Bridged"模式)
  1.2 选择 Install or upgrade an existing system
  1.3 在"Disc found" 框 选择 "skip"
  1.4 next 选择 "chinese(simplified)(中文(简介 ))  next
  1.5 选择 "美国英语式"  下一步
  1.6 选择 "基本 存储设备" 下一步
  1.7 弹出"警告"框时,选择"重新初始化所有"
  1.8 主机名可以保留默认,点击”配置网络“ 弹出“网络连接” 双击“System eth0"
  1.9 弹出“正在编辑 System eth0" 选择"自动连接" 点击"应用“ ,点击”关闭“ 关闭”网络连接“框 下一步
  1.10 不要选择“系统时钟使用UTC时间” 下一步
  1.11 输入并确认 ”根密码“ 下一步
  1.12 选择"替换现有Linux系统 "  下一步 “将修改写入磁盘"
  1.13 选择"Basic Server"  下一步
  1.14 大概一共590个软件包,复制安装完成后,点击“重新引导”,重新启动计算机
  1.15 (安装完成后,可以将虚拟机内存由1G,改为512M)
  
  二、更新centos6
  2.1 更新
  yum update -y
  2.2 查看版本,确认为"CentOS Linux release 6.0 (Final)"
  lsb_release -a
  2.2 安装编译器
  yum install -y gcc gcc-c++
  
  三、安装Google-perftools (使用tcmalloc 加速 mysql 和 nginx)
  3.1下载需要的文件
  下载 libunwind-1.0.1.tar.gz 到 /usr/local/src
  3.2 安装libunwind
  cd /usr/local/src/
  tar zvxf libunwind-1.0.1.tar.gz
  cd libunwind-1.0.1
  ./configure --enable-shared
  make && make install
  3.3  安装google-perftools
  cd /usr/local/src/
  tar zvxf google-perftools-1.8.3.tar.gz
  cd google-perftools-1.8.3
  ./configure --enable-shared --enable-frame-pointers
  make && make install
  3.4 更新,使动态链接库能够被系统共享
  echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
  ldconfig
  
  四、安装mysql
  4.1.下载文件
  下载 ncurses-5.9.tar.gz到/usr/local/src
下载 bison-2.5.tar.gz到/usr/local/src
下载 cmake-2.8.6.tar.gz到/usr/local/src
下载 mysql-5.5.18.tar.gz到/usr/local/src
  4.2 安装ncurses
  yum install ncurses-devel -y
  cd /usr/local/src/
  tar zvxf ncurses-5.9
  ./configure
  make && make install
  4.3 安装cmake
  cd /usr/local/src/
  tar zvxf cmake-2.8.6.tar.gz
  cd cmake-2.8.6
  ./bootstrap
  make && make install
  4.4 安装bison
  cd /usr/local/src/
  tar zvxf bison-2.5.tar.gz
  cd bison-2.5
  ./configure
  make && make install
  4.5 创建mysql需要的目录、配置用户和用户组
  groupadd mysql
  useradd -g mysql mysql
  mkdir -p /data/mysql
  chown -R mysql:mysql /data/mysql
  4.6.安装mysql (需要 cmake ncurses-devel bison 库)
  4.6.1 安装
  cd /usr/local/src/
  tar zvxf mysql-5.5.18.tar.gz
  cd mysql-5.5.18
  cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/data/mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc/ -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=on
  make && make install
  4.6.2 创建软连接
  ln -s /opt/mysql/lib/lib* /usr/lib/
  4.6.3 配置mysql数据库
  cd /opt/mysql
./scripts/mysql_install_db --basedir=/opt/mysql/ --datadir=/data/mysql/ --user=mysql
  4.6.4 复制配置文件
  cp ./support-files/my-large.cnf /etc/my.cnf
  4.6.5 修改配置文件,设置默认使用utf8编码
  vim /etc/my.cnf
在[client]下添加一行
default-character-set = utf8
在[mysqld]下添加一行
character-set-server = utf8
  4.6.6 设置mysql开机自动启动服务
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
  4.6.7 修改服务配置文件
vim /etc/rc.d/init.d/mysqld
  根据设定需要,修改mysqld文件中的下面两项
basedir=/opt/mysql
datadir=/data/mysql
  4.6.8 启动mysqld服务
service mysqld start
4.6.9 数据库初始化及修改root密码(root初始密码为空)
./bin/mysql_secure_installation
根据提示操作
  4.6.10 软连接mysql
  ln -s /opt/mysql/bin/mysql /bin 
  4.6.11 重启centos后,尝试用root连接mysql
mysql -u root -p
  成功登录后查看状态
  status;
  4.6.12 使用tcmalloc优化mysql ( 需要安装google-perftools)
  修改MySQL启动脚本(根据你的MySQL安装位置而定)
vim /opt/mysql/bin/mysqld_safe
  在# executing mysqld_safe的下一行,加上:
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
  4.6.13 重启服务,查看tcmalloc是否生效 (第二条命令显示即生效)
  service mysqld restart
  lsof -n | grep tcmalloc
  如果显示以下类似的信息,即表示tcmalloc生效
  [iyunv@localhost mysql]# lsof -n|grep tcmalloc
mysqld    30347     mysql  mem       REG              253,0  2177570     544322 /usr/local/lib/libtcmalloc.so.0.2.2
  
  五、安装Nginx
  5.1.准备安装
  下载 pcre-8.20.tar.gz到/usr/local/src
  下载 nginx-1.0.10.tar.gz到/usr/local/src
  5.2 更新包
  yum install zlib* openssl* -y
  
  5.3 安装Pcre
  cd /usr/local/src/
  tar zvxf pcre-8.20.tar.gz
  cd pcre-8.20
  ./configure
  make && make install
  5.4 创建www用户和组,创建www虚拟主机使用的目录,以及Nginx使用的日志目录,并且赋予他们适当的权限
  groupadd www
useradd -g www www
  mkdir -p /data/www
chmod +w /data/www
chown -R www:www /data/www
  为tcmalloc添加目录,并且赋予适当权限
  mkdir -p /tmp/tcmalloc/
  chown -R www:www /tmp/tcmalloc/
  
  5.1 安装Nginx (需要 pcre google-perftools 库)
  5.5.1 安装
  cd /usr/local/src/
  tar zvxf nginx-1.0.10.tar.gz
  伪装服务器信息(可以不修改)
  cd nginx-1.0.10/src/core
  vim ./src/core/nginx.h
  修改NGINX_VERSION为你希望显示的版号
  修改NGINX_VER为你希望显示的名称
  修改NGINX_VAR 为你希望显示的名称
  保存
  开始安装
  ./configure --user=www --group=www --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module --with-google_perftools_module
  make && make install
  5.4.2 修改 nginx.conf ,令nginx可以 google-perftools实现加速
  vim /opt/nginx/conf/nginx.conf
  修改前面几行为:
  user www www;
worker_processes 8;
error_log logs/error.log crit;
pid logs/nginx.pid;
google_perftools_profiles /tmp/tcmalloc/;
events{
  use epoll;
  worker_connections 65535;
}
  
  5.4.3 测试和运行
  cd /opt/nginx
  ./sbin/nginx -t
  如果显示下面信息,即表示配置没问题
  nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
  输入代码运行nginx服务
  ./sbin/nginx
  ps au|grep nginx
  如果显以类似下面的信息,即表示nginx已经启动
  root      2013  0.0  0.0 103156   856 pts/0    S+   03:22   0:00 grep nginx
  输入代码检测是否支持加速
  lsof -n | grep tcmalloc
  如果显示类似下面的信息,即表示支持tcmalloc加速 (mysqld和nginx两个线程都支持)
  mysqld    20818    mysql  mem       REG              253,0  2177570     281050 /usr/local/lib/libtcmalloc.so.0.2.2
  nginx     29454       www   25w      REG              253,0        0     288399 /tmp/tcmalloc/.29454
  nginx     29455       www   27w      REG              253,0        0     288403 /tmp/tcmalloc/.29455
  
  5.5.4 打开防火墙80端口
  写入规则,保存并重启服务
  iptables -I INPUT -p tcp --dport 80 -j ACCEPT
  /etc/rc.d/init.d/iptables save
  /etc/init.d/iptables restart
  查看防火墙信息
/etc/init.d/iptables status
  如果显示以下类似信息,即表示已经打开了80端口
  1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
  5.5.5 编写nginx 启动服务
  cd /etc/init.d
  vim nginx
  输入以下代码并保存
  #!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:    - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#                proxy and IMAP/POP3 proxy server
# processname: nginx
# config:       /etc/nginx/nginx.conf
# config:       /etc/sysconfig/nginx
# pidfile:      /var/run/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/opt/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

start() {
     [ -x $nginx ] || exit 5
     [ -f $NGINX_CONF_FILE ] || exit 6
     echo -n $"Starting $prog: "
     daemon $nginx -c $NGINX_CONF_FILE
     retval=$?
     echo
     [ $retval -eq 0 ] && touch $lockfile
     return $retval
}

stop() {
     echo -n $"Stopping $prog: "
     killproc $prog -QUIT
     retval=$?
     echo
     [ $retval -eq 0 ] && rm -f $lockfile
     return $retval
killall -9 nginx
}

restart() {
     configtest || return $?
     stop
     sleep 1
     start
}

reload() {
     configtest || return $?
     echo -n $"Reloading $prog: "
     killproc $nginx -HUP
RETVAL=$?
     echo
}

force_reload() {
     restart
}

configtest() {
$nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
     status $prog
}

rh_status_q() {
     rh_status >/dev/null 2>&1
}

case "$1" in
     start)
         rh_status_q && exit 0
     $1
         ;;
     stop)
         rh_status_q || exit 0
         $1
         ;;
     restart|configtest)
         $1
         ;;
     reload)
         rh_status_q || exit 7
         $1
         ;;
     force-reload)
         force_reload
         ;;
     status)
         rh_status
         ;;
     condrestart|try-restart)
         rh_status_q || exit 0
             ;;
     *)     
       echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
         exit 2
esac

  
  保存后,设置权限,并添加到启动服务列表中
  chmod 755 /etc/init.d/nginx
  chkconfig --add nginx
  chkconfig --level 345 nginx on

  service nginx start
  
  
  六、安装PHP
  6.1 准备安装
  下载php-5.3.6.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
下载libmcrypt-2.5.8.tar.gz到/usr/local/src
  yum -y 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-developenssl openssl-devel openldap openldap-devel nss_ldap openldap-clientsopenldap-servers libXpm* gcc gcc-c++

  5.2 安装libiconv (加强系统对支持字符编码转换的功能)
  cd /usr/local/src/
  tar zvxf libiconv-1.14.tar.gz
  cd libiconv-1.14
  ./configure --prefix=/usr/local
  make && make install

  5.3 安装libmcrypt(加密算法库,PHP扩展mcrypt功能对此库有依耐关系,要使用mcrypt必须先安装此库)
  5.3.1 安装libmcrypt
  cd /usr/local/src/
  tar zvxf libmcrypt-2.5.8.tar.gz
  cd libmcrypt-2.5.8
  ./configure
  make && make install
  5.3.2安装libltdl
  cd libltdl/
  ./configure --enable-ltdl-install
  make && make install
  5.3.3 更新共享
  ln -sf /usr/local/lib/libmcrypt.* /usr/lib64/
ln -sf /usr/local/bin/libmcrypt-config /usr/lib64/
ln -sf /usr/local/lib/libiconv.so.2 /usr/lib64/
  ldconfig
  5.4 安装mhash(hash加密算法库)
  5.4.1 安装mhash
  cd /usr/local/src/
  tar zvxf mhash-0.9.9.9.tar.gz
  cd mhash-0.9.9.9
  ./configure
  make && make install
  5.4.2更新共享
  ln -sf /usr/local/lib/libmhash.* /usr/lib64/
  ldconfig
  5.5 安装mcrypt
  cd /usr/local/src/
  tar zvxf mcrypt-2.6.8.tar.gz
  cd mcrypt-2.6.8
  ldconfig
  ./configure
  make && make install

  5.6 安装php
  5.6.1 创建mysql软连接、ldap软连接

  mkdir -p /opt/mysql/include/mysql
ln -s /opt/mysql/include/* /opt/mysql/include/mysql/
ln -s /usr/lib64/libldap* /usr/lib

  5.6.2 安装
  cd /usr/local/src/
  tar zvxf php-5.3.8.tar.gz
  cd php-5.3.8
  ./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 --disable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --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
  make ZEND_EXTRA_LIBS='-liconv'
  make install
5.6.3 复制配置文件
  cp php.ini-production /opt/php/etc/php.ini
  5.6.4 安装memcache扩展(已经安装PHP)
  cd /usr/local/src/
  tar zvxf memcache-2.2.6.tar.gz
  cd memcache-2.2.6
  /opt/php/bin/phpize
  ldconfig
  ./configure --with-php-config=/opt/php/bin/php-config
  make && make install
  修改php配置文件,支持memcache
  vim /opt/php/etc/php.ini
  在文件中搜索extension_dir、extension ,在相应位置添加下面两行
extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20090626/"
extension = "memcache.so"
  5.6.5 安装eaccelerator扩展(已经安装PHP)
  cd /usr/local/src/
  tar jxvf eaccelerator-0.9.6.1.tar.bz2
  cd eaccelerator-0.9.6.1

  /opt/php/bin/phpize
  ./configure --enable-eaccelerator=shared --with-php-config=/opt/php/bin/php-config
  make && make install
  修改php配置文件,支持eaccelerator
  vim /opt/php/etc/php.ini
  在文件尾加入以下代码
  [eaccelerator]
zend_extension="/opt/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.log_file = "/opt/php/var/log/eaccelerator_log"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

  增加eaccelerator目录
mkdir -p /tmp/eaccelerator
  
5.6.5 安装php-fpm
  cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
vim /opt/php/etc/php-fpm.conf
修改以下地方
[global]
pid = run/php-fpm.pid-p
error_log = log/php-fpm.log
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 5s
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_children = 35
[www]
user = www
group = www
  5.6.6 修改nginx,支持php
  vim /opt/nginx/conf/nginx.conf
  找到并修改以下代码
  location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /data/www$fastcgi_script_name;
            include        fastcgi_params;
        }
  
  5.6.7将php-fpm 作为服务运行
  cd  /usr/local/src/php-5.3.8
cp ./sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm
chmod 700 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --level 345 php-fpm on
服务方式启动php-fpm
service php-fpm restart
  
  5.6.8 编写测试页面
  vim /data/www/index.php
  输入代码
  <html>
  <head><title>hello php</title></head>
  <body>
    <?php phpinfo();?>
  </body>
</html>

  5.6.8 打开浏览器进行测试

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-102235-1-1.html 上篇帖子: [LTMP搭建] CentOS 6.5 编译安装lnmp的准备工作 下篇帖子: lnmp监控----nagios
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表