在CentOS6上搭建LNMP环境(上)

前端之家收集整理的这篇文章主要介绍了在CentOS6上搭建LNMP环境(上)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

搭建环境:

操作系统:CentOS 6.7

Nginx软件:Nginx-1.8.1.tar.gz

MysqL软件:MysqL-5.5.51-linux2.6-x86_64.tar.gz

PHP软件:PHP-5.6.11.tar.gz

一、LNMP安装前环境准备

1、设置linux防火墙

1)在iptables上开放80,3306,443端口

[root@db ~]# vim /etc/sysconfig/iptables

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-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 443 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

[root@db ~]# service iptables restart-----重启iptables服务

2)关闭selinux防火墙

[root@db ~]# vim /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

# enforcing - SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

# targeted - Targeted processes are protected,

# mls - Multi Level Security protection.

SELINUXTYPE=targeted

[root@db ~]#setenforc 0

3)安装依赖包

[root@db ~]#yum-yinstallgccgcc-c++autoconflibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develzlibzlib-develglibcglibc-develglib2glib2-develbzip2bzip2-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrb5krb5-devellibidnlibidn-developensslopenssl-developenldapopenldap-developenldap-clientsopenldap-serversmakelibtool*gittreebisonpcre-develperlgdgd-devel

4)编译安装其他软件

A:安装libiconv软件(该软件支持编码转换为函数

[root@db software]# tar xf libiconv-1.14.tar.gz

[root@db libiconv-1.14]#./configure--prefix=/usr/local

[root@db libiconv-1.14]#make&&makeinstall

[root@db libiconv-1.14]# echo $?

0

显示0,表示软件编译安装成功了)

B:安装libmcrypt (加密算法扩展库,支持DES,3DES,RIJNDAEL,Twofish,IDEA,GOST,CAST-256,ARCFOUR,SERPENT,SAFER+等算法)

[root@db software]# tar xf libmcrypt-2.5.7.tar.gz

[root@db software]# cd libmcrypt-2.5.7

[root@db libmcrypt-2.5.7]# ./configure

[root@db libmcrypt-2.5.7]# cd libltdl/

[root@db libltdl]# ./configure --enable-ltdl-install

[root@db libltdl]# make && make install

C: 安装mhash(mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存

[root@db software]# tar xf mhash-0.9.9.9.tar.gz

[root@db software]# cd mhash-0.9.9.9

[root@db mhash-0.9.9.9]# ./configure && make && make install

D:安装mcript(mcrypt 是 PHP 里面重要的加密支持扩展库,Mcrypt扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。)

[root@db software]# tar xf mcrypt-2.6.8.tar.gz

[root@db software]# cd mcrypt-2.6.8

[root@db mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

[root@db mcrypt-2.6.8]# ./configure && make && make install

E:增加文件

[root@db software]#ln -s /usr/local/lib/libmcrypt .la /usr/lib/libmcrypt .la
.so .so
.so.4 .so.4
.so.4.4.8 .so.4.4.8
/usr/local/lib/libmhash .a /usr/lib/libmhash .a
.la
.so
.so.2 .so.2
.so.2.0.1 .so.2.0.1
/usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

F:安装cmake (MysqL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具)

[root@db ~]# yum -y install cmake


二、安装MysqL数据软件

1)创建MysqL用户

[root@db software]#groupadd -r MysqL

[root@db software]# useradd -r -g MysqL MysqL -s /sbin/nologin

2)创建MysqL的数据目录

[root@db software]# mkdir -p /data/MysqLdb

3)安装MysqL

[root@db ~]# cd /software/

[root@db software]# tar xf MysqL-5.5.51-linux2.6-x86_64.tar.gz -C /usr/local/

[root@db software]# cd /usr/local/

[root@db local]# ll

total 48

drwxr-xr-x. 2 root root 4096 Aug 18 11:46 bin

drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc

drwxr-xr-x. 2 root root 4096 Sep 23 2011 games

drwxr-xr-x. 3 root root 4096 Aug 18 11:45 include

drwxr-xr-x. 3 root root 4096 Aug 18 11:45 lib

drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64

drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec

drwxr-xr-x. 3 root root 4096 Aug 18 11:41 man

drwxr-xr-x. 13 root root 4096 Aug 18 11:55 MysqL-5.5.51-linux2.6-x86_64

drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin

drwxr-xr-x. 8 root root 4096 Aug 18 11:41 share

drwxr-xr-x. 2 root root 4096 Sep 23 2011 src

[root@db local]# ln -sv MysqL-5.5.51-linux2.6-x86_64/ MysqL

`MysqL' -> `MysqL-5.5.51-linux2.6-x86_64/'

修改MysqL目录权限

[root@db MysqL]# chown -R MysqL:MysqL .

[root@db MysqL]# cd /data/MysqLdb/

[root@db MysqLdb]# chown -R MysqL:MysqL .

初始化MysqL数据库

[root@db ~]# cd /usr/local/MysqL

[root@db MysqL]# ./scripts/MysqL_install_db --user=MysqL --datadir=/data/MysqLdb

编辑MysqL配置文件/etc/my.cnf

[MysqLd]

datadir=/data/MysqLdb

socket=/tmp/MysqL.sock

user=MysqL

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

[MysqLd_safe]

log-error=/var/log/MysqLd.log

pid-file=/var/run/MysqLd/MysqLd.pid

复制MysqL启动文件及其命令加入PATH

[root@db MysqL]# cp support-files/MysqL.server /etc/init.d/MysqLd

[root@db MysqL]# chmod +x /etc/init.d/MysqLd

[root@db MysqL]# chkconfig MysqLd on

[root@db MysqL]# vim /etc/profile.d/MysqLd.sh

PATH= /usr/local/MysqL/bin : /usr/local/MysqL/lib :$PATH

[root@db MysqL]#source/etc/profile.d/MysqL.sh

启动MysqL服务器

[root@db etc]# service MysqLd start

Starting MysqL.. [ OK ]

修改root用户的密码及授权普通用户test可以远程连接到MysqL数据库

MysqL> grant all on *.* to 'root'@'localhost' identified by 'test123';

Query OK,0 rows affected (0.00 sec)

MysqL> flush privileges;

Query OK,0 rows affected (0.00 sec)

MysqL> grant all on *.* to 'test'@'%' identified by 'test1234';

Query OK,0 rows affected (0.00 sec

原文链接:https://www.f2er.com/centos/381125.html

猜你在找的CentOS相关文章