LANMP On CentOS 6
摘要
环境:最小化安装系统
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.-linux-glibc2.-x86_64.tar.gz
mv mysql-5.6.-linux-glibc2.-x86_64 /usr/local/mysql
useradd mysql -s /sbin/nologin
mkdir -p /data/mysql/data
chown -R mysql:mysql /usr/local/mysql /data/mysql/data
---------------------------------------------
#可选:ln -s /usr/local/mysql/lib/libmysqlclient.so. \
/usr/lib/libmysqlclient.so.
配置启动MySQL
1. 先修改 mysql 的配置 my.cnf
mv /etc/my.cnf /etc/my.cnf.old
vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
user=mysql
explicit_defaults_for_timestamp=true
innodb_file_per_table=
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-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/mysqld
chmod /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level mysqld off
chkconfig --level mysqld on
vi /etc/init.d/mysqld
#查找并修改以下变量内容:
basedir=/usr/local/mysql
datadir=/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_64
wget http://archive.apache.org/dist/httpd/httpd-2.4.17.tar.gz
tar zxf httpd-2.4..tar.gz
wget http://www.us.apache.org/dist//apr/apr-1.5.2.tar.gz
tar zxf apr-1.5..tar.gz
cp -r apr-1.5. httpd-2.4./srclib/apr
wget http://www.us.apache.org/dist//apr/apr-util-1.5.4.tar.gz
tar zxf apr-util-1.5..tar.gz
cp -r apr-util-1.5. httpd-2.4./srclib/apr-util
cd httpd-2.4.
./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
make
make install
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
#在 #!/bin/sh 下面添加:
# chkconfig:
# description: Activates/Deactivates Apache Web Server
#最后,运行chkconfig把Apache添加到系统的启动服务组里面:
chkconfig --add httpd
chkconfig --level httpd off
chkconfig --level httpd on
#安装时的--sysconfigdir参数只修改了httpd.conf本身的父文件夹,而httpd.conf内容中的Include指令依然搜索--prefix制定的apache程序目录
#解决方法:
#在httpd.conf中加入
Define extra_conf_parent_path /foo/bar/httpd
Include ${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-devel
wget http://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
wget http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar -zxf libmcrypt-2.5..tar.gz
cd libmcrypt-2.5.
./configure
make
make install
tar -zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
wget https://github.com/skvadrik/re2c/releases/download/0.16/re2c-0.16.tar.gz
tar zxf re2c-0.16.tar.gz
cd re2c-0.16
./configure
make
make install
cd php-5.6.
./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 make
make install
若有:
Sorry, I cannot run apxs. Possible reasons follow:
. Perl is not installed
. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
. 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 directory
configure: error: Aborting
则修改/usr/local/apache2/bin/apxs的/replace/with/path/to/perl/interpreter为perl程序路径(/usr/bin/perl) 若有:
chmod /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… no
checking for mysql_set_server_option in -lmysqlclient… no
configure: 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-config
make
make install
---------------------------------------------------------
若有:
configure: error: Cannot find libmysqlclient_r under/usr/local/mysql. Note that the MySQL client library is not bundledanymore!
cd /usr/local/mysql/lib
ln -s libmysqlclient.so.20.0. libmysqlclient_r.so
---------------------------------------------------------
若有:
gcc: Internal error: Killed (program cc1)
Please submit a full bug report.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [ext/date/lib/parse_date.lo] Error
则:
cd libmcrypt-2.5./libltdl/
pwd
/byrd/tools/libmcrypt-2.5./libltdl
./configure --enable-ltdl-install
ldconfig
cd ../../5.6.
make && make install
安装Nginx
groupadd www
useradd -g www -s /sbin/nologin -M www
---------------------------------------------
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
tar zxf libunwind-1.1.tar.gz
cd libunwind-1.1
./configure
make
make install
---------------------------------------------
git clone https://github.com/gperftools/gperftools.git
cd gperftools
./configure --enable-frame-pointers
make
make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
---------------------------------------------
cd nginx-1.9.
./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_module
make
make install
#创建模块需要的目录
mkdir /tmp/tcmalloc
chmod /tmp/tcmalloc -R
vi <somepath>/conf/nginx.conf
user www;
worker_processes ;
pid logs/nginx.pid;
#可选,根据编译时的参数
google_perftools_profiles /tmp/tcmalloc;
worker_rlimit_nofile ;
events {
use epoll;
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream; access_log off;
error_log /dev/null; include proxy.conf; server_names_hash_bucket_size ;
client_header_buffer_size 32k;
large_client_header_buffers 32k;
#client_max_body_size 8m; #move to proxy.conf sendfile on;
tcp_nopush on; keepalive_timeout ;
#fastcgi_connect_timeout ;
#fastcgi_send_timeout ;
#fastcgi_read_timeout ;
#fastcgi_buffer_size 64k;
#fastcgi_buffers 64k;
#fastcgi_busy_buffers_size 128k;
#fastcgi_temp_file_write_size 128k;
tcp_nodelay on; gzip on;
gzip_min_length 1k;
gzip_buffers 16k;
gzip_http_version 1.0;
gzip_comp_level ;
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 ;
proxy_send_timeout ;
proxy_read_timeout ;
proxy_buffer_size 4k;
proxy_buffers 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 cache
client_body_temp_path client_body ;
proxy_temp_path proxy_temp ;
#client_body_temp_path /tmpfs/client_body_temp ;
#proxy_temp_path /tmpfs/proxy_temp ;
#fastcgi_temp_path /tmpfs/fastcgi_temp ;
vi /etc/rc.d/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0. version.
# chkconfig: -
# 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.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/data/nginx/conf/nginx.conf
nginx_pid=/data/nginx/logs/nginx.pid
RETVAL=
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit
[ -x $nginxd ] || exit
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = ] && rm -f /var/lock/subsys/nginx $nginx_pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit
esac
exit $RETVAL
chmod /etc/rc.d/init.d/nginx chkconfig --add nginx
chkconfig --level nginx off
chkconfig --level nginx on
#启动nginx后,验证:
lsof -n | grep tcmalloc
lsof -n | grep nginx
#为 https 的 nginx 生成证书
openssl genrsa -des3 -out server.key
openssl req -new -key server.key -out server.csr
openssl rsa -in server.key -out server_nopwd.key
openssl x509 -req -days -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.gz tar zxvf mod_rpaf-0.6.tar.gz cd mod_rpaf-0.6 Apache 的目录按自己的环境修改,并选择相应的安装方式: /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.so RPAFenable On RPAFsethostname On RPAFproxy_ips 127.0.0.1 192.168.1.50 #Nginx所在服务器的IP RPAFheader X-Forwarded-For 保存退出后重启apache apache 2.4.x apache 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 = 2
replicate-ignore-db=mysql
relay-log = /data/mysql/logs/mysql-relay-bin
relay-log-index = /data/mysql/logs/mysql-relay-bin.index
master-info-file = /data/mysql/logs/mysql-master.info
relay-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.tgz
tar zxf redis-2.2.8.tgz
cd redis-2.2.8
phpize
./configure
make
make install
pecl install mongo
pecl install mongodb
pecl install memcache
pecl install memcached # 需要libmemcached的支持
http://www.phpgao.com/vps_ssh.html
LANMP On CentOS 6的更多相关文章
- CentOS 6、7下pptp vpn一键安装脚本
之前有折腾过<CentOS 6.7下IPSEC/L2TP VPN一键安装脚本>,不稳定.不支持IOS,因此换成pptp,并已经添加到<lnmp一键安装包>.这个脚本可以单独使用 ...
- Centos6.7下安装配置VPN
在Vultr上买了台VPS准备做VPN,不贵5刀,位置是日本东京的.ping值在100-200之间,还好算说的过去. Vultr地址 系统选择的Centos6 的版本是6.7 在网上查了查linux下 ...
- centos shell编程5 LANMP一键安装脚本 lamp sed lnmp 变量和字符串比较不能用-eq cat > /usr/local/apache2/htdocs/index.php <<EOF重定向 shell的变量和函数命名不能有横杠 平台可以用arch命令,获取是i686还是x86_64 curl 下载 第三十九节课
centos shell编程5 LANMP一键安装脚本 lamp sed lnmp 变量和字符串比较不能用-eq cat > /usr/local/apache2/htdocs/ind ...
- Centos 6.4 搭建LANMP一键安装版
lanmp一键安装包是wdlinux官网2010年开始推出的lamp,lnmp,lnamp(apache,nginx,php,mysql,zend,eAccelerator,pureftpd)应用环境 ...
- lanmp安装一(centos+apache+nginx+mysql+php=lanmp地址下载)
背景 centos7 官网地址https://www.centos.org/download/ 下载选择DVD版进入(也就是标准版,系统齐全) 点击任何一个国家的下载链接 下载地址 http://m ...
- lanmp之一 (动静分离)
一.lanmp--需求篇 1. 准备两台centos 6,其中一台机器跑mysql,另外一台机器跑apache,nginx + php 2. 同时安装apache和nginx,其中nginx启动80端 ...
- 使用 shell 脚本实现 LANMP 一键安装
使用 shell 脚本来实现 LANMP 系统的一键安装.使用的操作系统是 CentOS 6 ,不区分 32 位和 64 位,要求机器可以连通互联网.支持 LAMP 和 LNMP ,MySQL 支持 ...
- centos curl版本nss改成openssl
在centos 6.2的系统里面的curl支持的https是nss版本的,而不是openssl的,所以在php使用curl访问https的时候会报Unable to load client key - ...
- Linux下安装LANMP环境
记录下来,方便下次再用时从头查找资料 首先是操作系统和php环境:CentOS 6.5 64位(之所以不是7.0是因为本身对linux不熟,而7.0改变挺大的,搜索查询资料也不好搜索),Php版本:5 ...
随机推荐
- Windows Intellij环境下Gradle的 “Could not determine Java version from ‘9.0.1’”的解决方式
当我导入Gradle项目初试Java spring的时候,遇到下面报错: Gradle complete project refresh failed Error:Could not determin ...
- (转)Python 日期和时间
转自http://www.runoob.com/python/python-date-time.html Python 日期和时间 Python 程序能用很多方式处理日期和时间,转换日期格式是一个常见 ...
- CentOS7 nginx简单配置pathinfo模式(ThinkPHP)
location ~ \.php { #去掉$ root H:/PHPServer/WWW; fastcgi_pass 127.0.0.1:9000; fastcgi_in ...
- winform在鼠标操作时要判断是否按下Ctrl键
(Control.ModifierKeys & Keys.Control) == Keys.Control
- 【Android源码解析】View.post()到底干了啥
emmm,大伙都知道,子线程是不能进行 UI 操作的,或者很多场景下,一些操作需要延迟执行,这些都可以通过 Handler 来解决.但说实话,实在是太懒了,总感觉写 Handler 太麻烦了,一不小心 ...
- Linux用户管理的复习时间
所谓三天不练手生,你还记得关于Linux用户管理的所有知识吗?现在就来跟我一起复习一下吧! 1.常用配置文件 用户信息文件: /etc/password 密码文件: /etc/shadow 用户组文件 ...
- Unity3D中通过Animator动画状态机获取任意animation clip的准确播放持续时长
Unity3d 4及之前的版本中动画的播放用的animation,可直接获取其播放持续长度.但5.x及以后的版本中都是用animator来播放动画了. https://docs.unity3d.com ...
- 【new File(String Path)加载资源问题】
2017-12-17 15:07:38 [原创-wx] 一.我们在用IO流加载资源的时候,创建文件资源 1 File file = New File("String Path" ...
- C#线程等待句柄
相互排斥对象 Mutex private Mutex m = new Mutex(); public void Method(){ m.WaitOne(); //运行操作 m.ReleaseMutex ...
- hdu2993之斜率dp+二分查找
MAX Average Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...