linux配置分步安装lnmp环境----ghj

前台:nignx 后台:apache

【linux命令】
用户
文件目录
启动
定时任务:
【开启RZ命令】

yum -y install lrzsz

【防火墙】

防火墙配置文件: /etc/sysconfig/iptables
服务操作命令 : /etc/init.d/iptables service iptables {start|stop...}
临时改变命令 : iptables iptables-save iptables-restore等
service iptables status可以查看到iptables服务的当前状态。
但是即使服务运行了,防火墙也不一定起作用,你还得看防火墙规则的设置 iptables -L
在此说一下关于启动和关闭防火墙的命令:
1) 重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后失效
开启: service iptables start
关闭: service iptables stop

【修改IP】
#vi /etc/syssconfig/network-scripts/ifcfg-eth0

  DEVICE=eth0

  BOOTPROTO=static

  HWADDR= ;这里是你网卡的物理地址,通常检测到的网卡你就不用输入了

  ONBOOT=yes

  IPADDR=192.168.0.1

  NETMASK=255.255.255.0

  NETWORK=192.168.1.0

  BROADCAST=192.168.1.255

  GATEWAY= ;这里输入你的网关,路由器的IP地址

  保存退出

  #/sbin/service network restart

  如果网卡启动是OK的话就说明IP地址设定成功了。另外我们可以用ifconfig eth0来显示当前的IP来确认是否设置正确。

  利用以下命令:

  /etc/init.d/network reload 命令或service network [命令]

【yum源】

.本地源制作

1、首先在/media目录下创建一个目录cdrom并将将光盘挂载到系统/media/cdrom下
mkdir /media/cdrom
mount /dev/cdrom /media/cdrom/
2、进入到/etc/yum.repos.d目录CentOS-Base.repo重命名。

cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak
vi CentOS-Media.repo
修改为
gpgcheck=0
enabled=1

***3、将所有的CentOS安装包链接到/media/CentOS
ln -s /media/cdrom/CentOS/ /media/CentOS






#yum 安装系统环境所需要的软件包

yum -y install yum-fastestmirror ntp
yum -y install patch make flex bison tar
yum -y install libtool libtool-libs kernel-devel
yum -y install libjpeg libjpeg-devel libpng libpng-devel
yum -y install libtiff libtiff-devel gettext gettext-devel
yum -y install libxml2 libxml2-devel zlib-devel  net-snmp
yum -y install file glib2 glib2-devel bzip2 diff* openldap-devel
yum -y install bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs
yum -y install e2fsprogs-devel krb5 krb5-devel libidn libidn-devel
yum -y install openssl openssl-devel vim-minimal unzip

# 安装PHP支持GD库模块
yum -y install freetype freetype-devel png jpeg zlib gd php-gd*
# 安装PHP 5.* 组件
yum -y install libiconv libevent mhash mcrypt
# 安装MYDSQL所需要系统库相关库文件
yum install -y gcc gcc-c++ gcc-g77 autoconf automake  fiex* ncurses-devel libmcrypt* libtool-ltdl-devel*

# 安装NGINX 组件
yum -y install pcre*

yum -y install gcc gcc-c++ gcc-g77 flex bison tar libtool libtool-libs kernel-devel  autoconf libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel gettext gettext-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel file glib2 glib2-devel bzip2diff* openldap-devel bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal unzip  automake make

yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

【安装nginx 之前要安装pcre】

tar zvxf pcre-8.10.tar.gz
#cd pcre-8.10
#./configure
#make
#make install

【nginx】
下载安装包:http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure
make && make install

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


开机启动nginx:在linux系统的/etc/init.d/目录下创建nginx文件

vi /etc/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: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
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 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
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 1
esac
exit $RETVAL

chmod a+x /etc/init.d/nginx

最后将ngix加入到rc.local文件中,这样开机的时候nginx就默认启动了
 vi /etc/rc.local  
添加  /etc/init.d/nginx start  
保存并退出  下次重启就会生效,实现nginx的自启动。

【安装mysql】
yum -y install  gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake

yum -y install cmake

groupadd mysql
useradd -r -g mysql mysql

tar -zxvf mysql-5.6.21.tar.gz
cd mysql-5.6.21

cmake .
make && make install

-------------------------默认情况下是安装在/usr/local/mysql

chown -R mysql.mysql /usr/local/mysql

cd /usr/local/mysql/scripts
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

cd /usr/local/mysql/support-files
cp mysql.server /etc/rc.d/init.d/mysql
cp my-default.cnf /etc/my.cnf
chkconfig --add mysql
chkconfig mysql on
service mysql start




修改密码:/usr/local/mysql/bin/mysqladmin -u root password '123456'

登陆:/usr/local/mysql/bin/mysql -u root -p
 

修改远程访问权限:

1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

Sql代码 复制代码

   1. mysql -u root -p
   2. use mysql;  
   3. mysql>update user set host = '%' where user = 'root';  
   4. mysql>select host, user from user;

2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。

Sql代码 复制代码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

FLUSH PRIVILEGES;


【安装apache】

cd /usr/local/src

groupadd www
useradd -g www -s /sbin/nologin -M www

wget http://apache.freelamp.com//httpd/httpd-2.2.17.tar.gz

tar zxvf httpd-2.2.17.tar.gz

cd httpd-2.2.17


Apache默认最大连接数和最大客户端数为40000,如果你的服务器要求更大,可以编译Apache安装文件中的:

    server/mpm/worker/worker.c

找到下面几行,并改成如下的数值,其目的是在源码中修改apache可支持的最大线程数和最大客户端数目。

    define DEFAULT_SERVER_LIMIT 32
    define MAX_SERVER_LIMIT 40000
    define DEFAULT_THREAD_LIMIT 64
    define MAX_THREAD_LIMIT 40000

以上数值据说改小后,能减低服务器消耗。不过柒月修改后,发现没什么实质变化

依次安装apr和apr-util     
    tar zxvf apr-1.5.2.tar.gz
    cd apr-1.5.2    
    ./configure --prefix=/usr/local/apr
    make && make install
    
    tar zxvf apr-util-1.5.4.tar.gz

    cd apr-util-1.5.4

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

安装Apache 2.4

    cd /usr/local/src/httpd-2.4.20

    ./configure --prefix=/usr/local/apache --with-mysql=/usr/local/mysql --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-so --enable-rewrite --with-mpm=prefork --disable-cgid --disable-cgi

    make && make install

如果你需要编译apache其他功能,可以自行增加。不过在这里,我们只是用Apache作为后端并处理伪静态,无需添加过多设置来浪费内存

注解:

    ./configure //配置源代码树
    --prefix=/usr/local/apache //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。
    --enable-module=so //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块
    --enable-mods-shared=all //编译全部的模板,对于不需要我们可以在httpd.conf去掉。
    --enable-cache //支持缓存
    --enable-file-cache //支持文件缓存
    --enable-mem-cache //支持记忆缓存
    --enable-disk-cache //支持磁盘缓存
    --enable-static-support //支持静态连接(默认为动态连接)
    --enable-static-htpasswd //使用静态连接编译 htpasswd - 管理用于基本认证的用户文件
    --enable-static-htdigest //使用静态连接编译 htdigest - 管理用于摘要认证的用户文件
    --enable-static-rotatelogs //使用静态连接编译 rotatelogs - 滚动 Apache 日志的管道日志程序
    --enable-static-logresolve //使用静态连接编译 logresolve - 解析 Apache 日志中的IP地址为主机名
    --enable-static-htdbm //使用静态连接编译 htdbm - 操作 DBM 密码数据库
    --enable-static-ab //使用静态连接编译 ab - Apache HTTP 服务器性能测试工具
    --enable-static-checkgid //使用静态连接编译 checkgid
    --disable-cgid //禁止用一个外部 CGI 守护进程执行CGI脚本
    --disable-cgi //禁止编译 CGI 版本的 PHP
    --with-mpm=worker // 让apache以worker方式运行
    --enable-ssl // 编译 ssl模块。

启动Apache(建议先不要启动,等我们全部设置完毕后,和Nginx启动)

    /usr/local/apache/bin/apachectl start|stop|restart

查看apache是否启动

    ps aux|grep httpd

将apache设置成开机自启动:

echo '/usr/local/apache/bin/apachectl start ' >> /etc/rc.local  //将 apachectl 的调用加入到你的系统启动文件中。

问题:httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

在httpd.conf (/usr/local/apache/conf/httpd.conf)中找到
#ServerName www.example.com:8080   把#去掉

error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory

试着执行: ldd /usr/local/apache/bin/httpd
会看到这么一行
libiconv.so.2 => Not found
以前编译运行是可以的,可能是不久前升级一些库文件影响。在/usr/local/lib下可以找到libiconv.so.2,把/usr/local/lib加到路径中也不行。
在/etc/ld.so.conf中加一行/usr/local/lib,运行ldconfig。再运行apache,OK。
ld.so.conf和ldconfig是维护系统动态链接库的。


【软件版本:PHP 5.6.3】

一、安装libiconv库

tar -zvxf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure –help
./configure --prefix=/usr/local

make && make install

echo "/usr/local/lib">>/etc/ld.so.conf

/sbin/ldconfig

下载php5.6.12
      
wget http://cn2.php.net/distributions/php-5.6.3.tar.gz

解压 php 5.6.3 源码包
      
tar -zxvf php-5.6.3.tar.gz



./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mb --enable-bcmath --enable-mbstring --enable-sockets --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-iconv-t --with-zlib --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --enable-dom --enable-xml --enable-fpm --with-iconv-dir=/usr/local --with-apxs2=/usr/local/apache/bin/apxs

编译完毕后,我们再来make。在make时,我们注意要加上-liconv参数。如果不加上-liconv参数,系统在make编译会报错。报错信息如下:

Generating phar.php

//php-5.3.16/sapi/cli/php: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
make: *** [sapi/cli/php] Error 1

使用命令如下:

make ZEND_EXTRA_LIBS='-liconv'

make install

[注意]上述命令中:
–enable-fpm的作用是开启php的fastcgi功能,即开启php-fpm功能。

–with-mysql=/usr/local/mysql是启用php支持mysql的功能,/usr/local/mysql是mysql数据库的安装路径。

–enable-mbstring表示启用mbstring模块mbstring模块的主要作用在于检测和转换编码,提供对应的多字节操作的字符串函数。目前php内部的编码只支持ISO-8859-*、EUC-JP、UTF-8,其他的编码的语言是没办法在php程序上正确显示的,所以我们要启用mbstring模块。

–with-iconv-dir=/usr/local指定php存放libiconv库的位置。

–with-apxs2=/usr/local/apache/bin/apxs指定php查找apache的位置。

配置php的环境变量

echo "PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin" >> /etc/profile
source !$  # 刷新系统环境

cp php.ini-production /usr/local/php/etc/php.ini

cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf

vi etc/php-fpm.conf

user = www
group = www

在安装目录下:

cp /usr/local/src/php-5.6.3/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod 755 /etc/init.d/php-fpm

/usr/local/php/sbin/php-fpm -t

启动和关闭php 并查看php状态
service php-fpm start
或者
/usr/local/php/sbin/php-fpm
service php-fpm stop
service php-fpm status
Usage: /etc/init.d/php-fpm {start|stop|force-quit|restart|reload|status}

添加php到系统服务,并随机启动
      
chkconfig --add php-fpm && chkconfig php-fpm on



【php与apache】

/usr/local/apache/conf/httpd.conf:

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php

重启apache /usr/local/apache/bin/apachectl restart

echo "<?php phpinfo();?>">/usr/local/apache/htdocs/index.php

cat /usr/local/apache/htdocs/index.php

【php与nginx】 nginx-> php-fpm(502)->  php

 location ~ .php$ {
                root html;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

【主从复制】


【读写分离】

【反向代理】

【git】

【svn】

=======================================================

svn配置

1.安装svn服务器端
yum install subversion 从镜像下载安装svn服务器端
cd /usr/local/ //进入目录,准备创建svn目录
mkdir svn //创建一个svn目录
chmod -R 777 svn //修改目录权限为777
svnadmin create /usr/local/svn/sunny //创建一个svn版本仓库sunny(sunny可以随便起名字)
cd svn/sunny/conf //进入sunny版本仓库下的配置文件目录

下面要修改这个目录下的三个配置文件
(1)vi svnserve.conf //配置版本库信息和用户文件和用户密码文件的路径、版本库路径


# anon-access = read
# auth-access = write
# password-db = passwd
//这四行,前面的#号和空格去掉(注意去掉#要顶格写,不要留有多余空格),变成
anon-access = none //改成none
auth-access = write
password-db = passwd
realm = sunny //改成自己的版本库
保存

(2)vi authz //文件,创建svn组和组用户的权限
[group]
sunny = gep,wce //创建一个sunny的组,并指定两个用户gep和wce

[/] //制定根目录下的权限
@sunny = rw //sunny组用户权限为读写
* = r //其他用户只有读权限
保存退出

(3) vi passwd //创建或修改用户密码
[users]
gep = 123456 //用户名为gep的用户的密码为123456
wce = 123456 //。。。
保存退出


启动svn:
svnserve -d -r /usr/local/svn/ //这里采用多版本库的方式启动 如果是单版本库 可以svnserve -d -r /usr/local/svn/sunny
添加一行
然后要设置自启动
vi /etc/rc.local 打开自启动文件添加
/usr/bin/svnserve -d -r /usr/local/svn/

到此为止可以从服务端检出文件了.

svn命令:
netstat -tnl |grep :3690 查看svn是否启动
ps aux |grep 'svn' 查找所有svn启动的进程
kill -9 2505 杀死2505这个查找到的svn进程


svn checkout svn://172.19.5.2/sunny /data0/htdocs/blog //检出一份版本库文件到指定目录
svn up //更新文件

自动更新
在vi /usr/local/svn/sunny/hooks/post-commit中加入

#!/bin/sh
#设置一些变量
SVN=/usr/bin/svn
WEB=/home/testsvn #要更新的目录
export LANG=en_US.UTF-8
$SVN update $WEB --username xxx --password xxx


其中SVN=右边改成 svn 命令位置 一般默认为/usr/bin/svn
WEB=右边改成你实际的web目录
赋予可执行权限
chmod 777 /usr/local/svn/sunny/hooks/post-commit
安装完毕


=========================================================================
其他操作

#svn commit -m "注释" xxx.php //提交文件
svn ci -m'aaa' test.php //提交文件

#svn add file //新建文件并添加到svn
svn add *.php //(添加当前目录下所有的php文件)
svn delete test.php //删除test.php
svn log test.php //查看test文件的log信息
svn cleanup //清理当前目录

 

svn switch --relocate svn://192.168.1.253 svn://172.19.10.250 //重新定位SVN版本库地址


 

// SVN版本库起动方式,现在SVN下面有 sunny、test 两个版本库
1:单版本库起动 svnserve -d -r /usr/local/svn/sunny
2:多版本库起动 svnserve -d -r /usr/local/svn
区别在于起动svn时候的命令中的启动参数-r指定的目录。

限制不同的用户对不同的版本库操作权限,修改版本库中的conf目录下的 authz文件

以配置 sunny 版本库为例
vi authz
[groups]
teacher = sunny,sunny1
[sunny:/] //指定版本库跟目录下的权限
@teacher = rw //teacher组用户权限为读写
* = r //其他用户只有读权限
保存退出

vi passwd 设置组中用户的账号和密码
[users]
sunny = 123456
sunny1 = 123456

【memecache radius】


【负载均衡】

原文地址:https://www.cnblogs.com/ghjbk/p/6740322.html