博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LANMP On CentOS 6
阅读量:5014 次
发布时间:2019-06-12

本文共 14076 字,大约阅读时间需要 46 分钟。

摘要

——在CentOS6.2-x86_64上安装Apache,Nginx,MySQL,Php

环境:最小化安装系统

yum install lrzsz mlocate.x86_64 wget lsof unzip \setuptool ntsysv \system-config-firewall-base.noarch \system-config-date.noarch system-config-date-docs.noarch \system-config-firewall.noarch system-config-firewall-tui.noarch \system-config-kdump.noarch system-config-keyboard.x86_64 \system-config-kickstart.noarch system-config-language.noarch \system-config-lvm.noarch system-config-network-tui.noarch \system-config-printer.x86_64 system-config-printer-libs.x86_64 \system-config-printer-udev.x86_64 system-config-services.noarch \system-config-services-docs.noarch system-config-users.noarch system-config-users-docs.noarch

预先设置环境变量

export MYSQL_HOME="/usr/local/mysql"export APACHE_HOME="/usr/local/apache2"export NGINX_HOME="/usr/local/nginx"export PHP_HOME="/usr/local/php"export PATH="$PATH:$MYSQL_HOME/bin:$APACHE_HOME/bin:$PHP_HOME/bin:$NGINX_HOME/sbin"

安装MySQL

tar zxf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysqluseradd mysql -s /sbin/nologinmkdir -p /data/mysql/datachown -R mysql:mysql /usr/local/mysql /data/mysql/data---------------------------------------------#可选:ln -s /usr/local/mysql/lib/libmysqlclient.so.16 \/usr/lib/libmysqlclient.so.16

配置启动MySQL

1. 先修改 mysql 的配置 my.cnf

mv /etc/my.cnf /etc/my.cnf.oldvi /etc/my.cnf[mysqld]basedir=/usr/local/mysqldatadir=/data/mysql/datasocket=/tmp/mysql.sockuser=mysqlexplicit_defaults_for_timestamp=trueinnodb_file_per_table=1# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[client]socket=/tmp/mysql.sock

2. mysql 初始化安装

/usr/local/mysql/scripts/mysql_install_db \--basedir=/usr/local/mysql \--datadir=/data/mysql/data \--user=mysql
#for mysql 5.7.x/usr/local/mysql/bin/mysqld --initialize \--user=mysql \--basedir=/usr/local/mysql \--datadir=/data/mysql/data#额外的工作ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_root_password';

3. 将 mysql 加入开机启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldchmod 755 /etc/init.d/mysqldchkconfig --add mysqldchkconfig --level 2 mysqld offchkconfig --level 345 mysqld onvi /etc/init.d/mysqld#查找并修改以下变量内容:basedir=/usr/local/mysqldatadir=/data/mysql/data

4. 启动 mysql

/usr/local/mysql/bin/mysqld_safe &#或者 /etc/init.d/mysqld start#或者 service mysqld start

安装Apache

yum install zlib-devel gcc gcc-c++ pcre.x86_64 pcre-devel.x86_64 pcre-static.x86_64wget http://archive.apache.org/dist/httpd/httpd-2.4.17.tar.gztar zxf httpd-2.4.17.tar.gzwget http://www.us.apache.org/dist//apr/apr-1.5.2.tar.gztar zxf apr-1.5.2.tar.gzcp -r apr-1.5.2 httpd-2.4.17/srclib/aprwget http://www.us.apache.org/dist//apr/apr-util-1.5.4.tar.gztar zxf apr-util-1.5.4.tar.gzcp -r apr-util-1.5.4 httpd-2.4.17/srclib/apr-utilcd httpd-2.4.17./configure --prefix=/usr/local/apache2 \--sysconfdir=/data/httpd/conf \--enable-so \--enable-dav \--enable-module=so \--enable-mods-shared=all \--enable-rewrite \--with-mpm=prefork \--enable-cache \--with-included-apr makemake installcp /usr/local/apache2/bin/apachectl /etc/init.d/httpdvi /etc/init.d/httpd#在 #!/bin/sh 下面添加:# chkconfig: 2345 14 90# description: Activates/Deactivates Apache Web Server#最后,运行chkconfig把Apache添加到系统的启动服务组里面:chkconfig --add httpdchkconfig --level 2 httpd offchkconfig --level 345 httpd on#安装时的--sysconfigdir参数只修改了httpd.conf本身的父文件夹,而httpd.conf内容中的Include指令依然搜索--prefix制定的apache程序目录#解决方法:#在httpd.conf中加入Define extra_conf_parent_path /foo/bar/httpdInclude ${extra_conf_parent_path}/conf/extra/httpd-vhosts.conf

安装PHP

yum install bison 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-devel libidn libidn-devel \openssl openssl-devel openldap openldap-devel openldap-clients \openldap-servers net-snmp net-snmp-devel libevent libevent-develwget http://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gzwget http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gztar -zxf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8./configuremakemake installtar -zxf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9./configuremakemake installwget https://github.com/skvadrik/re2c/releases/download/0.16/re2c-0.16.tar.gztar zxf re2c-0.16.tar.gzcd re2c-0.16./configuremakemake installcd php-5.6.12./configure --prefix=/usr/local/php \--with-apxs2=/usr/local/apache2/bin/apxs \--with-config-file-path=/etc \--with-mysqli=/usr/local/mysql/bin/mysql_config \--with-pdo-mysql=/usr/local/mysql \--with-gd \--with-gettext \--with-iconv \--with-zlib \--with-openssl \--with-curl \--with-freetype-dir=/usr/include/freetype2/freetype/ \--with-bz2 \--with-jpeg-dir \--with-png-dir \--with-mcrypt \--enable-gd-native-ttf \--enable-mbstring \--enable-sockets \--enable-pcntl \--enable-xml \--enable-maintainer-zts  makemake install
若有:Sorry, I cannot run apxs.  Possible reasons follow:1. Perl is not installed2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs3. Apache was not built using --enable-so (the apxs usage page is displayed)The output of /usr/local/apache2/bin/apxs follows:./configure: /usr/local/apache2/bin/apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directoryconfigure: error: Aborting则修改/usr/local/apache2/bin/apxs的/replace/with/path/to/perl/interpreter为perl程序路径(/usr/bin/perl) 若有:chmod 755 /usr/local/apache2/modules/libphp5.so chmod: cannot access `/usr/local/apache2/modules/libphp5.so': No such file or directory apxs:Error: Command failed with rc=65536则:yum install libtool./libtool --version,确保php和apache的libtool版本一致---------------------------------------------------------若有:checking whether to enable embedded MySQLi support… nochecking for mysql_set_server_option in -lmysqlclient… noconfigure: error: wrong mysql library version or lib not found. Check config.log for more information.则:在php/ext/mysqli中yum -y install mysql-devel/usr/local/php/bin/phpize./configure --enable-embedded-mysqli=shared --enable-shared --with-php-config=/usr/local/php/bin/php-configmakemake install---------------------------------------------------------若有:configure: error: Cannot find libmysqlclient_r under/usr/local/mysql. Note that the MySQL client library is not bundledanymore!cd /usr/local/mysql/libln -s libmysqlclient.so.20.0.9 libmysqlclient_r.so---------------------------------------------------------若有:gcc: Internal error: Killed (program cc1)Please submit a full bug report.See 
for instructions.make: *** [ext/date/lib/parse_date.lo] Error 1则:cd libmcrypt-2.5.8/libltdl/pwd/byrd/tools/libmcrypt-2.5.8/libltdl./configure --enable-ltdl-installldconfigcd ../../5.6.12make && make install

安装Nginx

groupadd wwwuseradd -g www -s /sbin/nologin -M www---------------------------------------------wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gztar zxf libunwind-1.1.tar.gzcd libunwind-1.1./configuremakemake install---------------------------------------------git clone https://github.com/gperftools/gperftools.gitcd gperftools./configure --enable-frame-pointersmakemake installecho "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf/sbin/ldconfig---------------------------------------------cd nginx-1.9.4./configure --prefix=/usr/local/nginx \--conf-path=/data/nginx/conf/nginx.conf \--user=www --group=www \--with-http_ssl_module \--with-http_stub_status_module \--with-google_perftools_modulemakemake install#创建模块需要的目录mkdir /tmp/tcmallocchmod 777 /tmp/tcmalloc -R

vi <somepath>/conf/nginx.conf

user www;worker_processes 8;pid logs/nginx.pid;#可选,根据编译时的参数google_perftools_profiles /tmp/tcmalloc;worker_rlimit_nofile 51200;events {    use epoll;    worker_connections 51200;}http {    include mime.types;    default_type application/octet-stream;        access_log off;    error_log /dev/null;        include proxy.conf;        server_names_hash_bucket_size 128;    client_header_buffer_size 32k;    large_client_header_buffers 4 32k;    #client_max_body_size 8m; #move to proxy.conf        sendfile on;    tcp_nopush on;        keepalive_timeout 120;    #fastcgi_connect_timeout 300;    #fastcgi_send_timeout 300;    #fastcgi_read_timeout 300;    #fastcgi_buffer_size 64k;    #fastcgi_buffers 4 64k;    #fastcgi_busy_buffers_size 128k;    #fastcgi_temp_file_write_size 128k;    tcp_nodelay on;        gzip on;    gzip_min_length 1k;    gzip_buffers 4 16k;    gzip_http_version 1.0;    gzip_comp_level 2;    gzip_types text/plain application/x-javascript text/css application/xml;    gzip_vary on;        log_format access_format '$remote_addr - $remote_user [$time_local] "$request" '        '$status $body_bytes_sent "$http_referer" '        '"$http_user_agent" "$http_x_forwarded_for"';        include vhosts/*.conf;}

proxy.conf

proxy_redirect          off;proxy_set_header        Host $host;proxy_set_header        X-Real-IP $remote_addr;proxy_set_header        X-Forwarded-For   $proxy_add_x_forwarded_for;client_max_body_size    50m;client_body_buffer_size 256k;proxy_connect_timeout   1200;proxy_send_timeout      1200;proxy_read_timeout      1200;proxy_buffer_size       4k;proxy_buffers           4 32k;proxy_busy_buffers_size 64k;proxy_temp_file_write_size 64k;proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;proxy_max_temp_file_size 128m;#Nginx cacheclient_body_temp_path client_body 1 2;proxy_temp_path proxy_temp 1 2;#client_body_temp_path      /tmpfs/client_body_temp 1 2;#proxy_temp_path            /tmpfs/proxy_temp 1 2;#fastcgi_temp_path          /tmpfs/fastcgi_temp 1 2;

vi /etc/rc.d/init.d/nginx

#!/bin/bash# nginx Startup script for the Nginx HTTP Server# it is v.0.0.2 version.# chkconfig: - 85 15# description: Nginx is a high-performance web and proxy server.# It has a lot of features, but it's not for everyone.# processname: nginx# pidfile: /usr/local/nginx/logs/nginx.pid# config: /usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/data/nginx/conf/nginx.confnginx_pid=/data/nginx/logs/nginx.pidRETVAL=0prog="nginx"# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0[ -x $nginxd ] || exit 0# Start nginx daemons functions.start() {if [ -e $nginx_pid ];thenecho "nginx already running...."exit 1fiecho -n $"Starting $prog: "daemon $nginxd -c ${nginx_config}RETVAL=$?echo[ $RETVAL = 0 ] && touch /var/lock/subsys/nginxreturn $RETVAL}# Stop nginx daemons functions.stop() {echo -n $"Stopping $prog: "killproc $nginxdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginx_pid}reload() {echo -n $"Reloading $prog: "#kill -HUP `cat ${nginx_pid}`killproc $nginxd -HUPRETVAL=$?echo}# See how we were called.case "$1" instart)start;;stop)stop;;reload)reload;;restart)stopstart;;status)status $progRETVAL=$?;;*)echo $"Usage: $prog {start|stop|restart|reload|status|help}"exit 1esacexit $RETVAL
chmod 755 /etc/rc.d/init.d/nginx chkconfig --add nginxchkconfig --level 2 nginx offchkconfig --level 345 nginx on#启动nginx后,验证:lsof -n | grep tcmalloc lsof -n | grep nginx#为 https 的 nginx 生成证书openssl genrsa -des3 -out server.key 1024openssl req -new -key server.key -out server.csropenssl rsa -in server.key -out server_nopwd.keyopenssl x509 -req -days 365 -in server.csr -signkey server_nopwd.key -out server.crt

null.conf

server {        listen  80 default_server;        server_name    _;        index index.html index.htm index.php;        root    /data/www/null;        location / {        }        error_page   500 502 503 504  /50x.html;        location = /50x.html {                root   html;        }        access_log    off;}

  

MySQL运行时加载tcmalloc

根据mysql安装位置而定

vi /usr/local/mysql/bin/mysqld_safe#在# executing mysqld_safe的下一行,加入以下内容export LD_PRELOAD="/usr/local/lib/libtcmalloc.so"(见:前文安装的libunwind和gperftools)

nginx代理apache后台获取IP问题

跑在后方 apache 上的应用获取到的IP都是Nginx所在服务器的IP ,或者是本机 127.0.0.1 。最明显就是查看 apache 的访问日志。发现始终都是内网的IP。可以通过修改 nginx proxy 的参数令后端应用获取到 Nginx 发来的请求报文获取到外网的IP。proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;但这解决的问题单单只是应用上,apache 日志上所获取的ip依然还是本地。solution:apache 2.2.x第三方的mod配合Nginx proxy使用。说明:http://stderr.net/apache/rpaf/下载:http://stderr.net/apache/rpaf/download/ 最新版本是 mod_rpaf-0.6.tar.gztar zxvf mod_rpaf-0.6.tar.gzcd mod_rpaf-0.6Apache 的目录按自己的环境修改,并选择相应的安装方式:/usr/local/apache2/bin/apxs -i -a -c mod_rpaf.c #Apache 1.3.x 的安装方式/usr/local/apache2/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c #Apache 2.x 的安装方式安装完成后在httpd.conf添加如下:LoadModule rpaf_module modules/mod_rpaf-2.0.soRPAFenable OnRPAFsethostname OnRPAFproxy_ips 127.0.0.1 192.168.1.50 #Nginx所在服务器的IPRPAFheader X-Forwarded-For保存退出后重启apacheapache 2.4.xapache 2.4 自带了mod_remoteip:参考:http://imcat.in/replacing-mod_rpaf-with-mod_remoteip-in-apache-2-4-nginx-real_ip-problem-solution/参考:https://blog.linuxeye.com/378.html或者依然使用apache 2.4 对应的mod_rpaf:参考:http://www.meidahua.com/2015/apache-2-4-mod_rpaf.html参考:http://jayanvenugopalan.blogspot.hk/2014/07/install-modrpaf-with-apache-24.html

MySQL从服务器my.cnf

server-id = 2replicate-ignore-db=mysqlrelay-log = /data/mysql/logs/mysql-relay-binrelay-log-index = /data/mysql/logs/mysql-relay-bin.indexmaster-info-file = /data/mysql/logs/mysql-master.inforelay-log-info-file = /data/mysql/logs/mysql-relay-log.info

  

CHANGE MASTER TO MASTER_HOST='119.254.81.66', MASTER_USER='backup_user', MASTER_PASSWORD='db_sub-1';“OR”CHANGE MASTER TO MASTER_HOST='192.168.0.200', MASTER_USER='backup_user', MASTER_PASSWORD='db_sub-1';start salve;

为php追加若干扩展

wget https://pecl.php.net/get/redis-2.2.8.tgztar zxf redis-2.2.8.tgz cd redis-2.2.8phpize./configuremakemake install

  

pecl install mongopecl install mongodbpecl install memcachepecl install memcached # 需要libmemcached的支持
http://www.phpgao.com/vps_ssh.html

 

 

转载于:https://www.cnblogs.com/saonian/p/6796077.html

你可能感兴趣的文章
获取NVIDIA显卡的温度
查看>>
Dijkstra算法
查看>>
Deep Learning 9: Performance
查看>>
面试题61 把二叉树打印成多行
查看>>
C#例子 易懂故事 接口 委托 事件 异步通知 好玩.
查看>>
[转]Windows Shell 编程 第十一章 【来源:http://blog.csdn.net/wangqiulin123456/article/details/7987992】...
查看>>
修改presto新版源码让他支持redash数据库
查看>>
Javascript的书写位置
查看>>
树-线索二叉树
查看>>
JAVA遇见HTML——Servlet篇:Servlet基础
查看>>
第二章 Vue快速入门--20 品牌案例-完成品牌列表的添加功能+ 21 品牌案例-根据Id完成品牌的删除...
查看>>
Java单例模式
查看>>
重温WCF之消息契约(MessageContract)(六)
查看>>
Excel2007制作直方图和正态分布曲线图
查看>>
android adb常用指令
查看>>
Android框架之路——GreenDao3.2.2的使用
查看>>
类方法WCF学习笔记-KnowTypeAttribute用法
查看>>
平台程序微信平台开发应用的签名
查看>>
程序卡OK6410裸板更新程序_update
查看>>
MYSQL用户名:root
查看>>