uclund 部署架设环境
cp /etc/resolv.conf /etc/resolv.conf.bak
yum update -y
yum -y install gcc gcc-c++ autoconf cmake libjpeg libg libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-deves-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-idn-devel openssl openssl-devel openldap openldap-devel nss_ldclients openldap-servers gd gd2 gd-devel gd2-devel perl-CPAN ncurses-devel bison bison-devel bzip2-devel libxslt-devel zip unzip
reboot
//网卡绑定多个内网和外网 ucloud.cn下
cd /etc/sysconfig/network-scripts
cp ifcfg-eth0 ifcfg-eth0:1
vim ifcfg-eth0
DEVICE=eth0 IPADDR=$Publick_IP NETMASK=255.255.255.255 BOOTPROTO=none PEERDNS=yes USERCTL=no NM_CONTROLLED=no ONBOOT=yes
vim ifcfg-eth0:1 其实这部不用操作 默认就是原来的内网配置
DEVICE=eth0:1 HWADDR=原配置中的mac地址 IPADDR=原配置的内网ip地址 NETMASK=255.255.0.0 BOOTPROTO=none PEERDNS=yes USERCTL=no NM_CONTROLLED=no ONBOOT=yes DNS1=原配置 DNS2=原配置 DNS3=原配置
vim route-eth0
10.0.0.0/8 via 10.9.0.1
default via 10.9.0.1 src $Public_IP
service network restart
vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
添加iptables规则:
iptables -t nat -A PREROUTING ! -s 10.0.0.0/8 -d 内网ip/32 -j DNAT --to-destination $Publick_IP
iptables -t nat -A POSTROUTING -s 外网ip/32 -j SNAT --to-source 内网ip
umount /dev/vdb
fdisk -l
fdisk /dev/vdb
n
p
1
[enter]
[enter]
w
去掉vdb1的自动加载
vim /etc/fstab
mkdir /web
mkfs.ext3 /dev/vdb1
vim /etc/fstab
/dev/vdb1 /web ext3 defaults 0 0
mount -a
安装MysqL-5.6.26
创建MysqL用户和组
groupadd MysqL
useradd -g MysqL -s /usr/sbin/nologin MysqL
mkdir -p /web/MysqL/data
mkdir -p /web/MysqL/logs
mkdir -p /usr/local/MysqL
chown -R MysqL:MysqL /usr/local/MysqL
chown -R MysqL:MysqL /web/MysqL
编译安装MysqL
tar zxvf MysqL-5.6.26.tar.gz
cd MysqL-5.6.26
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \
-DMysqL_DATADIR=/web/MysqL/data \
-DSYSCONFDIR=/etc \
-DMysqL_UNIX_ADDR=/tmp/MysqL.sock \
-DMysqL_TCP_PORT=3306 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0
make && make install
============可能遇到的编译错误===========
出现函数gets错误的
解决办法:
rm -f CMakeCache.txt
yum -y install ncurses-devel
修改配置文件
cp./support-files/my-medium.cnf/etc/my.cnf
vi/etc/my.cnf
输入以下内容(可以先清空默认内容):
[MysqLd]
datadir=/web/MysqL/data
socket=/tmp/MysqL.sock
user=MysqL
symbolic-links=0
[MysqLd_safe]
log-error=/web/MysqL/logs/MysqLd.log
pid-file=/web/MysqL/MysqLd.pid
user=MysqL
tmpdir=/tmp
or
cp /web/lanmp/my.cnf /etc/my.cnf
初始化数据库
/usr/local/MysqL/scripts/MysqL_install_db \
--user=MysqL \
--basedir=/usr/local/MysqL \
--datadir=/web/MysqL/data
配置开机自启动
cp ./support-files/MysqL.server /etc/init.d/MysqLd
chmod +x /etc/init.d/MysqLd
chkconfig --add MysqLd
chkconfig MysqLd on
添加MysqL的软链接以适应init脚本
ln -sv /usr/local/MysqL/bin/MysqL /usr/sbin/MysqL
ln -sv /usr/local/MysqL/bin/MysqLadmin /usr/sbin/MysqLadmin
ln -sv /usr/local/MysqL/bin/MysqLdump /usr/sbin/MysqLdump
启动MysqL
service MysqLd start#或/etc/init.d/MysqLdstart
修改root密码:
MysqLadmin -uroot password '新密码'
MysqL -uroot -p
输入新密码
create user 'duigou'@'%' identified by '密码'
create user 'duigou'@'localhost' identified by '密码'
create database duigou default character set utf8mb4 collate utf8mb4_general_ci;
grant all privileges on duigou.* to 'duigou'@'%' identified by '密码';
grant all privileges on duigou.* to 'duigou'@'localhost' identified by '密码';
======================================================================================
或者重新配置一个超级管理员并删除root
GRANTALLPRIVILEGESON.TO'admin'@'localhost'IDENTIFIEDBY'12345678';
GRANTALLPRIVILEGESON.TO'admin'@'127.0.0.1'IDENTIFIEDBY'12345678';
DELETEFROMuserWHEREuser!='admin';#删除原先默认的用户,仅保留新建的admin用户
第三步:安装Nginx-1.8.0
添加www用户和组、创建网站虚拟目录
groupadd www
useradd -g www -s /usr/sbin/nologin www
mkdir -p /web/htdocs/www
chmod +w /web/htdocs/www
chown -R www:www /web/htdocs/www
mkdir -p /web/htdocs/logs
chmod +w /web/htdocs/logs
chown -R www:www /web/htdocs/logs
安装Nginx所需的pcre库
tar zxvf pcre-8.37.tar.gz
cd pcre-8.37
./configure
make && make install
ln -s /usr/local/lib/libpcre.so.1 /usr/lib64/libpcre.so.1
cd ..
安装Nginx-1.8.0
tar zxvf Nginx-1.8.0.tar.gz
cd Nginx-1.8.0
./configure \
--user=www \
--group=www \
--prefix=/usr/local/Nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module
make && make install
创建Nginx配置文件和创建fcgi.conf文件
cp -f /web/lanmp/Nginx.conf.uclound /usr/local/Nginx/conf/Nginx.conf
cp -f /web/lanmp/fastcgi.conf /usr/local/Nginx/conf/fastcgi.conf
启动Nginx
ulimit -SHn 65535
/usr/local/Nginx/sbin/Nginx 直接启动
配置开机自启动
cp /web/lanmp/initd/Nginx /etc/init.d/Nginx
chmod +x /etc/init.d/Nginx
chkconfig Nginx on
service Nginx start|stop|restart|reload
第四步:安装PHP5.5.13
cd ..
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local
make && make install
=====================================================================
编译libiconv解决./stdio.h:1010:1: 错误: ‘gets’未声明(不在函数内)
cd srclib/
sed -i -e '/gets is a security/d' ./stdio.in.h
cd ../
make
make install
cd ..
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7/
./configure
make && make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
cd ..
cd ..
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make && make install
对共享库做符号链接
ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
ln -s /usr/local/MysqL/lib/libMysqLclient.so.18 /usr/lib64/libMysqLclient.so.18
cd ..
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make && make install
=====================================================================
遇到问题:configure: error: * libmcrypt was not found
继续查找,还是变量的问题
解决方法如下:运行
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
安装PHP:
cd ..
tar zxvf PHP-5.6.11.tar.gz
cd PHP-5.6.11
./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 \
--enable-fpm \
--enable-calendar \
--enable-dba \
--enable-wddx \
--enable-opcache \
--with-fpm-user=PHP-fpm \
--with-fpm-group=PHP-fpm \
--with-MysqL=MysqLnd \
--with-MysqL-sock=/tmp/MysqL.sock \
--with-libxml-dir=/usr \
--with-xsl \
--with-gd \
--with-bz2 \
--with-kerberos \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-sockets \
--enable-zip \
--enable-posix \
--enable-pcntl \
--enable-mbstring \
--enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf \
--with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap \
--enable-mbregex \
--enable-sysvsem \
--enable-sockets \
--enable-shmop \
--enable-bcmath \
--enable-xml \
--enable-exif \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl \
--with-pdo-MysqL \
--enable-magic-quotes \
--disable-fileinfo \
注:如果内存较大 可以去掉--disable-fileinfo
======================================================
configure: error: Please reinstall the BZip2 distribution
yum install bzip2-devel.x86_64 -y
error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install libxslt-devel -y
make ZEND_EXTRA_LIBS='-liconv'
make
如果直接make出错make: * [sapi/cli/PHP] Error 1
make ZEND_EXTRA_LIBS='-liconv'
make install
PHP.ini设置
cp /web/lanmp/PHP.ini /usr/local/PHP/etc/PHP.ini
cp /web/lanmp/PHP-fpm.conf /usr/local/PHP/etc/PHP-fpm.conf
fpm加入自启动
cp /web/lanmp/initd/PHP-fpm /etc/init.d/PHP-fpm
chmod +x /etc/init.d/PHP-fpm
chkconfig PHP-fpm on
service PHP-fpm start|stop|restart|reload
vi /etc/rc.local
输入
ulimit -SHn 65535
以上简单部署 下面是增加部分的扩展和优化
编译PHP扩展模块memcache、pdo_MysqL、imagick
tar zxvf memcache-3.0.8.tgz
cd memcache-3.0.8
/usr/local/PHP/bin/PHPize
./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config
出错出现configure: error: MysqL_query missing!? 解决方法 ./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config --with-pdo-MysqL=/usr/local/MysqL
make出错
make && make install
cd ../
tar zxvf PDO_MysqL-1.0.2.tgz
cd PDO_MysqL-1.0.2/
/usr/local/PHP/bin/PHPize
./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config --with-pdo-MysqL=/usr/local/MysqL
ln -s /usr/local/MysqL/include/* /usr/local/include/
make
make install
cd ../
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../
tar zxvf imagick-3.2.0RC1.tgz
cd imagick-3.2.0RC1
/usr/local/PHP/bin/PHPize
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config
make
make install
cd ../
修改PHP.ini配置文件
vi /usr/local/PHP/etc/PHP.ini
查找; extension_dir = "/" 将前面的;去掉并修改为
extension_dir = "/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20121212/"
并加入
extension=memcache.so
extension=pdo_MysqL.so
extension=imagick.so
执行下面的命令使配置文件立即生效:
kill -USR2 cat /usr/local/PHP/var/run/PHP-fpm.pid
其他(可选):
优化linux内核参数
vi /etc/sysctl.conf
Add
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535
使配置立即生效:
/sbin/sysctl -p
安装opcache(因为PHP 5.5已经集成Zend Opcache,可以替代eaccelerator)
tar zxvf zendopcache-7.0.3.tgz
cd zendopcache-7.0.3
/usr/local/PHP/bin/PHPize
./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config
make
make install
cd ../
在PHP.ini中加入下面配置:
[opcache]
zend_extension="/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20121212/opcache.so"
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
?
1
2 # 使PHP.ini配置文件立即生效
kill -USR2 cat /usr/local/PHP/var/run/PHP-fpm.pid
常用命令:
修改完PHP.ini后执行:
kill -USR2 cat /usr/local/PHP/var/run/PHP-fpm.pid
修改完Nginx.conf后执行
/usr/local/Nginx/sbin/Nginx -s reload
重启MysqL服务执行:
service MysqLd (start|stop|restart)
原文链接:https://www.f2er.com/centos/376823.html