zoukankan      html  css  js  c++  java
  • LAMP架构编译安装过程详解

    linux Git 安装 

    1.安装git依赖包 

    1. yum install -y perl-ExtUtils-MakeMaker package
    2. yum install -y tcl  build-essential tk gettext
    3. yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker    #安装gcc编译器

    2.下载编译包并安装

     1 #下载git 
     2 wget https://www.kernel.org/pub/software/scm/git/git-2.8.1.tar.gz
     3 #解压压缩包
     4 tar  -zxvf   git-2.8.1.tar.gz
     5  
     6 #进入目录
     7 cd      git-2.8.1  
     8 
     9 #编译安装
    10 ./configure   -prefix=/usr/local/git
    11 make   &&  make install  

    3.加入环境变量

    1 echo -e '
    export PATH=$PATH:/usr/local/git/bin' >> /etc/profile && source /etc/profile

    4.验证成功

    git  --version 

     LAMP-APR安装

    【apache 安装需要的依赖包:apr  apr-util  pcre 】

    下载编译安装:apr

    wget  http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
    cd ./apr-1.7.0/
    ./configure --perfix=/usr/local/apr
    make && make install 

    下载编译安装:apr-util

    #安装前需要先安装expat库。否则会报错
    yum  install  expat-devel
    #下载源码包
    wget  http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
    #解压
    tar -zxvf  apr-util-1.6.1.tar.gz
    #配置编译安装
    cd  apr-util-1.6.0
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
    make && make install

    下载安装编译:pcre 

    #下载
    wget https://sourceforge.net/projects/pcre/files/pcre/8.43/pcre-8.43.tar.gz
    #配置并编译安装
    cd pcre-8.43.tar.gz
    ./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config
    make && make install

    下载编译安装apache

    #下载
    wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
    
    #解压
    tar -zxvf httpd-2.4.41.tar.gz
    
    #配置并编译安装
    cd  httpd-2.4.41

    ./configure --prefix=/usr/local/apache
    --sysconfdir=/etc/httpd24
    --enable-so
    --enable-ssl
    --enable-cgi
    --enable-rewrite
    --with-zlib
    --with-pcre
    --with-apr=/usr/local/apr
    --with-apr-util=/usr/local/apr-util/
    --enable-modules=most
    --enable-mpms-shared=all
    --with-mpm=prefork

    make && make install

     apache修改配置文件

    编译Apache的unit文件,在/usr/lib/systemd/system/目录下新建一个名为httpd.service的unit文件,其内容为:

    [Unit]
    Description=apache
    
    [Service]
    Type=simple #设置service类型为simple
    EnvironmentFile=/usr/local/apache/conf/httpd.conf #指定service的环境配置文件
    ExecStart=/usr/local/apache/bin/httpd -k start -DFOREGROUND 
    ExecReload=/usr/local/apache/bin/httpd -k graceful 
    ExecStop=/bin/kill -WINCH ${MAINPID} #此处的${MAINPID}为特殊变量,对应着相应服务的主进程ID
    
    [Install]
    WantedBy=multi-user.target

      启动httpd服务并设置自动启动

      编辑完成后,记得使用systemctl daemon-reload加载新建或编辑过的unit文件

      使用systemctl启动httpd服务

    [root@localhost /]# systemctl start  httpd
    [root@localhost /]# systemctl status httpd 

    第二种httpd启动方式

    1. 将apache启动脚本复制到系统服务目录

    cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

    2. 添加apache的环境变量

    echo -e '
    export PATH=/usr/local/apache/bin:/usr/local/apache/lib:$PATH
    ' >> /etc/profile && source /etc/profile

    3. 加入自启动服务

    #编辑启动脚本
    vim /etc/rc.d/init.d/httpd
     
    #给脚本中添加注释
    #chkconfig:2345 64 36
     
    #当进行chkconfig --add httpd操作时,如果没有指定level那么就会来这个注释中取值
    #添加到自启服务列表并开启自启
    chkconfig --add httpd
    chkconfig httpd on

    4.修改配置文件

    #编辑httpd.conf 文件
    vim /usr/local/apache/conf/httpd.conf
     
    将ServerName前面的#去掉, 
    #ServerName www.example.com:80

    5.启动服务

    [root@localhost httpd-2.4.27]# service httpd start
    Starting httpd:                                            [  OK  ]

    下载安装编译:php

    1 安装依赖包

     yum install -y gcc gcc-c++  make zlib zlib-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
    #下载php编译包
    wget  https://www.php.net/distributions/php-7.3.10.tar.gz
    
    #解压
    tar -zxvf php-7.3.10.tar.gz
    cd  cd php-7.3.10/
    
    #编译安装
    ./configure 
    --prefix=/usr/local/php7/ 
    --with-apxs2=/usr/local/apache/bin/apxs 
    --enable-mbstring 
    --with-curl 
    --with-gd 
    --enable-fpm 
    --enable-mysqlnd 
    --with-pdo-mysql=mysqlnd 
    --with-config-file-path=/usr/local/php7/etc/ 
    --with-mysqli=mysqlnd
    
    make && make install  

    2. 配置php启动命令

    # 复制启动脚本到 init.d 目录
    $ cp php-7.3.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    # 增加执行权限
    $ chmod +x /etc/init.d/php-fpm
    # 配置 php-fpm 文件
    $ cd /usr/local/php7/etc/
    $ cp php-fpm.conf.default php-fpm.conf
    # 进入 php-fpm.conf , 并去除 pid = run/php-fpm.pid 的注释
    $ vim php-fpm.conf
    === 
    ...
    [global]
    ; Pid file
    ; Note: the default prefix is /usr/local/php7/var
    ; Default Value: none
    # 取消下面的注释
    pid = run/php-fpm.pid
    ...
    ===
    # 复制 www.conf 文件
    $ cp php-fpm.d/www.conf.default php-fpm.d/www.conf
    # 重启 php 服务器
    $ pkill -9 php-fpm
    $ /usr/local/nginx/php7/sbin/php-fpm
    # 测试 
    $ /etc/init.d/php-fpm stop  # 停止服务
    Gracefully shutting down php-fpm . done
    $ /etc/init.d/php-fpm start # 启动服务
    Starting php-fpm  done
    $ /etc/init.d/php-fpm restart # 重启服务
    Gracefully shutting down php-fpm . done
    Starting php-fpm  done

    CentOS 7 配置自启动

    # 启动(因为上面已经配置好启动脚本了,并且放到了 /etc/init.d 中所以下面命令是可以用的)
    # 在 centos7 中 systemctl 是找 /etc/init.d 中的脚本
    $ systemctl start php-fpm # 启动
    $ systemctl enable php-fpm # 自启动
    php-fpm.service is not a native service, redirecting to /sbin/chkconfig.
    Executing /sbin/chkconfig php-fpm on # 这里他提示我 php-fpm 并不是系统服务所以不能使用 systemctl 推荐我使用 /sbin/chkconfig php-fpm on 来实现自启动
    $ /sbin/chkconfig php-fpm on 再次重启即可完成自启动
    # 注: 如果不想配置 php-fpm 服务器化到此已经可以结束了,如果想看服务化可以看以下操作

    Centos 7 服务化 php-fpm

    # 在 centos 7 之后我们可以使用 systemctl 更好的管理系统服务
    # 所以我们也要让 php-fpm 支持
    # 因为 php 7.2 源码包里面含有 systemctl 所需要的脚本文件
    # 我们只要复制过去即可,我们来开始配置
    # 进入下载的 php源码包
    $ cd php-7.2.19/sapi/fpm
    # 复制其中的 php-fpm.service 到 /usr/lib/systemd/system/
    $ cp php-fpm.service /usr/lib/systemd/system/
    # 再次使用 systemctl enable php-fpm 进行配置自启动
    $ systemctl enable php-fpm
    # 重启测试一下看看自己服务器的 php-fpm 是否成功运行

    安装MySQL依赖包

    1. 安装boost

    [root@node2~]# yum –y install libevent* libtool* autoconf* libstd* ncurse* bison* openssl*

    2. 安装 boost_1_59_0.tar.gz

    #下载boost
    wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz     #解压到/usr/local/下

      下载更新cmake 【 编译安装mysql - 从mysql5.5起,mysql源码安装开始使用cmake 】

    #下载
    wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz 
    
    #解压
     tar -zxvf  cmake-3.6.2.tar.gz 
    cd cmake-3.6.2/
    
    #编译安装
     ./bootstrap 
    make && make  install 
    
    #查看版本
    #cmake --version 
    cmake version 3.6.2
    
    CMake suite maintained and supported by Kitware (kitware.com/cmake).

    安装数据库

    1. 卸载已有MySQL

    [root@node2~]# yum -y remove mariadb 
    [root@node2~]# yum -y remove mysql [root@node2~]# rm -rf /usr/local/mysql57
    [root@node2~]# rm -rf /var/lib/mysql57/ 
    [root@node2~]# rm -rf /usr/src/mysql-5.7.18/
    [root@node2~]# rm /etc/my.cnf

    2. 下载解压MySQL包

    [root@node2~]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.20.tar.gz # 解压到/usr/src/目录 
    [root@node2~]# tar zxvf mysql-5.7.20.tar.gz -C /usr/local/src/

    3. 添加mysql用户和组

    [root@node2 ~]# groupadd  mysql
    [root@node2 ~]# id myql
    id: myql: no such user
    [root@node2 ~]# useradd -d /home/myql -g mysql -m mysql
    [root@node2 ~]# id mysql
    uid=1000(mysql) gid=1000(mysql) 组=1000(mysql)
    [root@node2 ~]# passwd mysql
    更改用户 mysql 的密码 。
    新的 密码:
    重新输入新的 密码:
    passwd:所有的身份验证令牌已经成功更新。

    4. 新建相关目录,并赋权限给mysql用户

    [root@node2 home]# mkdir /home/mysql-5.7.20
    [root@node2 home]# mkdir /home/mysql-5.7.20/data
    [root@node2 home]# mkdir -p /home/mysql-5.7.20/log
    [root@node2 home]# mkdir -p /home/mysql-5.7.20/run [root@node2 home]# mkdir -p /home/mysql-5.7.20/tmp
    [root@node2 home]# chown -R mysql:mysql /home/mysql-5.7.20/

    5. 编译安装

    ###编译时注意内存是否满足编译要求否则会中断编译

    [root@node2 ~]# cd /usr/src/mysql-5.7.20/
    #cmke编译
    cmake 
    -DCMAKE_INSTALL_PREFIX=/home/mysql-5.7.20    #指定安装目录
    -DINSTALL_DATADIR=/home/mysql-5.7.20/data 
    -DDEFAULT_CHARSET=utf8                       #默认字符集
    -DDEFAULT_COLLATION=utf8_general_ci 
    -DEXTRA_CHARSETS=all 
    -DWITH_SSL=yes 
    -DWITH_EMBEDDED_SERVER=1 
    -DENABLED_LOCAL_INFILE=1 
    -DWITH_MYISAM_STORAGE_ENGINE=1 
    -DWITH_INNOBASE_STORAGE_ENGINE=1 
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 
    -DWITH_FEDERATED_STORAGE_ENGINE=1 
    -DWITH_PARTITION_STORAGE_ENGINE=1 
    -DMYSQL_UNIX_ADDR=/home/mysql-5.7.20/run/mysql.sock        #用来做网络通信,启动时再会发生
    -DMYSQL_TCP_PORT=3306 
    -DENABLED_LOCAL_INFILE=1 
    -DSYSCONFDIR=/etc                   #配置文件的位置
    -DWITH_READLINE=on 
    -DWITH_BOOST=/usr/local/boost_1_59_0

    make install

    6.编写配置文件my.cnf

    mkdir /etc/mysql
    cd /etc/mysql
    vim my.cnf
    [mysqld]
    basedir=/home/mysql-5.7.20
    datadir=/home/mysql-5.7.20/data
    socket=/home/mysql-5.7.20/mysql.sock
    user=mysql
    symbolic-links=0
    [mysqld_safe]
    log-error=/home/mysql-5.7.20/log/mysqld.log
    pid-file=/home/mysql-5.7.20/run/mysqld.pid

    7. 初始化系统数据库

    [root@node2 bin]# ./mysqld –defaults-file=/etc/mysql/my.cnf --initialize --user=mysql --basedir=/home/mysql-5.7.20/ --datadir=/home/mysql-5.7.20/data/ 
    #创建密码一定要记下来

    8. 启动mysql

    [root@node2 bin]# touch /home/mysql-5.7.20/log/mysqld.log
    [root@node2 bin]# chown -R mysql:mysql /home/mysql-5.7.20/log/mysqld.log
    [root@node2 bin]# ./mysqld_safe --defaults-file=/etc/mysql/my.cnf --user=mysql
    2019-05-15T06:33:33.794898Z mysqld_safe Logging to '/home/mysql-5.7.20/log/mysqld.log'.
    2019-05-15T06:33:33.826283Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7.20/data

    9. 添加mysql服务

    cp /home/mysql-5.7.20/support-files/mysql.server /etc/init.d/mysqld 
    
    chmod 755 /etc/init.d/mysqld

    10. 启动服务

    [root@node2 bin]# service mysqld start
    Starting MySQL. SUCCESS! 

    11. 添加mysql的环境变量

    vim /etc/profile
    最后一行添加
    export PATH=/home/mysql-5.7.20/bin:$PATH
    source /etc/profile

    12. 连接mysql

    #查看mysql.log日志,查看初始密码
    [root@node2 data]# cat /home/mysql-5.7.20/log/mysqld.log |grep password
    2019-05-15T03:34:45.137254Z 1 [Note] A temporary password is generated for root@localhost: 1ws;,dEy?kM#

    13. 登录

    [root@node2 bin]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 4
    Server version: 5.7.26
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql>

      #修改密码               

    mysql> set PASSWORD=PASSWORD('xxxxxxxx');
    Query OK, 0 rows affected, 1 warning (0.01 sec)
    
    mysql> alter user 'root'@'localhost' PASSWORD EXPIRE NEVER;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

      #重新登录              

    [root@node2 log]# /home/mysql-5.7.20/bin/mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 3
    Server version: 5.7.26 Source distribution
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> show database;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    rows in set (0.00 sec
  • 相关阅读:
    bootstrap 菜鸟笔记
    OOCSS待解疑惑
    sass 菜鸟笔记
    WOW.js – 让页面滚动更有趣 初学者使用教程
    JAVA8 十大新特性详解
    数据库事务的四大特性以及事务的隔离级别
    java基础--泛型
    java基础之 泛型
    springboot的文件路径,配置文件
    maven使用心得
  • 原文地址:https://www.cnblogs.com/Mercury-linux/p/11658620.html
Copyright © 2011-2022 走看看