文章引用列表:

Linux安装AMP http://www.21ops.com/ops/25307.html

mysql开启远程登录http://www.pc6.com/infoview/Article_63285.html

mysql安装:http://www.chenyudong.com/archives/building-mysql-5-6-from-source.html

关于ssh登录超时解决http://www.linuxidc.com/Linux/2013-02/79942.htm

nginx虚拟主机配置http://www.neoease.com/nginx-virtual-host/

apache虚拟主机配置http://www.neoease.com/apache-virtual-host/

zip解压说明 http://www.cnblogs.com/chinareny2k/archive/2010/01/05/1639468.html

rar源码安装 http://oldboy.blog.51cto.com/2561410/597515/

注意:mysql配置部分。参数为–。由于wordpress本身问题,后台编辑好之后,前台显示的为-。

小命令(不断更新中):

1.etc/sysconfig/network 修改Linux主机的名称。

2.curl -I www.mrliangqi.com 探测网站服务版本信息。

3.nginx配置文件里增加 server_tokens off; //隐藏Nginx版本号

相关源代码包下载地址

apr-1.4.6.tar.gz

apr-util-1.4.1.tar.gz

cmake-2.8.7.tar.gz

libmcrypt-2.5.7.tar.gz

mysql-5.5.21.tar.gz

nginx-1.7.1.tar.gz

php-5.3.27.tar.gz

一.系统以安全以及必备库文件安装

1.sshd: ssh sshd //两个配置文件添加端口,在防火墙放行修改的端口

2.selinu //注释前两行添加SELINUX=disable

3.yum update && upgrade //系统以及软件更新

4.yum -y install gcc gcc-c++ apr* make automake autoconf kernel-devel ncurses-devel libxml2* openssl-devel curl-devel libjpeg-devel libpng-devel pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils   readline-devel glib* bzip2-devel gettext-devel libcap-devel libmcrypt-devel libjpeg* libpng* php-common php-gd ncurses* libtool*   //安装库文件

安装lib cmake apr apr-util

cmake

./configure && make &&make install

linmcrypt

./configure && make &&make install

apr

./configure -prefix=/usr/local/apr && make &&make install

apr-util

./configure -prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config && make && make install

二.mysql数据库的安装

1.useradd -M -s /sbin/nologin mysql //创建mysql账户并禁止登录系统账户

2.mkdir -p /data/mysql //创建mysql数据库的存放路径

3.mkdir -p /usr/local/mysql //创建mysql的安装目录

4.chown -R mysql.mysql /data/mysql

  chown –R mysql /usr/local/mysql //设置mysql数据库的目录权限

5.编译安装

cmake . -DCMAKE_INSTALL_PREFIX_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysql/ -DSYSCONFIDIR=/etc/ && make&& make install

6.cp ./support-files/my-huge.cnf /etc/my.cnf //复制配置文件(默认/etc下有,直接覆盖即可)

7.vi /etc/my.cnf   #编辑配置文件,在 [mysqld] 部分增加下面一行

datadir = /data/mysql  #添加MySQL数据库路径

socket         = /var/lib/mysql/mysql.sock

8./usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql/ –datadir=/data/mysql & //初始化数据库

常见报错:FATAL ERROR: Could not find ./bin/my_print_defaults

(备用命令:/usr/local/mysql/scripts/mysql_install_db  –user=mysql –basedir=/usr/local/mysql/  –datadir=/data/mysql/

/usr/local/mysql/bin/mysqld_safe  –user=mysql  & //启动mysql

9.cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld //复制mysql服务到系统

10.chmod 755 /etc/rc.d/init.d/mysqld //赋予可执行权限

11.chkconfig –add mysqld //添加到系统服务

12.chkconfig mysqld on //添加到开启启动

13.ln -s /usr/local/mysql/bin/mysql /usr/bin //添加到系统路径

14.ln -s /usr/local/mysql/bin/mysqladmin /usr/bin//添加到系统路径

15.mysqladmin –socket=/var/lib/mysql/mysql.sock  -u root password ’3306.com‘ //给mysql设置密码为3306.com (需要启动mysql之后执行)

报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 解决:由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,但linux系统总是去/tmp/mysql.sock查找,所以会报错

[[email protected] ~]# find / -name mysql.sock /var/lib/mysql/mysql.sock

跟完整路径:mysql –socket=/var/lib/mysql/mysql.sock -u –p

创建符号连接:ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

也可以使用–socket=/var/lib/mysql/mysql.sock 参数指定sockt

附加:命令行修改root密码:     mysql> UPDATE mysql.user SET password=PASSWORD(’新密码’) WHERE User=’root’;     mysql> FLUSH PRIVILEGES;

4、显示当前的user: mysql> SELECT USER();

给数据库添加远程登录权限

mysql> Grant all privileges on *.* to 'root'@'%' identified by ‘password’ with grant option;(%表示是所有的外部机器,如果指定某一台机,就将%改为相应的机器名;‘root’则是指要使用的用户名,里面的password需要自己修改成root的密码) mysql> flush privileges; (运行为句才生效,或者重启MySQL).

关于mysql的字符串乱码情况解决办法:

在my.conf配置文件中添加两处参数,1.,在[mysql]段加入default_character_set=utf8    [mysqld]段加入character_set_server=utf8 即可解决。

也可以登陆mysql之后,用命令查看字符设置的情况:

show variables like 'collation_%';

show variables like 'character_set_%';

三.php环境的安装

mkdir -p /usr/local/php

./configure –prefix=/usr/local/php  –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-iconv-dir=/usr/local/libiconv –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 –with-curlwrappers –enable-mbregex –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 –enable-fpm –with-fpm-user=www –with-fpm-group=www –with-pdo-mysql=/usr/local/mysql –without-pear  –disable-fileinfo  –with-libdir=/lib64

(备用:./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-iconv-dir=/usr/local/libiconv –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –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 –enable-fpm –with-fpm-user=www –with-fpm-group=www –with-pdo-mysql=/usr/local/mysql –without-pear –disable-fileinfo –with-libdir=/lib64)

#make

# make intsall

安装OK。

# cp php.ini-production /usr/local/php/etc/php.ini //复制配置文件

# /usr/local/php/etc/

# mv php-fpm.conf.default php-fpm.conf //移动脚本文件

启动PHP:/usr/local/php/sbin/php-fpm & //后台启动

Netstat –an | grep 9000 //查看php的端口9000是否开启。

报错:error: Cannot find ldap.h

解决:yum install openldap openldap-devel

注意:

因为是64位系统,所以要加 –with-libdir=/lib64

遇到这个错误:configure: error: Cannot find libmysqlclient under /usr/local/mysql

解决方法:ln -s /usr/local/mysql/lib/ /usr/local/mysql/lib64

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/

报错:make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

解决方法:这是由于内存小于1G所导致.

在./configure加上选项: –disable-fileinfo

Disable fileinfo support 禁用 fileinfo

报错:error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

解决:

ln -s /usr/local/mysql/lib /usr/local/lib

四.Nginx的安装配置

Nginx安装

 groupadd  www

 useradd  -g www www

# tar -zxvf nginx-1.5.0.tar.gz

# cd nginx-1.5.0

#./configure –prefix=/usr/local/nginx –with-http_stub_status_module && make && make install

遇到此错误 ./configure: error: the HTTP rewrite module requires the PCRE library.

原因:安装http_rewrite_module模块需要先安装PCRE开发包

解决方法 :yum -y install pcre-devel

遇到此错误./configure: error: the HTTP SSL module requires OpenSSL library

原因:安装http_ssl_module模块需要openssl library

解决方法:yum install openssl-devel

Nginx 基本命令

/usr/local/nginx/sbin/nginx 启动 /usr/local/nginx/sbin/nginx -s reload 重启

/usr/local/nginx/sbin/nginx -s stop 关闭

设置nginx开机启动

vi /etc/init.d/nginx 编辑启动文件添加下面内容

#!/bin/sh

# chkconfig: – 55 45

# description: The nginx daemon is a web service.

# processname: nginx

. /etc/rc.d/init.d/functions

NGINX="/usr/local/nginx/sbin/nginx"

start()

{

echo -n $"Starting nginx: "

daemon $NGINX

echo

}

stop()

{

echo -n $"Shutting down nginx: "

$NGINX -s stop

echo

}

quit()

{

echo -n $"Shutting down nginx: "

$NGINX -s quit

echo

}

reload()

{

echo -n $"reload config:"

$NGINX -s reload

echo

}

[ -f $NGINX ] || exit 1

 

# See how we were called.

case "$1" in

start)

start

;;

stop)

quit

;;

reload)

reload

;;

restart)

stop

sleep 3

start

;;

*)

echo $"Usage: $0 {start|stop|restart|reload}"

exit 1

esac

exit 0

保存退出

chmod 775 /etc/init.d/nginx   #赋予文件执行权限

chkconfig –level 012345 nginx on   #设置开机启动

chkconfig –level 3 nginx on

/etc/init.d/nginx restart

 

配置nginx

mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

创建nginx用户www

groupadd www

useradd -g www www

编辑主配置文件

vi /usr/local/nginx/conf/nginx.conf

内容如下

user www;

worker_processes 1;     #工作进程数,为CPU的核心数或者两倍

pid       logs/nginx.pid;

events {

worker_connections 1024; #Linux最常用支持大并发的事件触发机制

}

http {

include       mime.types; #设定mime类型,类型由mime.type文件定义

default_type application/octet-stream;

log_format main '$remote_addr – $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;   #设定请求缓冲

sendfile       on;

#tcp_nopush     on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

server {

listen       80;

#server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root   html;

index index.html index.htm;

}

#error_page 404             /404.html;

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504 /50x.html;

location = /50x.html {

root   html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

#   proxy_pass   http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

#   root           html;

#   fastcgi_pass   127.0.0.1:9000;

#   fastcgi_index index.php;

#   fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

#   include       fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

#   deny all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

#   listen       8000;

#   listen       somename:8080;

#   server_name somename alias another.alias;

#   location / {

#       root   html;

#       index index.html index.htm;

#   }

#}

# HTTPS server

#

#server {

#   listen       443;

#   server_name localhost;

#   ssl                 on;

#   ssl_certificate    cert.pem;

#   ssl_certificate_key cert.key;

#   ssl_session_timeout 5m;

#   ssl_protocols SSLv2 SSLv3 TLSv1;

#   ssl_ciphers HIGH:!aNULL:!MD5;

#   ssl_prefer_server_ciphers   on;

#   location / {

#       root   html;

#       index index.html index.htm;

#   }

#}

include vhost/*.conf;   #nginx虚拟主机包含文件目录

}

编辑配置文件

cd /usr/local/nginx/conf/vhost/admin.conf

内容如下

server{

listen  80;

server_name 192.168.1.55;

root   /home/admin/;    #配置发布目录

access_log      logs/www_lolfs.log main;

location / {

index  index.php index.html index.htm;

}

location ~ \.php$ {

root           /home/admin/;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

location ~ \.(cgi|pl)?$ {

gzip off;

root   /usr/local/nagios/sbin;

rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;

fastcgi_pass  unix:/usr/local/perl-fcgi/logs/perl-fcgi.sock;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;

fastcgi_index index.cgi;

fastcgi_read_timeout   60;

#fastcgi_param  REMOTE_USER        $remote_user;

#auth_basic "Nagios Access";

#auth_basic_user_file /usr/local/nagios/etc/nagiospasswd;

}

location ~* ^.+.(jpg|jpeg|gif|png|ico)$ {

access_log   off;

expires      30d;

}

location ~* ^.+.(js|css)$ {

access_log   off;

expires      1h;

}

location ~* ^.+.(html|php)$ {

access_log   off;

expires      10m;

}

}

 

 

——–完毕。

 

 

 

 

 

 

 

 

 

发表评论

后才能评论