练习:远程连接客户机安装php+tengine,
一、需要用到脚本8获取远程ip以及推送公钥到远程机器。
二、创建如下目录结构
1.lnmp.sh
------------------------------------------------------
lnmp
├── conf
│ ├── index.php
│ ├── nginx.conf
│ └── php-fpm.conf
├── include
│ ├── config.sh
│ ├── init_os.sh
│ ├── nginx_install.sh
│ └── php_install.sh
├── installrc
├── lnmp.sh
└── src
├── php-7.2.6.tar.bz2
└── tengine-2.3.0.tar.gz
三、分别编写脚本
#!/bin/bash
#####lnmp main program
###2019-6-8######
soft_dir=`pwd`/src
config_dir=`pwd`/conf
cpus=`lscpu|awk '/^CPU\(s\)/{print $2}'`
. installrc
. include/init_os.sh
. include/nginx_install.sh
. include/php_install.sh
. include/config.sh
init_os
nginx_install
php_install
config
2.init_os.sh
#!/bin/bash
#### init os #########
###yum########
init_os(){
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum make cache && yum repolist
####SELinux########
systemctl disable firewalld
systemctl stop firewalld
#firewall-cmd --permanent --add-service=http
#firewall-cmd --permanent --add-service=https
#firewall-cmd --reload
setenforce 0
sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
#NTP
yum -y install chrony
sed -ri '/3.CentOS.pool.ntp.oeg/a\server pool.ntp.org iburst prefer' /etc/chrony.conf
systemctl start chronyd
systemctl enable chronyd
}
3.nginx_install.sh
#!/bin/bash
#
#tengine install scripts
#by Dan Chen 2019-6-8
nginx_install(){
yum -y install gcc gcc-c++ openssl-devel pcre-devel
useradd nginx
cd $soft_dir
tar xf $tengine_version
cd ${tengine_version%.tar.gz}
./configure && make -j $cpus && make install
echo "$nginx_prefix/sbin/nginx" >> /etc/rc.local
chmod a+x /etc/rc.d/rc.local
echo "export PATH=$PATH:$nginx_prefix/sbin" >> /etc/profile
source /etc/profile
}
4.php_install.sh
#!/bin/bash
#
##php install scripts
php_install(){
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel \
libxml libxml-devel libcurl libcurl-devel libxslt-devel openssl-devel
cd $soft_dir
tar xf $php_version
cd ${php_version%.tar.bz2}
./configure --prefix=$php_prefix --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir \
--with-jpeg-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli \
--with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir \
--with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml \
--enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache \
--enable-pcntl --enable-shmop --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make -j $cpus && make install
cp $php_prefix/etc/php-fpm.conf.default $php_prefix/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod a+x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
}
5.config.sh
#!/bin/bash
#config conf
config() {
#tengine
\cp $config_dir/nginx.conf $nginx_prefix/conf/nginx.conf
\cp $config_dir/index.php $nginx_prefix/html/index.php
\cp $php_prefix/etc/php-fpm.d/www.conf.default $php_prefix/etc/php-fpm.d/www.conf
$nginx_prefix/sbin/nginx
/etc/init.d/php-fpm start
}
6.installrc
#!/bin/bash
#config conf
config() {
#tengine
\cp $config_dir/nginx.conf $nginx_prefix/conf/nginx.conf
\cp $config_dir/index.php $nginx_prefix/html/index.php
\cp $php_prefix/etc/php-fpm.d/www.conf.default $php_prefix/etc/php-fpm.d/www.conf
$nginx_prefix/sbin/nginx
/etc/init.d/php-fpm start
}
总结:
1.本例主要是使用shell函数,在主程序lnmp.sh入口中调用函数,安装过程大概20分钟左右
2.本例未安装mysql数据库,原因是一般mysql是单独安装在多台高配置服务器并做成集群更好一点,有兴趣的朋友可以尝试完成mysql集群的搭建。
运行结果:
[root@Node1 etc]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*