系统优化

优化yum源:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup &&\
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
  • # -O 指定将下载的信息保存当哪个路径中
  • # epel 表示扩展的yum源

关闭selinux:

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config  #修改配置文件永久生效
grep SELINUX=disabled /etc/selinux/config    #检查一下
setenforce 0    #使用命令临时关闭
 getenforce   #查看临时关闭状态

时间同步:

echo "*/5 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1">>/var/spool/cron/root

ssh连接速度慢:

sed -i.bak 's@#UseDNS yes@UseDNS no@g;s@^GSSAPIAuthentication yes@GSSAPIAuthentication no@g' /etc/ssh/sshd_config
/etc/init.d/sshd reload #重新加载一下

开始搭建:

统一目录:

mkdir /lnmp    #项目目录
mkdir -p /server/tools  #下载的资源包目录

部署nginx项目:

安装nginx的依赖包(pcre-devel openssl-devel):

yum install -y pcre-devel openssl-devel

下载nginx软件:

cd /server/tools
wget http://nginx.org/download/nginx-1.10.3.tar.gztar xf nginx-1.10.3.tar.gz

创建nginx启动用户(www)

useradd www -s /sbin/nologin -M    # -s /sbin/nologin 创建的是傀儡用户(不能登录服务器)  

编译安装nginx

解压要编译安装的软件(解压软件—配置(./configure)—做菜(编译 make)—上菜(安装 make install))

tar xf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure --prefix=/lnmp/nginx-1.10.3 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
make && make install
  •        –prefix: 表示指定软件安装到哪个目录中,指定目录不存在会自动创建
  •        –user/–group: nginx工作进程由哪个用户运行管理
  •        –with-http_stub_status_module:  启动nginx状态模块功能(用户访问nginx的网络信息)
  •        –with-http_ssl_module:         启动https功能模块

测试nginx软件程序

ln -s /lnmp/nginx-1.10.3 /lnmp/nginx     # 创建软连接
启动nginx软件程序进行测试
/lnmp/nginx/sbin/nginx
lsof -i:80 #查看端口(nginx默认80)

检测: 浏览器打上IP地址 或者是域名

mysql编译安装:

下载mysql资源包:

cd /service/tools
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz
tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz
mv mysql-5.5.49-linux2.6-x86_64 /lnmp/mysql-5.5.49
ln -s /lnmp/mysql-5.5.49/ /lnmp/mysql

创建用户和授权目录

useradd mysql -s /sbin/nologin -M   #创建mysql启动用户
chown -R mysql.mysql /lnmp/mysql/data/    #授权mysql用户权限

初始化时数据库

cd /lnmp/mysql/scripts
./scripts/mysql_install_db --user=mysql --basedir=/lnmp/mysql --datadir=/lnmp/mysql/data/    #初始化数据库

创建基本需求

cd  /lnmp/mysql
\cp support-files/my-small.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
sed -i 's#/usr/local/mysql#/lnmp/mysql#g' /lnmp/mysql/bin/mysqld_safe /etc/init.d/mysqld

开启服务、检查

/etc/init.d/mysqld start             # 启动mysql
netstat -lntup|grep mysql
echo "PATH="/lnmp/mysql/bin:$PATH"" >>/etc/profile   #添加变量
source /etc/profile                       #变量生效
which mysql
chkconfig --add mysqld           #开机自启
chkconfig mysqld on

检查:命令行输入mysql进入数据库

 

安装PHP

安装PHP基础库

yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y

检查:rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel

下载安装

cd /service/tools/     #需要先安装支持的软件包
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

PHP相关扩展库

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install libmcrypt-devel
yum -y install mhash
yum -y install mcrypt
yum -y install libmcrypt-devel

检查:rpm -qa libmcrypt-devel mhash mcrypt
——————————-

解压php安装包,编辑

useradd www -s /sbin/nologin -M
cd /service/tools
tar xf php-5.5.32.tar.gz

编译安装php

cd /service/tools/ php-5.5.32
./configure \
--prefix=/lnmp/php5.5.32 \
--with-mysql=/lnmp/mysql/ \
--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 /lnmp/mysql/lib/libmysqlclient.so.18 /usr/lib64/
echo '/application/mysql/lib' >>/etc/ld.so.conf && ldconfig
make
make install
ln -s /lnmp/php5.5.32/ /lnmp/php   #软链接

配置php解析文件

cp php.ini-production /lnmp/php/lib/php.ini

配置php-fpm配置文件

cd /lnmp/php/etc
cp php-fpm.conf.default php-fpm.conf

启动php及检查

nginx结合PHP (修改部分为紫色)

server {
listen 80;
server_name baidu.com;
location / {
root html/blog;
index index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}

重启nginx

nginx -t     #检查配置文件
主要是看这个successful
nginx -s reload   #重启nginx

添加检测php页面

cd /lnmp/nginx/html/blog/
echo "<?php phpinfo(); ?>" >index.php

测试php和mysql是否可以通信

cat mysql.php 
<?php
$link_id=mysql_connect('localhost','root') or mysql_error();
if($link_id){
echo "mysql successful by baby !";
}else{
echo mysql_error();
}
?> 

测试IP地址/mysql.php访问:
mysql successful by baby !

 

 

 

2 Replies to “lnmp编译安装lnmp (centos6.9)”

发表评论

电子邮件地址不会被公开。 必填项已用*标注