Linux常用的企业服务

1.rpm 安装软件包

rpm -ivh yy.rpm #安装rpm软件
  • rpm -q查询功能
    • -a #查询所有已安装的软件包
    • -f #查询文件所需软件包
    • -p #查询软件包
    • -i #显示安装详细信息
rpm -qa nginx
  • rpm -U升级:需要下载更高级的rpm软件包
rpm -Uvh yy.rpm  #升级yy.rpm,已有更高版本软件在本地
  • rpm -e 卸载
rpm -e yy #将yy服务卸载 ,不能将全称yy.rpm写上

2.yum安装软件包

介绍yum软件包的管理并配置本地yum源
yum安装:方便快捷 不用考虑包依赖,自动下载软件包

  • yum repolist #列出yum源列表
  • yum clean all #清除yum缓存
  • yum makecache #创建新的缓存
  • yum install -y zsh #安装zsh软件
  • yum info zsh #显示zsh软件包详细信息
  • yum info installed zsh #查看已安装的zsh
  • yum remove zsh #卸载zsh软件
  • yum search gcc #寻找可安装的gcc

根据yum源,下载rpm文件,自动安装

[oceanshadow@localhost ~]$ ll /etc/yum.repos.d/ #显示在线yum源
total 32
-rw-r--r--. 1 root root 1664 Apr 29  2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Apr 29  2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Apr 29  2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Apr 29  2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Apr 29  2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Apr 29  2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 Apr 29  2018 CentOS-Vault.repo
  • 配置本地yum源:yum 源配置路径:/etc/yum.repos.d/
    [root@localhost yum.repos.d]# vi Centos7-yum.repo #配置yum源,必须.repo结尾
    #配置信息:baseurl代表rpm包的路径
[Centos7-yum]
name=Centos7-source
baseurl=file:///mnt
enabled=1
gpgcheck=0
[root@localhost yum.repos.d] yum repolist   #列出yum源列表
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Centos7-yum                                                      | 3.6 kB  00:00:00     
(1/2): Centos7-yum/group_gz                                      | 166 kB  00:00:00     
(2/2): Centos7-yum/primary_db                                    | 3.1 MB  00:00:00     
repo id                                repo name                                  status
Centos7-yum                            Centos7-source                             3,971
repolist: 3,971
[root@localhost yum.repos.d] vi Centos7-yum.repo
[root@localhost yum.repos.d] yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                repo name                                  status
Centos7-yum                            Centos7-source                             3,971
repolist: 3,971

[root@localhost oceanshadow] mount /dev/cdrom /mnt/ #将iso文件挂载到/mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost oceanshadow] mv /etc/yum.repos.d/* /home/oceanshadow/yum_source/ #将在线源移动到其他路径
[root@localhost oceanshadow] cd /etc/yum.repos.d/ #切换到 yum源配置路径
[root@localhost yum.repos.d] ll #查看文件是否被移除
total 0
[root@localhost yum.repos.d] yum clean all  #清除yum缓存
Loaded plugins: fastestmirror, langpacks
Cleaning repos: Centos7-yum
Cleaning up everything
[root@localhost yum.repos.d] yum makecache  #创建新的缓存
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
Centos7-yum                                                      | 3.6 kB  00:00:00     
(1/4): Centos7-yum/group_gz                                      | 166 kB  00:00:00     
(2/4): Centos7-yum/primary_db                                    | 3.1 MB  00:00:00     
(3/4): Centos7-yum/other_db                                      | 1.3 MB  00:00:00     
(4/4): Centos7-yum/filelists_db                                  | 3.1 MB  00:00:00     
Metadata Cache Created

[root@localhost yum.repos.d] yum install -y zsh  #安装/mnt/Packages/zsh-5.0.2-28.el7.x86_64.rpm

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================
 Package        Arch              Version                 Repository              Size
=======================================================================================
Installing:
 zsh            x86_64            5.0.2-28.el7            Centos7-yum            2.4 M

Transaction Summary
=======================================================================================
Install  1 Package

Total download size: 2.4 M
Installed size: 5.6 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : zsh-5.0.2-28.el7.x86_64                                             1/1 
  Verifying  : zsh-5.0.2-28.el7.x86_64                                             1/1 

Installed:
  zsh.x86_64 0:5.0.2-28.el7                                                            

Complete!

[root@localhost yum.repos.d]  yum info zsh 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
Name        : zsh
Arch        : x86_64
Version     : 5.0.2
Release     : 28.el7
Size        : 5.6 M
Repo        : installed
From repo   : Centos7-yum
Summary     : Powerful interactive shell
URL         : http://zsh.sourceforge.net/
License     : MIT
Description : The zsh shell is a command interpreter usable as an interactive login
            : shell and as a shell script command processor.  Zsh resembles the ksh
            : shell (the Korn shell), but includes many enhancements.  Zsh supports
            : command line editing, built-in spelling correction, programmable
            : command completion, shell functions (with autoloading), a history
            : mechanism, and more.

3.源码编译安装

  • 源码安装优点:编译安装过程中可以设定参数,指定安装目录,按照需求进行安装,指定安装版本,加入功能,灵活性较大。
  • 源码安装缺点:需要一个一个安装依赖,升级后因为依赖包不可用导致不能使用的连锁反应。
  • 编译安装软件四大步骤
    • 1.解压源码包 :tar -xvf 源码包
    • 2.配置:进入解压后的目录,用./configure命令来配置相关的信息(比如指定安装目录–prefix=/usr/local/nginx)和生成Makefile文件。
    • 3.编译:make -j4
    • 4.安装:make install

4.JDK8安装

java8jdk地址

[root@localhost jdk1.8.0_251] tar -xvf jdk-8u251-linux-x64.tar.gz #解压缩
[root@localhost local] mv jdk1.8.0_251/ /usr/local/jdk1.8  #重命名为jdk1.8
[root@localhost local] vi /etc/profile  #配置java8环境变量

export JAVA_HOME=/usr/local/jdk1.8    #根据jdk的根目录更改,此处在/usr/local/jdk1.8
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
[root@localhost local] source /etc/profile #激活环境变量
[root@localhost local] java -version  #查看java版本
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)

5.CentOS7 源码部署tomcat网站服务器

#下载tomcat
[root@localhost local] wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.35/bin/apache-tomcat-9.0.35.tar.gz
[root@localhost tomcat8] tar -xf apache-tomcat-9.0.35.tar.gz  #解压
[root@localhost tomcat8] mv apache-tomcat-9.0.35/ /usr/local/tomcat8 #换路径,重命名
[root@localhost tomcat8] cd /usr/local/tomcat8/bin
[root@localhost bin] sh startup.sh   #启动tomcat
Using CATALINA_BASE:   /usr/local/tomcat8
Using CATALINA_HOME:   /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME:        /usr/local/jdk1.8/jre
Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Tomcat started.
[root@localhost bin] ps -ef | grep tomcat  #查看进程号
root      48719      1  8 10:25 pts/4    00:00:02 /usr/local/jdk1.8/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8 -Dcatalina.home=/usr/local/tomcat8 -Djava.io.tmpdir=/usr/local/tomcat8/temp org.apache.catalina.startup.Bootstrap start
root      50069  66185  0 10:25 pts/4    00:00:00 grep --color=auto tomcat
[root@localhost bin] netstat -tunlp | grep 48719  #查看端口是否监听
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      48719/java          
tcp6       0      0 :::8080                 :::*                    LISTEN      48719/java          
[root@localhost bin] systemctl stop firewalled.service  #关闭防火墙

前端访问ip和端口。
在这里插入图片描述

6.CentOS7 实战源码部署apache网站服务器

简介:实战演练apache网站服务器的搭建

  • Apache简介
Apache软件基金会的一个开源免费的网页服务器,也是目前世界上使用最广泛的一种web server ,apache最出名的
是它跨平台,高效和稳定,可以运行在几乎所有广泛使用的计算机平台上。其特点是简单、速度快、性能稳定,并可做代
理服务器来使用,并且可通过简单的 API 扩充,将 Perl/Python 等解释器编译到服务器中
  • 源码编译安装 Apache

    • 下载组件apr并解压:
      组件apr官方网站:http://apr.apache.org/download.cgi
      wget http://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
      tar -xf apr-1.7.0.tar.gz
    • 下载组件apr-util并解压:
      组件apr-util官方网站:http://apr.apache.org/download.cgi
      wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
      tar -xf apr-util-1.6.1.tar.gz
    • 下载apache并解压:
      apache官方网站:http://httpd.apache.org/download.cgi
      wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.43.tar.gz
      tar -xf httpd-2.4.43.tar.gz
    • 安装gcc环境:
      yum install -y gcc*
    • 安装zlib-devel库:
      yum install -y zlib-devel
    • 安装xml 的解析器:
      yum install -y expat-devel
    • 下载并安装pcre正则表达式库:
      下载地址:https://ftp.pcre.org/pub/pcre/
[root@localhost apache_test] wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
[root@localhost apache_test] tar -xf pcre-8.44.tar.gz
[root@localhost apache_test] cd pcre-8.44   #进入源码文件夹
[root@localhost pcre-8.44 ] mkdir -p /usr/local/pcre
[root@localhost pcre-8.44 ] ./configure --prefix=/usr/local/pcre  #指定pcre安装路径
[root@localhost pcre-8.44 ] make && make install
  • 把组件apr与组件apr-util拷贝到apache安装包里:
[root@localhost apache_test] cp -rf apr-1.7.0 ./httpd-2.4.43/srclib/apr
[root@localhost apache_test] cp -rf apr-util-1.6.1 ./httpd-2.4.43/srclib/apr-util

#进入apache解压包进行./configure进行环境收集检验与配置相关模块:
[root@localhost httpd-2.4.43] mkdir -p /usr/local/apache
[root@localhost httpd-2.4.43] ./configure \--prefix=/usr/local/apache \--sysconfdir=/usr/local/apache/etc \--with-apr=/home/oceanshadow/apache_test/apr-1.7.0 \--with-apr-util=/home/oceanshadow/apache_test/apr-util-1.6.1 \--with-included-apr \--with-pcre=/usr/local/pcre \--enable-deflate \--enable-expires \--enable-headers \--enable-so \--enable-modules=most \--with-mpm=worker \--enable-rewrite
----------------------------------------------------------------------------------
选项说明:
--prefix #指定安装目录
--sysconfdir #指定配置文件的路径
--with-apr #指定依赖文件的路径
--with-apr-util #指定依赖文件的路径
--with-included-apr #增加编译效率的
--with-pcre #指定pcre正则表达式库安装路径
--enable-deflate #开启压缩文件提高速度节约带宽
--enable-expires #开启让浏览器缓存,减轻服务器压力,提高访问速度
--enable-headers #使得支持http头
--enable-so #使得支持动态模块
--enable-modules=most #使得支持大多数模块
--with-mpm=worker #使得Apache工作在worker模式下
--enable-rewrite #使得支持地址重写
----------------------------------------------------------------------------------
  • 编译并安装apache:
    make -j 4 && make install
  • 设置服务器名称:
vi /usr/local/apache/etc/httpd.conf
输入:ServerName进行搜索
添加:
ServerName www.xdclss.com
  • 测试并启停apache服务器:
ln -s /usr/local/apache/bin/* /usr/sbin/ #设置软连接
echo "export PATH=/usr/local/apache/bin:$PATH" >> /etc/profile #设置环境变量
source /etc/profile #加载环境变量
httpd -t #测试配置文件语法有没有错误
httpd -k start #启动apache服务
httpd -k stop #关闭apache服务
在防火墙关闭的条件下,打开浏览器,输入IP地址,成功打开apache测试页面
  • 相关报错收集与解决办法:
1)make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Entering directory `/home/test/apr-util-1.6.1'
/bin/sh /usr/local/apache/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -
pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/home/test/aprutil-1.6.1/include -I/home/test/apr-util-1.6.1/include/private -
I/usr/local/apache/apr/include/apr-1 -o xml/apr_xml.lo -c xml/apr_xml.c &&
touch xml/apr_xml.lo
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
# include <expat.h> ^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/home/test/apr-util-1.6.1'
make: *** [all-recursive] Error 1
错误原因:缺少xml 的解析器
解决方法:yum -y install expat-devel
----------------------------------------------------------------------------------2)configure 时 error: APR not found
错误详情:
configure:
checking for APR… no
configure: error: APR not found. Please read the documentation.
错误原因:没有指定 Apache 必需组件 APR 或没有加–with-apr 选项指定 APR
的安装位置。
解决方法:安装 APR 并且加-with-apr 选项指定正确的位置。
----------------------------------------------------------------------------------3)configure 时-with-apr 选项不正确
错误详情:
configure:
checking for APR… configure: error:with-apr requires a directory
or file to be provided
configure:
checking for APR… configure: error: the –with-apr parameter is
incorrect. It must specify an install prefix, a build directory, or
an apr-config file.
错误原因:-with-apr 选项不能为空或者指定的 APR 的位置不正确
解决方法:指定正确的 APR 选项。其实系统中已经使用 yum 安装了 APR,却不
知道如何指定 yum 安装的 APR 的位置,故出此错误,也可以进行手动源代码编译安装
APR来解决这个错误。
----------------------------------------------------------------------------------4)configure 时 error: APR-util not found
错误详情:
configure:
checking for APR-util… no
configure: error: APR-util not found. Please read the documentation.
错误原因:没有安装 Apache 必需组件 APR-util 或没有加–with-apr-util 选
项指定 APR-util 的位置
解决方法:-with-apr-util 选项指定正确的安装位置
----------------------------------------------------------------------------------5)configure 时 error: pcre-config for libpcre not found
错误详情:
checking for pcre-config… false
configure: error: pcre-config for libpcre not found. PCRE is required
and available from http://pcre.org/
错误原因:没有安装 Apache 必需组件 PCRE 或没有加–with-pcre 选项指定
PCRE 的安装位置。
解决方法:安装 PCRE 并且加–with-pcre 选项指定正确的安装位置
----------------------------------------------------------------------------------6)configure 时 error: Did not find pcre-config script at
/usr/local/pcre2
错误详情:
checking for pcre-config… false
configure: error: Did not find pcre-config script at /usr/local/pcre2
5.7 CentOS7 实战源码部署nginx网站服务器
简介:实战演练nginx网站服务器的搭建
nginx 简介:
Nginx的优点:
Nginx的缺点:
编译安装:
安装gcc编译环境:
yum install -y gcc-c++
安装zlib-devel库:
yum install -y zlib-devel
安装OpenSSL密码库:
yum install -y openssl openssl-devel
错误原因: httpd 2.4.39 不支持 pcre2?
解决方法:下载 pcre-8.43 安装即可。
----------------------------------------------------------------------------------7)启动 Apache 时提示设置 ServerName
错误详情:
AH00558: httpd: Could not reliably determine the server's fully qualified domain
name, using localhost.localdomain. Set the 'ServerName' directive globally to
suppress this message
错误原因:没有设置服务器名称
解决方法:vi /usr/local/apache/etc/httpd.conf

7.CentOS7 源码部署nginx网站服务器

简介:实战演练nginx网站服务器的搭建

  • nginx 简介:Nginx是一款高性能的 HTTP 和反向代理服务器
  • Nginx的优点:
1.高并发量:根据官方给出的数据,能够支持高达 50,000 个并发连接数的响应
2.内存消耗少:处理静态文件,同样起web 服务,比apache 占用更少的内存及资源,所有它是轻量级的
3.简单稳定:配置简单,基本在一个conf文件中配置,性能比较稳定,可以7*24小时长时间不间断运行
4.模块化程度高:Nginx是高度模块化的设计,编写模块相对简单
5.负载均衡服务器:Nginx可以做高并发的负载均衡,且Nginx是开源免费的,如果使用F5等硬件来做负载均衡,硬
件成本比较高
6.可移植性高:Nginx代码完全用C语言编写
  • Nginx的缺点:
1.动态处理差:nginx处理静态文件好,耗费内存少,但是处理动态页面比较差
2.rewrite弱:虽然nginx支持rewrite功能,但是相比于Apache来说,Apache比nginx 的rewrite 强大
  • 编译安装:
    • 安装gcc编译环境:
      yum install -y gcc-c++

    • 安装zlib-devel库:
      yum install -y zlib-devel

    • 安装OpenSSL密码库:
      yum install -y openssl openssl-devel

    • 安装pcre正则表达式库

[root@localhost apache_test] wget  http://downloads.sourceforge.net/project/pcre/pcre/8.44/pcre-8.44.tar.gz
tar -xf pcre-8.44.tar.gz
cd pcre-8.44
mkdir -p /usr/local/pcre
./configure --prefix=/usr/local/pcre
make && make install
wget http://nginx.org/download/nginx-1.18.0.tar.gz
mkdir -p /usr/local/nginx
tar -xf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre
make -j4 && make install

安装路径说明:

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

  • 启停nginx服务:
启动:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
测试:
/usr/local/nginx/sbin/nginx -t
关闭:
/usr/local/nginx/sbin/nginx -s stop
打开浏览器测试能否访问到测试页面

8. CentOS7 源码安装mysql5.7.17数据库服务器

简介:实战演练mysql数据库服务器的搭建

  • mysql简介
    mysql是一个开源的关系型数据库管理系统,现在是oracle公司旗下的一款产品,由C和C++语言编写,可移植性高。支持在多种操作系统上安装,最常见有AIX,linux,window。mysql因为开源免费,所以受到了目前互联网行业的欢 迎。以mysql作为数据库,linux系统作为操作系统,apache或者nginx作为web服务器,perl/php/python作为服务端 的脚本解释器,就可以搭建起一个免费的网站。被业界称为LNMP或者LAMP

  • 准备工作:
    磁盘空间剩余量达到15GB,内存2G以上,确保依赖组件安装完毕,安装mysql5.7.17一致,centos 7

    • 关闭selinux,关闭防火墙:
      systemctl stop firewalld.service
      vi /etc/selinux/config
      SELINUX=disabled

    • 安装cmake工具:
      yum -y install cmake

    • 下载boost路径(mysql5.7.17的必需依赖组件):
      tar -xf boost_1_59_0.tar.gz

    • yum安装其它依赖组件:
      yum -y install gcc gcc-c++ bzip2 bzip2-devel bzip2-libs python-devel ncurses ncurses-devel openssl openssl-devel

    • 创建路径:
      mkdir -p /usr/local/mysql
      mkdir -p /data/mydata

    • 创建mysql用户:
      useradd -M -s /sbin/nologin mysql

  • 使用cmake工具对mysql5.7.17进行环境收集检验与配置相关模块:

解压mysql源码包,并进入解压后的路径
[root@localhost mysql] tar -xf mysql-5.7.17.tar.gz #解压
[root@localhost mysql] tar -xf boost_1_59_0.tar.gz   #解压
[root@localhost mysql] cd mysql-5.7.17
[root@localhost mysql-5.7.17] cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/data/mydata \-DSYSCONFDIR=/etc \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \-DWITH_SSL=system \-DWITH_ZLIB=system \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DDOWNLOAD_BOOST=1 \-DWITH_BOOST=../boost_1_59_0 \-DENABLE_DOWNLOADS=1

参数详细信息解释:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #指定mysql数据库安装目录
-DMYSQL_DATADIR=/data/mydata \ #指定数据库文件路径
-DSYSCONFDIR=/etc \ #指定配置文件目录
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #安装INNOBASE存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ #安装ARCHIVE存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ #安装BLACKHOLE存储引擎
-DWITH_READLINE=1 \ #使用readline功能
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ #连接文件位置
-DWITH_SSL=system \ #表示使用系统上的自带的SSL库
-DWITH_ZLIB=system \ #表示使用系统上的自带的ZLIB库
-DDEFAULT_CHARSET=utf8 \ #指定默认使用的字符集编码
-DDEFAULT_COLLATION=utf8_general_ci \ #指定默认使用的字符集校对规则
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=../boost_1_59_0 \ #指定Boost库的位置,mysql5.7必须添加该参数
-DENABLE_DOWNLOADS=1 #支持下载可选文件
[root@localhost mysql-5.7.17] echo $?  #查看命令是否执行成功
0

在这里插入图片描述

  • 编译并安装:
[root@localhost mysql-5.7.17] make -j 4 && make install
[root@localhost mysql-5.7.17] echo $?
0
  • 初始化mysql:
[root@localhost mysql-5.7.17] /usr/local/mysql/bin/mysqld \--initialize \--user=mysql \--basedir=/usr/local/mysql \--datadir=/data/mydata \--socket=/tmp/mysql.sock

2020-06-03T05:14:46.806477Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-06-03T05:14:46.962735Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-06-03T05:14:46.989498Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-06-03T05:14:47.045952Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2473c039-a559-11ea-a7c7-000c29025983.
2020-06-03T05:14:47.047172Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-06-03T05:14:47.176650Z 0 [Warning] CA certificate ca.pem is self signed.
2020-06-03T05:14:47.200610Z 1 [Note] A temporary password is generated for root@localhost: D;o3s.ds,qxB

  • 对mysql的相关路径进行更改权限
[root@localhost mysql-5.7.17] chown -R mysql:mysql /usr/local/mysql /data/mydata
  • 修改配置文件:
[root@localhost mysql-5.7.17] mkdir -p /usr/local/mysql/log
vi /etc/my.cnf
[mysqld]
datadir=/data/mydata
socket=/tmp/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/log/mysql.errlog
pid-file=/data/mydata/$hostname.pid
  • 启停mysql:
[root@localhost oceanshadow] cd /usr/local/mysql/
[root@localhost mysql] cd support-files/
[root@localhost support-files] ./mysql.server start
Starting MySQL.2019-08-03T14:19:37.028727Z mysqld_safe error: log-error set to
'/usr/local/mysql/log/mysql.errlog', however file don't exists. Create writable for user
'mysql'.
ERROR! The server quit without updating PID file
(/data/mydata/localhost.localdomain.pid).
解决:
[root@localhost mysql-5.7.17] touch /usr/local/mysql/log/mysql.errlog      #创建错误日志
[root@localhost mysql-5.7.17] chown -R mysql:mysql /usr/local/mysql/log/mysql.errlog  #更改权限
启动:
[root@localhost mysql-5.7.17] /usr/local/mysql/support-files/mysql.server start
Starting MySQL. SUCCESS! 
关闭:
[root@localhost mysql-5.7.17] /usr/local/mysql/support-files/mysql.server stop
  • 登录mysql:
[root@localhost support-files] /usr/local/mysql/bin/mysql -uroot -p
  • 修改mysql密码:
mysql>  set password for 'root'@'localhost'=password('1009');  #将密码设置为1009
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
ERROR 1146 (42S02): Table 'mysql.servers' doesn't exist
use mysql;
drop table if exists mysql.servers;
CREATE TABLE `servers` (
`Server_name` char(64) NOT NULL,
`Host` char(64) NOT NULL,`Db` char(64) NOT NULL,
`Username` char(64) NOT NULL,
`Password` char(64) NOT NULL,
`Port` int(4) DEFAULT NULL,
`Socket` char(64) DEFAULT NULL,
`Wrapper` char(64) NOT NULL,
`Owner` char(64) NOT NULL,
PRIMARY KEY (`Server_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='MySQL Foreign Servers table';
  • 添加MySQL服务并设置mysql开机启动:
[root@localhost ~]  cp -a /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
[root@localhost ~] chkconfig --add mysql  #将mysql加入服务管理
[root@localhost ~] chkconfig --list mysql

mysql          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
  • 使用mysql服务的方式操作启停mysql服务:
    service mysql start
    service mysql stop
    service mysql restart
[root@localhost ~] service mysql start #启动mysql服务器
Starting MySQL SUCCESS!

[root@localhost ~] service mysql stop  #关闭mysql服务器
Shutting down MySQL. SUCCESS! 

[root@localhost ~] service mysql restart  #重启mysql服务器
Starting MySQL. SUCCESS! 
  • 设置mysql环境变量
    ln -s /usr/local/mysql/bin/* /usr/sbin/
[root@localhost ~]  mysql -uroot -p   #不使用绝对路径登录失败
bash: mysql: command not found...
[root@localhost ~] ln -s /usr/local/mysql/bin/* /usr/sbin/  #创建软连接
[root@localhost ~]  mysql -uroot -p   #成功使用 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.17 Source distribution

Copyright (c) 2000, 2016, 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>       

9.CentOS7 源码部署php服务与nginx 的整合

简介:实战演练php服务的搭建

  • PHP是一种脚本语言,常用于做动态网站的
  • 源码编译安装:
[root@localhost oceanshadow] yum -y install gcc gcc-c++ bzip2 bzip2-devel bzip2-libs python-devel ncurses ncursesdevel openssl openssl-devel
yum install -y libxml2-devel #安装依赖组件
[root@localhost oceanshadow] wget https://www.php.net/distributions/php-5.5.35.tar.gz  #下载php源码
tar -xf php-5.5.35.tar.gz && cd php-5.5.35  #解压php并进入解压后php包:
[root@localhost php-5.5.35] mkdir -p /usr/local/php
[root@localhost php-5.5.35] ./configure --prefix=/usr/local/php/ --enable-fpm --with-config-file=/usr/local/php/etc
[root@localhost php-5.5.35 make -j 4 && make install  #编译安装
  • 修改配置文件:
[root@localhost oceanshadow] cd /home/oceanshadow/php-5.5.35/
[root@localhost php-5.5.35] cp -a php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-5.5.35] cp -a /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
  • 启停php服务器:
[root@localhost oceanshadow] /usr/local/php/sbin/php-fpm #启动
php的默认端口是:9000
[root@localhost oceanshadow] cd /usr/local/php/sbin && pkill php-fpm #关闭

[root@localhost oceanshadow] ps -ef | grep php   #查看pipd
root      69941      1  0 15:51 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody    69942  69941  0 15:51 ?        00:00:00 php-fpm: pool www
nobody    69943  69941  0 15:51 ?        00:00:00 php-fpm: pool www
root      69970   2336  0 15:54 pts/1    00:00:00 grep --color=auto php
[root@localhost oceanshadow] netstat -tunlp | grep 69941  #查看监听端口
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      69941/php-fpm: mast 
  • 整合nginx测试php:
修改nginx配置文件并添加以下内容:vi /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
修改后对nginx进行重启:/usr/local/nginx/sbin/nginx -s reload
FastCGI是 一个 在HTTP服务器和动态脚本语言间通信的接口
fastcgi_pass 127.0.0.1:9000; #设置监听端口
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#设置脚本文件请求的路径
include fastcgi_params; #引入fastcgi的配置文件
  • 在nginx的网站发布路径下创建index.php文件
vi /usr/local/nginx/html/index.php

<?php
phpinfo();
?>
  • 打开浏览器访问 IP/index.php,能出来就成功了
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值