liunx搭建配置

 

预安装准备工具
yum -y install gcc gcc-c++ wget cmake


安装
软件存放目录: /lnmp/
软件安装目录: /usr/local/

1.下载安装PCRE
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz/wget https://sourceforge.net/projects/pcre/files/pcre/8.42/pcre-8.42.tar.gz/download

tar -zxvf pcre-8.42.tar.gz
cd /lnmp/pcre-8.42
./configure --prefix=/usr/local/pcre
make && make install

2.下载安装zlib
wget https://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd /lnmp/zlib-1.2.11
./configure --prefix=/usr/local/zlib
make && make install

3.下载安装openssl
wget https://www.openssl.org/source/old/1.1.0/openssl-1.1.0b.tar.gz
tar -zxvf openssl-1.1.0b.tar.gz
cd /lnmp/openssl-1.1.0b
./config -fPIC --prefix=/usr/local/openssl/ enable-shared && make && make install
make && make install
说明:
--prefix:指定安装目录
-fPIC:编译openssl的静态库
enable-shared:编译动态库

4.安装nginx
4-1:创建nginx用户和用户组
groupadd -r www
useradd -r -g www www
4-2:下载安装nginx
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar -zxvf nginx-1.12.2.tar.gz
cd /lnmp/nginx-1.12.2
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-
path=/usr/local/nginx/nginx.pid --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_stub_status_module --with-
select_module --with-poll_module --error-log-path=/web/logs/nginx/error.log --http-log-path=/web/logs/nginx/access.log --with-pcre=/lnmp/pcre-8.42 --with-
zlib=/lnmp/zlib-1.2.11 --with-openssl=/lnmp/openssl-1.1.0b
make && make install

configure的安装配置参数说明:
--prefix : nginx的安装路径,这里的安装路径为/usr/local/nginx
--sbin-path : nginx的可执行文件存放路径
--conf-path : nginx的主配置文件存放路径,nginx允许使用不同的配置文件启动,通过命令行中的-c选项
--pid-path : nginx.pid文件的存放路径,将存储的主进程的进程号
--error-log-path : nginx的主错误、警告、和诊断文件存放路径,这里的存放路径为 /web/logs/nginx/error.log
--http-log-path : nginx的主请求的HTTP服务器的日志文件的存放路径,这里的存放路径为 /web/logs/nginx/access.log
--user : nginx工作进程的用户
--group : nginx工作进程的用户组
--with-select_module或--without-select_module : 启用或禁用构建一个模块来允许服务器使用select()方法
--with-poll_module或--without-poll_module : 启用或禁用构建一个模块来允许服务器使用poll()方法
--with-http_ssl_module : 使用https协议模块。默认情况下,该模块没有被构建。建立并运行此模块的OpenSSL库是必需的
--with-pcre : pcre的源码路径,这里的源码路径为 /lnmp/pcre-8.42
--with-zlib : zlib的源码路径,这里的源码路径为 /lnmp/zlib-1.2.11
--with-openssl : openssl库的源码路径,这里的源码路径为 /lnmp/openssl-1.1.0b

4-3.启动nginx
/usr/local/nginx/sbin/nginx

4-4.加入环境变量
使用vim命令打开/etc/profile文件,在文件最末尾加上如下代码
export PATH=$PATH:/usr/local/nginx/sbin
保存后执行 source /etc/profile
4-5.设置开机自启动
vim /etc/init.d/nginx(脚本地址:https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/)
就该脚本的以下两个地方:
nginx="/usr/sbin/nginx"
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
修改为:
nginx="/usr/local/nginx/sbin/nginx"
NGINX_CONF_FILE="/usr/local/nginx/nginx.conf"
赋权限,设置开机启动:
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on

5.安装PHP(5.6版)(后台语言1)
5-1.安装PHP相关依赖扩展和常用库
yum -y install libmcrypt-devel mhash-devel 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 krb5-devel libidn
libidn-devel openssl openssl-devel

5-2.下载安装Libmcrypt
wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd /lnmp/libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt
make && make install
5-3.安装libltdl
cd /lnmp/libmcrypt-2.5.8/libltdl
./configure --enable-ltdl-install
make && make install

5-4.下载安装PHP
wget http://am1.php.net/distributions/php-5.6.39.tar.gz
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mcrypt=/usr/local/libmcrypt/ --enable-fpm --enable-
mbstring --enable-pdo --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-
sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysqli --with-gd --with-jpeg-dir --with-freetype-dir --enable-calendar --
enable-opcache=no

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mcrypt=/usr/local/libmcrypt/ --with-zlib-dir --with-
freetype-dir --enable-mbstring --with-libxml-dir --enable-soap --enable-calendar --with-curl --with-gd --disable-rpath --enable-inline-optimization --with-bz2 --with-
zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --
with-pdo-mysql --with-mysqli --with-jpeg-dir --with-png-dir --with-openssl --enable-opcache --enable-fpm --with-iconv --enable-mysqlnd --with-mysqli=mysqlnd --with-
pdo-mysql=mysqlnd

make && make install

configure各种报错解决方案
(1):configure: error: Don’t know how to define struct flock on this system, set –enable-opcache=no
解决: vim /etc/ld.so.conf,在文件后面追加
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
/usr/local/libmcrypt/lib
保存后执行 ldconfig ,如何再重新configure

5-5.配置PHP配置文件
cp /lnmp/php-5.6.39/php.ini-development /usr/local/php/etc/php.ini

5-6.配置php-fpm文件
复制配置文件:
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
配置php-fpm:
#开启pid ,去掉分号注释
pid = run/php-fpm.pid
启动:
/usr/local/php/sbin/php-fpm
5-7.加入环境变量
vim /etc/profile:
export PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin
source /etc/profile
5-8.将php-fpm加入系统服务
vim /etc/init.d/php-fpm(脚本如下)

#!/bin/bash
# php-fpm startup script for the php-fpm
# php-fpm version:5.6.39
# chkconfig: - 85 15
# description: php-fpm
# processname: php-fpm
# pidfile: /usr/local/php/var/run/php-fpm.pid
# config: /usr/local/php/etc/php-fpm.conf

php_command=/usr/local/php/sbin/php-fpm
php_config=/usr/local/php/etc/php-fpm.conf
php_pid=/usr/local/php/var/run/php-fpm.pid
RETVAL=0
prog="php-fpm"

#start function
php_fpm_start() {
/usr/local/php/sbin/php-fpm
}

start(){
if [ -e $php_pid ]
then
echo "php-fpm already start..."
exit 1
fi
php_fpm_start
}

stop(){
if [ -e $php_pid ]
then
parent_pid=`cat $php_pid`
all_pid=`ps -ef | grep php-fpm | awk '{if('$parent_pid' == $3){print $2}}'`
for pid in $all_pid
do
kill $pid
done
kill $parent_pid
fi
exit 1
}

restart(){
stop
start
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|status}"
exit 1
esac
exit $RETVAL


chmod +x /etc/init.d/php-fpm

5-9.设置php-fpm开机启动
chkconfig --add php-fpm
chkconfig php-fpm on
5.安装nodejs(5.6版)(后台语言2)
1、去官网下载和自己系统匹配的文件:

英文网址:https://nodejs.org/en/download/

中文网址:http://nodejs.cn/download/

通过 uname -a 命令查看到我的Linux系统位数是64位(备注:x86_64表示64位系统, i686 i386表示32位系统),如图

 

故下载一下红色框中文件 ,版本为v12.4.0
下载node安装包

1、wget https://npm.taobao.org/mirrors/node/latest-v12.x/node-v12.4.0-linux-x64.tar.gz


2、下载下来的tar文件上传到服务器并且解压,然后通过建立软连接变为全局;

1)上传服务器可以是自己任意路径,目前我的放置路径为 cd /lnmp

2)解压上传(解压后的文件我这边将名字改为了nodejs,这个地方自己随意,只要在建立软连接的时候写正确就可以)

① tar -xvf node-v12.4.0-linux-x64.tar.gz

② mv node-v12.4.0-linux-x64 nodejs

③确认一下nodejs下bin目录是否有node 和npm文件,如果有执行软连接,如果没有重新下载执行上边步骤;

3)建立软连接,变为全局

 

①ln -s /lnmp/node-v12.4.0-linux-x64/nodejs/bin/npm /usr/local/bin/

 

②ln -s /lnmp/node-v12.4.0-linux-x64/nodejs/bin/node /usr/local/bin/

 

4)最后一步检验nodejs是否已变为全局


在Linux命令行node -v 命令会显示nodejs版本,如图所示为大功告成


6.安装MySQL

6-1.下载安装boost
wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
tar -zxvf boost_1_59_0.tar.gz
cd /lnmp/boost_1_59_0/
./bootstrap.sh
./b2 install

6-2.下载安装MySQL(或者https://blog.csdn.net/qq_37598011/article/details/93489404数据库安装或者
https://blog.csdn.net/weikaixxxxxx/article/details/86532074)
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.24.tar.gz
cd /lnmp/mysql-5.7.24/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DMYSQL_DATADIR=/usr/local/mysql/data -
DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1? -DWITH_ARCHIVE_STORAGE_ENGINE=1? -
DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -
DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/include/boost
make&&make install

6-3创建用户并修改权限
groupadd mysql
useradd -g mysql mysql
chown mysql:mysql /usr/local/mysql/

6-4初始化mysql数据库
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

av*HuaYs8bp-

6-5修改配置文件
vim /etc/my.cnf

写入以下内容:

[mysqld]

basedir =/usr/local/mysql

datadir=/usr/local/mysql/data/

socket=/usr/local/mysql/data/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

6-6.创建mysqld的pid文件
mkdir /var/run/mysqld/
touch /var/run/mysqld/mysqld.pid
chown mysql:mysql /var/run/mysqld/
chmod -R 777 /var/run/mysqld/

6-7.设置开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on


6-7.配置环境变量
echo "PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
source /etc/profile

6-8.修改登录密码
update mysql.user set authentication_string=password('123456') where user='root';
flush privileges;

//alter user user() identified by "123456";


安装PHP7.2版本
安装PHP相关依赖扩展和常用库
yum -y install libmcrypt-devel mhash-devel 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 krb5-devel libidn libidn-devel
openssl openssl-devel

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-mbstring --enable-pdo --with-curl --disable-debug --
disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --
enable-zip --with-pcre-regex --with-mysqli --with-gd --with-jpeg-dir --with-freetype-dir --enable-calendar

./configure --prefix=/usr/local/php7.3 --with-config-file-path=/usr/local/php7.3/etc --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir
--enable-soap --enable-calendar --with-curl --with-gd --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-
sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql --with-mysqli --with-jpeg-dir --
with-png-dir --with-openssl --enable-opcache --enable-fpm --with-iconv --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd

make && make install

 

安装redis
1、下载解压
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
tar -xzf redis-4.0.10.tar.gz
cd redis-4.0.10
2、编译安装
make PREFIX=/usr/local/redis install
mkdir /usr/local/redis/etc/
cp redis.conf /usr/local/redis/etc/
3、修改配置文件
vim /usr/local/redis/etc/redis.conf

# 修改一下配置
# redis以守护进程的方式运行
# no表示不以守护进程的方式运行(会占用一个终端)
daemonize yes

# 客户端闲置多长时间后断开连接,默认为0关闭此功能
timeout 300

# 设置redis日志级别,默认级别:notice
loglevel verbose

# 设置日志文件的输出方式,如果以守护进程的方式运行redis 默认:""
# 并且日志输出设置为stdout,那么日志信息就输出到/dev/null里面去了
logfile stdout
# 设置密码授权
requirepass <设置密码>

安装pm2
 npm install -g pm2 这里安装之后需要指定软连接

  ln -s /lnmp/node-v12.4.0-linux-x64/bin/pm2 /usr/local/bin/pm2
可以通过pm2 -v 验证。

posted @ 2020-02-11 11:11  岑丰涛  阅读(186)  评论(0编辑  收藏  举报