CentOS 7 用户怎样安装 LNMP

CentOS 7 用户怎样安装 LNMP,第1张

LNMP动态网站部署架构是一套由Linux + Nginx + MySQL + PHP组成的动态网站系统解决方案。LNMP中的字母L是Linux系统的意思,不仅可以是RHEL、CentOS、Fedora,还可以是Debian、Ubuntu等系统。在使用源码包安装服务程序之前,首先要让安装主机具备编译程序源码的环境,他需要具备C语言、C++语言、Perl语言的编译器,以及各种常见的编译支持函数库程序。因此请先配置妥当Yum软件仓库,然后把下面列出的这些软件包都统统安装上:

[root@linuxprobe ~]# yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel

Loaded plugins: langpacks, product-id, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

………………省略部分安装过程………………

Installing:

apr x86_64 1.4.8-3.el7 rhel7 103 k

apr-devel x86_64 1.4.8-3.el7 rhel7 188 k

apr-utilx86_64 1.5.2-6.el7 rhel792 k

apr-util-devel x86_64 1.5.2-6.el7 rhel776 k

autoconfnoarch 2.69-11.el7 rhel7 701 k

automakenoarch 1.13.4-3.el7 rhel7 679 k

bison x86_64 2.7-4.el7 rhel7 578 k

bzip2-devel x86_64 1.0.6-12.el7 rhel7 218 k

compat-dapl x86_64 1:1.2.19-3.el7rhel7 109 k

compat-db-headers noarch 4.7.25-27.el7 rhel748 k

compat-db47 x86_64 4.7.25-27.el7 rhel7 795 k

compat-gcc-44 x86_64 4.4.7-8.el7 rhel710 M

compat-gcc-44-c++ x86_64 4.4.7-8.el7 rhel7 6.3 M

compat-glibcx86_64 1:2.12-4.el7 rhel7 1.2 M

compat-glibc-headersx86_64 1:2.12-4.el7 rhel7 452 k

compat-libcap1 x86_64 1.10-7.el7rhel719 k

compat-libf2c-34x86_64 3.4.6-32.el7 rhel7 155 k

compat-libgfortran-41 x86_64 4.1.2-44.el7 rhel7 142 k

compat-libtiff3 x86_64 3.9.4-11.el7 rhel7 135 k

compat-openldap x86_64 1:2.3.43-5.el7rhel7 174 k

cpp x86_64 4.8.2-16.el7 rhel7 5.9 M

fontconfig-develx86_64 2.10.95-7.el7 rhel7 128 k

freetype-devel x86_64 2.4.11-9.el7 rhel7 355 k

gcc x86_64 4.8.2-16.el7 rhel716 M

gcc-c++ x86_64 4.8.2-16.el7 rhel7 7.1 M

………………省略部分安装过程………………

Complete!

[root@linuxprobe ~]# cd /usr/local/src

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/cmake-2.8.11.2.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/Discuz_X3.2_SC_GBK.zip

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/freetype-2.5.3.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/jpegsrc.v9a.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/libgd-2.1.0.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/libmcrypt-2.5.8.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/libpng-1.6.12.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/libvpx-v1.3.0.tar.bz2

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/mysql-5.6.19.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/nginx-1.6.0.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/openssl-1.0.1h.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/php-5.5.14.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/pcre-8.35.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/t1lib-5.1.2.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/tiff-4.0.3.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/yasm-1.2.0.tar.gz

[root@linuxprobe src] # wget https://www.linuxprobe.com/Software/zlib-1.2.8.tar.gz

[root@linuxprobe src]# ls

zlib-1.2.8.tar.gz libmcrypt-2.5.8.tar.gz pcre-8.35.tar.gz

cmake-2.8.11.2.tar.gz libpng-1.6.12.tar.gzphp-5.5.14.tar.gz

Discuz_X3.2_SC_GBK.zip libvpx-v1.3.0.tar.bz2 t1lib-5.1.2.tar.gz

freetype-2.5.3.tar.gz mysql-5.6.19.tar.gz tiff-4.0.3.tar.gz

jpegsrc.v9a.tar.gz nginx-1.6.0.tar.gz yasm-1.2.0.tar.gz

libgd-2.1.0.tar.gz openssl-1.0.1h.tar.gz

CMake是Linux系统中一款常用的编译工具。要想通过源码包安装服务程序,就一定要严格遵守上面总结的安装步骤—下载及解压源码包文件、编译源码包代码、生成二进制安装程序、运行二进制的服务程序安装包。接下来在解压、编译各个软件包源码程序时,都会生成大量的输出信息,下文中将其省略,请读者以实际 *** 作为准。

[root@linuxprobe src]# tar xzvf cmake-2.8.11.2.tar.gz

[root@linuxprobe src]# cd cmake-2.8.11.2/

[root@linuxprobe cmake-2.8.11.2]# ./configure

[root@linuxprobe cmake-2.8.11.2]# make

[root@linuxprobe cmake-2.8.11.2]# make install

20.2.1 配置Mysql服务

[root@linuxprobe cmake-2.8.11.2]# cd ..

[root@linuxprobe src]# useradd mysql -s /sbin/nologin

创建一个用于保存MySQL数据库程序和数据库文件的目录,并把该目录的所有者和所属组身份修改为mysql。其中,/usr/local/mysql是用于保存MySQL数据库服务程序的目录,/usr/local/mysql/var则是用于保存真实数据库文件的目录。

[root@linuxprobe src]# mkdir -p /usr/local/mysql/var

[root@linuxprobe src]# chown -Rf mysql:mysql /usr/local/mysql

接下来解压、编译、安装MySQL数据库服务程序。在编译数据库时使用的是cmake命令,其中,-DCMAKE_INSTALL_PREFIX参数用于定义数据库服务程序的保存目录,-DMYSQL_DATADIR参数用于定义真实数据库文件的目录,-DSYSCONFDIR则是定义MySQL数据库配置文件的保存目录。由于MySQL数据库服务程序比较大,因此编译的过程比较漫长,在此期间可以稍微休息一下。

[root@linuxprobe src]# tar xzvf mysql-5.6.19.tar.gz

[root@linuxprobe src]# cd mysql-5.6.19/

[root@linuxprobe mysql-5.6.19]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/var -DSYSCONFDIR=/etc

[root@linuxprobe mysql-5.6.19]# make

[root@linuxprobe mysql-5.6.19]# make install

[root@linuxprobe mysql-5.6.19]# rm -rf /etc/my.cnf

[root@linuxprobe mysql-5.6.19]# cd /usr/local/mysql

[root@linuxprobe mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var

把系统新生成的MySQL数据库配置文件链接到/etc目录中,然后把程序目录中的开机程序文件复制到/etc/rc.d/init.d目录中,以便通过service命令来管理MySQL数据库服务程序。记得把数据库脚本文件的权限修改成755以便于让用户有执行该脚本的权限:

[root@linuxprobe mysql]# ln -s my.cnf /etc/my.cnf

[root@linuxprobe mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

[root@linuxprobe mysql]# chmod 755 /etc/rc.d/init.d/mysqld

编辑刚复制的MySQL数据库脚本文件,把第46、47行的basedir与datadir参数分别修改为MySQL数据库程序的保存目录和真实数据库的文件内容。

[root@linuxprobe mysql]# vim /etc/rc.d/init.d/mysqld

………………省略部分输出信息………………

39 #

40 # If you want to affect other MySQL variables, you should make your changes

41 # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

42

43 # If you change base dir, you must also change datadir. These may get

44 # overwritten by settings in the MySQL configuration files.

45

46 basedir=/usr/local/mysql 47 datadir=/usr/local/mysql/var

48

………………省略部分输出信息………………

[root@Linuxprobe mysql]# service mysqld start

Starting MySQL. SUCCESS!

[root@linuxprobe mysql]# chkconfig mysqld on

[root@linuxprobe mysql]# vim /etc/profile

………………省略部分输出信息………………

64

65 for i in /etc/profile.d/*.sh do

66 if [ -r "$i" ]then

67 if [ "${-#*i}" != "$-" ]then

68 . "$i"

69 else

70 . "$i" >/dev/null

71 fi

72 fi

73 done

74 export PATH=$PATH:/usr/local/mysql/bin

75 unset i

76 unset -f pathmunge

[root@linuxprobe mysql]# source /etc/profile

[root@linuxprobe mysql]# mkdir /var/lib/mysql

受限制,没办法全部搬运,可百度 免费电子书 linux就该这么学,第20章,复制文章中的命令来安装

1、安装cmake

tar zxf untar/cmake-2.8.8.tar.gz

pushd cmake-2.8.8

./bootstrap &&gmake &&gmake install

popd

2、创建用户

groupadd mysql

useradd -g mysql mysql

mkdir -p /usr/local/mysql

mkdir -p /var/lib/mysql

chown -R mysql.mysql /usr/local/mysql

chown -R mysql.mysql /var/lib/mysql

3、安装mysql

tar zxf untar/mysql-5.6.12.tar.gz

pushd mysql-5.6.12

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS:STRING=all \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=/var/lib/mysql \

-DMYSQL_USER=mysql

make

make install

4、启动脚本和配置文件

cp /opt/LNMP/mysql-5.6.12/support-files/my-default.cnf /usr/local/mysql/my.cnf

cp /opt/LNMP/mysql-5.6.12/support-files/mysql.server /etc/init.d/mysqld

5、初始化mysql

cd /usr/local/mysql

./scripts/mysql_install_db –datadir=/var/lib/mysql –user=mysql

6、启动mysql

chmod +x /etc/init.d/mysqld

chkconfig mysqld on

/etc/init.d/mysqld start

7、设置root密码

./bin/mysqladmin -u root password ‘123456’

8、检查端口

netstat -ntlp |grep 3306

9、删除不必要的用户

mysql -uroot -p123456 -e”drop user ”@’localhost'”

mysql -uroot -p123456 -e”drop user ”@’`hostname`'”

mysql -uroot -p123456 -e”drop user ‘root’@’`hostname`'”

mysql -uroot -p123456 -e”drop user root@’::1′”

10、#创建数据库

mysql -uroot -p123456 -e”create database db01”

#创建用户

mysql -uroot -p123456 -e”CREATE USER ‘user01’@’localhost’ IDENTIFIED BY ‘123456’”

mysql -uroot -p123456 -e”GRANT ALL ON db01.* TO ‘user01’@’localhost’”


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9713853.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存