linux企业常用服务---部署lnmp环境

部署前准备;

nginx的安装参考其他博文

本文只针对mysql+php

iptables和selinux不做配置,关掉

系统光盘作为yum源,配置yum文件

从网络获取源码包,ip地址能上网

mysql使用cmake编译安装的,先编译安装cmake

编译安装及配置mysql:

[[email protected] ~]# wget http://down1.chinaunix.net/distfiles/mysql-5.5.22.tar.gz

[[email protected] ~]# tar zxvf mysql-5.5.22.tar.gz -C /usr/src/

[[email protected] ~]# cd /usr/src/mysql-5.5.22/

[[email protected] mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc/

[[email protected] mysql-5.5.22]# make &&make install

[[email protected] mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf

cp:是否覆盖"/etc/my.cnf"? y

[email protected] mysql-5.5.22]# cp support-files/mysql.server /etc/init.d/mysqld

[[email protected] mysql-5.5.22]# chmod +x /etc/init.d/mysqld

[[email protected] mysql-5.5.22]# chkconfig --add mysqld

[[email protected] mysql-5.5.22]# echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile

[[email protected] mysql-5.5.22]# source /etc/profile

[[email protected] mysql-5.5.22]# groupadd mysql

[[email protected] mysql-5.5.22]# useradd -M -s  /sbin/nologin mysql -g mysql

[[email protected] mysql-5.5.22]# cd /usr/local/mysql/scripts/

[[email protected] scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

Installing MySQL system tables...

OK

Filling help tables...

OK

[[email protected] scripts]# cd

[[email protected] ~]# /etc/init.d/mysqld start

Starting MySQL...[确定]

[[email protected] ~]# mysqladmin -uroot password 123123

[[email protected] ~]# mysql -uroot -p123123

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.5.22-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> quit;

安装php:

[[email protected] ~]# yum -y install libxml2-devel gd-devel zlib-devel

[[email protected] ~]# wget http://cn2.php.net/distributions/php-5.4.36.tar.bz2

[[email protected] ~]# tar jxvf php-5.4.36.tar.bz2 -C /usr/src/

[[email protected] ~]# cd /usr/src/php-5.4.36/

[[email protected] php-5.4.36]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib

[[email protected] php-5.4.36]# make &&make install

[[email protected] php-5.4.36]# ls /usr/local/php5/

bin  etc  include  lib  php  sbin  var

[[email protected] php-5.4.36]# cp php.ini-development /usr/local/php5/php.ini

[[email protected] ~]# ln -s /usr/local/php5/bin/* /usr/local/bin/

[[email protected] ~]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/

安装ZendGuardLoader:

[[email protected] ~]# tar zxvf ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz

ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/

ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/

ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/ZendGuardLoader.so

ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/README.txt

[[email protected] ~]# cp ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/ZendGuardLoader.so /usr/local/php5/

[[email protected] ~]#

编辑php.ini(/usr/local/php/etc )文件,在最后位置添加以下内容:

[[email protected] ~]# vi /usr/local/php5/php.ini

[Zend Guard]

zend_extension=/usr/local/php5/ZendGuardLoader.so

; Enables loading encoded scripts. The default value is On

zend_loader.enable=1

; Optional: following lines can be added your php.ini file for ZendGuardLoader configuration

zend_loader.disable_licensing=0

zend_loader.obfuscation_level_support=3

:wq

配置nginx支持php:

[[email protected] ~]# cd /usr/local/php5/etc/

[[email protected] etc]# vi php-fpm.conf  ##新建配置文件

[global]

pid = run/php-fpm.pid

[www]

listen = 127.0.0.1:9000

user = nginx

group = nginx

pm = dynamic

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

[[email protected] ~]# /usr/local/sbin/php-fpm   ##启动php-fpm

[[email protected] ~]# netstat -utpln |grep php

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      5587/php-fpm

编写启动LNMP脚本:

[[email protected] ~]# vi /etc/init.d/lnmp

#!/bin/bash

# chkconfig: 35 95 30

# description: This script is for LNMP Management!

NGF=/usr/local/nginx/sbin/nginx

NGP=/usr/local/nginx/logs/nginx.pid

FPMF=/usr/local/php5/sbin/php-fpm

FPMP=/usr/local/php5/var/run/php-fpm.pid

case $1 in

start)

$NGF &&echo "nginx is starting! "

$FPMF && echo "php-fpm is starting! "

;;

stop)

kill -QUIT $(cat $NGP) &&echo "nginx is stoped! "

kill -QUIT $(cat $FPMP) &&echo "php-fpm is stoped! "

;;

restart)

$0 stop

$0 start

;;

reload)

kill -HUP $(cat $NGP)

kill -HUP $(cat $FPMP)

;;

status)

netstat -utpln |grep nginx &>/dev/null

if [  $? -eq 0 ]

then

echo "nginx is running! "

else

echo "nginx is not running! "

fi

netstat -upltn |grep php-fpm &>/dev/null

if [ $? -eq 0 ]

then

echo "php-fpm is runing! "

else

echo "php-fpm is not running! "

fi

;;

*)

echo "Usage $0 {start|stop|status|restart}"

exit 1

;;

esac

:wq

[[email protected] ~]# chmod +x /etc/init.d/lnmp

[[email protected] ~]# chkconfig --add lnmp

[[email protected] ~]# /etc/init.d/lnmp status

nginx is running!

php-fpm is runing!

时间: 2024-10-05 23:09:38

linux企业常用服务---部署lnmp环境的相关文章

linux企业常用服务---部署Nginx+Tomcat负载均衡集群

部署前准备: iptables和selinux不做配置,关掉 系统光盘作为yum源,配置yum文件 源码包准备jdk-7u65-linux-x64.gz apache-tomcat-7.0.54.tar.gz 注意源码包存放位置要与脚本中相互对应 环境介绍: 一台nginx,两台tomcat 分别在后端tomcat1和tomcat2上配置: [[email protected] ~]# vi install_tomcat.sh #!/bin/bash ##by linuxfan ########

linux企业常用服务---部署NGINX虚拟主机

部署前准备: 光盘配置本地yum源,修改yum配置文件 防火墙和selinux不做设置,关掉 IP地址设置为192.168.100.222 nginx已安装完成 1.安装安装并配置dns: 安装dns: [[email protected] ~]# yum install bind-utils bind bind-chroot 配置: [[email protected] ~]# cd /var/named/chroot/etc/ 配置主文件: [[email protected] etc]#

linux企业常用服务---squit传统代理

安装前准备: 本文不对iptables和selinux做设置,关掉 确保代理主机能上网 下载源码包squid-3.4.6.tar.gz 环境介绍 192.168.100.150为代理服务器,192.168.100.151为内网测试服务器(可以换xp等) 安装squid: [[email protected] network-scripts]# vi ifcfg-eth0 DEVICE=eth0 HWADDR=00:0C:29:88:f9:43 TYPE=Ethernet ONBOOT=yes N

linux企业常用服务---nfs

NFS是一种基于TCP/IP传输的网络文件系统协议,最初由SUN公司开发. 通过NFS协议,客户机可以像访问本地目录一样访问远程服务器中的共享资源. NFS得到了如NAS等网络存储的设备极好支持.也是LVS共享存储的首选. nfs相关服务 软件包:nfs-utils,rpcbind 配置文件:/etc/exports 相关命令: exportfs showmount rpcinfo mount 基本配置文件: /etc/exports / master(rw) trusty(rw,no_root

linux企业常用服务---lvs+Keepalived高可用集群

部署前准备: iptables和selinux没配置,关掉 挂载系统镜像作为本地yum源,修改yum文件 源码包准备keepalived-1.2.13.tar.gz 环境介绍: 主服务器ip:192.168.100.157(keeplived+lvs) 从服务器ip:192.168.100.156(keeplived+lvs) 节点服务器ip:192.168.100.153-192.168.100.155(httpd) 集群vip:192.168.100.95 1.安装keepalived(在两

linux企业常用服务---haproxy+nginx搭建web高可用集群

部署前准备: iptables和selinux没配置,关掉 挂载系统镜像作为本地yum源,修改yum文件 源码包准备 nginx.1.6.0.tar.gz  haproxy-1.4.24.tar.gz 实验环境描述: 两个nginx分别为192.168.100.110 and192.168.100.120 一个haproxy为192.168.100.160 1 .分别在110和120上搭建nginx yum -y install pcre-devel zlib-devel ##安装依赖包 use

linux企业常用服务---编译安装lamp及优化

安装注意: 本地光盘得挂载好需要安装一些依赖包及充当yum源: 源码包存放的位置与脚本中要一致: 使用脚本形式安装,安装前先看脚本内容,稍作调整后再进行安装: 安装mcrypt支持,安装的顺序必须libmcrypt-->mhash-->mcrypt,每安装都必须ln链接到系统库中: 防火墙和selinux先关闭最后在打开. 需提前准备好以下源码包及yum的配置 源码包: httpd-2.2.17.tar.gz    ##apache的httpd                        

linux企业常用服务---dns+ftp+dhcp

基础服务安装: [[email protected] ~]# mount /dev/cdrom /mnt mount: block device /dev/sr0 is write-protected, mounting read-only [[email protected] ~]# yum -y install vsftpd bind bind-chroot bind-utils dhcp 1.配置dhcp服务: [[email protected] ~]# vi /etc/dhcp/dhc

linux企业常用服务---编译安装nginx

网络下载nginx源码包: wget http://nginx.org/download/nginx-1.6.2.tar.gz 安装依赖: yum install pcre-devel zlib-devel  ##本地的光盘作为yum源 安装nginx: useradd -M -s /sbin/nologin nginx tar zxvf nginx-1.6.2.tar.gz -C /usr/src/ cd /usr/src/nginx-1.6.2/ [[email protected] ngi