LNMP源码安装和一键安装

LNMP的源码安装步骤:(以及一键安装O(∩_∩)O)
#!/bin/bash
cd $HOME

yum -y install gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel pcre pcre-devel libmcrypt libmcrypt-devel cmake bison

#nginx-1.13
wget http://nginx.org/download/nginx-1.13.9.tar.gz
如果报command not fond的话,执行 yum install wget
#php-5.6
wget http://php.net/get/php-5.6.34.tar.gz/from/this/mirror
#redis4.0
wget http://download.redis.io/releases/redis-4.0.8.tar.gz

for i in ls .
do
echo 解压$i
tar -zxvf $i >> /dev/null
rm -f $i
done

#安装msyql
源码安装mysql的步骤(在CentOS6.9)
1.安装编译代码所需要的包
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
2.下载mysql的安装包
wget http://www.mysql.com/Downloads/MySQL-5.6/mysql-5.6.26.tar.gz
如果提示你没有装wget的话就运行 yum install wget
3.解压mysql的安装包
tar zxvf mysql-5.6.26.tar.gz
4.切换到解压后的目录里
cd mysql-5.6.26
5.编译安装(这是一条命令)
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/usr/local/mysql/data
-DSYSCONFDIR=/etc
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci

然后执行 make && make install
6.配置mysql
创建mysql用户及用户组
groupadd mysql
useradd -g mysql mysql
7.修改/usr/local/mysql权限
chown -R mysql:mysql /usr/local/mysql
8.进入mysql的安装目录
cd /usr/local/mysql
9.初始化配置脚本,创建系统自带的数据库和表(把/etc目录下的my.cnf删除)
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
如果报错-bash: scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory
就执行:yum -y install perl perl-devel
10.启动mysql
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start
11.配置用户
MySQL启动成功后,root默认没有密码,我们需要设置root密码。
设置之前,我们需要先设置PATH,要不不能直接调用mysql
修改/etc/profile文件,在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
export PATH

关闭文件,运行下面的命令,让配置立即生效
source /etc/profile
12.设置mysql密码
mysql -uroot
mysql> SET PASSWORD = PASSWORD(‘123456’);
13.配置防火墙(我是在本地的虚拟机上安装的所以直接给关闭了service iptables stop)
防火墙的3306端口默认没有开启,若要远程访问,需要开启这个端口
打开/etc/sysconfig/iptables
在“-A INPUT –m state --state NEW –m tcp –p –dport 22 –j ACCEPT”,下添加:
-A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT

然后保存,并关闭该文件,在终端内运行下面的命令,刷新防火墙配置:
service iptables restart

#安装php
useradd -M -s /sbin/nologin php
cd $HOME/php-5.6.34
./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
–with-pdo-mysql
–with-iconv
–with-freetype-dir
–with-jpeg-dir
–with-png-dir
–with-gd
–with-libxml-dir
–with-openssl
–with-iconv
–with-curl --with-bz2 --with-zlib --with-mhash
–enable-mbstring=all
–enable-sockets
–enable-mbstring
–enable-fpm
–enable-xml

make
make install
cp php.ini-development /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
sed -i s/user\ =\ nobody/user\ =\ php/g php-fpm.conf
sed -i s/group\ =\ nobody/group\ =\ php/g php-fpm.conf
ln -s /usr/local/php/sbin/php-fpm /usr/sbin/php-fpm
ln -s /usr/local/php/bin/php /usr/local/bin/php
/usr/local/php/sbin/php-fpm
echo /usr/local/lnmp/php/sbin/php-fpm >> /etc/rc.local

#redis
cd $HOME/redis-4.0.8
make
make prefix=/usr/local/redis install

#nginx
useradd -M -s /sbin/nologin nginx
cd $HOME/nginx-1.13.9
./configure --prefix=/usr/local/nginx
–user=www --group=www
–with-http_ssl_module
–with-http_gzip_static_module
make
make install
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
sed -i s/#user\ \ nobody/user\ \ nginx/g /usr/local/nginx/conf/nginx.conf
nginx

当然也可以选择意见安装包
友情链接:https://lnmp.org/install.html
个人认为其实都一样,只是编译安装显得逼格很高,一般情况下是都差不多的

你可能感兴趣的:(笔记)