(三)、LNMP的搭建,并制作rpm包
中小型规模网站集群架构:yum仓库搭建
: Ago-linux运维群:https://hankbook.cn
编译的三条命令的规则
./configure 就是在本地创建了一个Makefile文件 (也就是指定一下各种配置参数)
make 就是在执行Makefile这个文件里的内容。生成文件在源码包
make install 把make生成的文件 移动到指定的目录下面 没指定就默认/usr/local
rpm制作与yum仓库搭建,点此处
超链已经有了nginx的搭建
LNMP的搭建
1.Nginx-1.10.2搭建
#1.安装依赖包
yum install -y pcre-devel openssl-devel
#2.下载源码包
wget http://nginx.org/download/nginx-1.10.2.tar.gz
#3.创建www用户
useradd -s /sbin/nologin -M www
#4.编译安装
./configure --user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module --with-http_ssl_module
make
make install
#5.创建软链
ln -s nginx-1.10.2/ nginx
2.php-5.5.32搭建
cd /server/files
#1.安装依赖包
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel curl-devel openssl-devel -y
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y
#2.安装字符集转换库---libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
#3.安装其它相关程序---libmcrypt
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install libmcrypt-devel mhash mcrypt
rpm -qa libmcrypt-devel mhash mcrypt
#4.编译安装
wget http://tw1.php.net/distributions/php-5.5.32.tar.gz
tar xf php-5.5.32.tar.gz
cd php-5.5.32
./configure --prefix=/application/php-5.5.32 \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--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 \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--enable-opcache=no
可能出现问题解决:
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
touch ext/phar/phar.phar
make && make install
ln -s /application/php-5.5.32/ /application/php
#5.配置文件的复制
cp php.ini-production /application/php/lib/php.ini
cd /application/php/etc/
cp php-fpm.conf.default php-fpm.conf
需要在本地使用mysql的话请编译时,改此参数
--with-mysql=mysql路径
3.MySQL搭建.使用二进制安装
#1.下载安装包
cd /server/files
wget http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.6/mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
#2.安装,并创建用户和授权
tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.34-linux-glibc2.5-x86_64 /application/mysql-5.6.34
ln -s /application/mysql-5.6.34/ /application/mysql
useradd mysql -M -s /sbin/nologin -u 899
chown -R mysql.mysql /application/mysql
#3.初始化数据库
cd /application/mysql
./scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/
#4.修改启动文件
\cp support-files/mysql.server /etc/init.d/mysqld
sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysqld
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe
#5.复制配置文件并启动
\cp /application/mysql/my.cnf /etc/my.cnf
/etc/init.d/mysqld start
rpm包制作
1.php
单独打包libiconv和在php安装之前先安装一下libiconv
ini和php-fpm.conf两个文件记得先移动再打包
vi /server/scripts/after_php.sh
#!/bin/sh
ln -s /application/php-5.5.32 /application/php
fpm -s dir -t rpm -n php -v 5.5.32 -d 'libmcrypt-devel mhash mcrypt zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel curl-devel openssl-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel' --after-install /server/scripts/after_php.sh -f /application/php-5.5.32/
2.MySQL
vi /server/scripts/mysql_rpm.sh
useradd mysql -M -s /sbin/nologin -u 899
chown -R mysql.mysql /application/mysql*
cd /application/mysql
./scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/
\cp support-files/mysql.server /etc/init.d/mysqld
sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysqld
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe
#5.复制配置文件并启动
\cp /application/mysql/my.cnf /etc/my.cnf
/etc/init.d/mysqld start
fpm -s dir -t rpm -n mysql -v 5.6.34 --post-install /server/scripts/mysql_rpm.sh -f /application/mysql-5.6.34/
3.sersync制作
1-配置文件
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/>
<filter start="false">
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify>
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/data/">
<remote ip="172.16.1.41" name="nfsbackup"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-az --delete"/>
<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/var/log/rsync_fail_log.log" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>
<plugin name="command">
<param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*)\.php"/>
<include expression="(.*)\.sh"/>
</filter>
</plugin>
<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>
2脚本编写
vi /server/scripts/sersync_rpm.sh
#!/bin/sh
/usr/local/sersync/bin/sersync -d -r -o /usr/local/sersync/conf/confxml.xml
echo '/usr/local/sersync/bin/sersync -d -r -o /usr/local/sersync/conf/confxml.xml' >> /etc/rc.local
3-rpm制作
fpm -s dir -t rpm -n sersync -v 1.1 --post-install /server/scripts/sersync_rpm.sh -f /usr/local/sersync