本文使用的Linux系统为CentOS必威手机官网

Linux下启动和停止apache服务,linuxapache

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

本文使用的Linux系统为CentOS 7,下面将介绍apache服务的启动、关闭与设置。apache在CentOS 7中一般是默认安装的,而且服务名字为httpd

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

文章作者:Tyan
博客:noahsnail.com | CSDN | 简书

文章作者:Tyan
博客:noahsnail.com | CSDN | 简书

1. 安装apache及查看相关配置

# apache安装命令

$ sudo yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package httpd-2.4.6-45.el7.centos.4.x86_64 already installed and latest version
Nothing to do


# 查看apache文件的位置

$ sudo find / -name httpd
/run/httpd
/etc/logrotate.d/httpd
/etc/sysconfig/httpd
/etc/httpd
/var/log/httpd
/var/cache/httpd
/usr/sbin/httpd
/usr/lib64/httpd
/usr/share/httpd
/usr/include/httpd
/usr/libexec/initscripts/legacy-actions/httpd

Apache配置文件位于/etc/httpd/conf,主要的配置文件是/etc/httpd/conf/httpd.conf, apache相关的配置信息都可以在这个文件中看到。

1. 下载Tomcat并解压

  • 首先下载Tomcat,这不必多说,下载地址为:http://tomcat.apache.org/

  • 解压Tomcat,例如作者下载的apache-tomcat-7.0.70.zip,直接解压即可,解压后得到apache-tomcat-7.0.70文件夹。

本文主要介绍scikit-learn中的交叉验证。

1. Maven介绍

Maven这个单词来自于意第绪语(犹太语),意为知识的积累,最初在Jakata Turbine项目中用来简化构建过程。Maven主要是一个针对Java的项目管理和构建自动化工具。Maven主要处理软件构建的两个方面:1、描述软件是如何构建的,即项目构建;2、描述软件的依赖,即依赖管理。

2. apache服务的启动与关闭

# 启动服务
$ sudo systemctl start httpd.service

# 查看服务
$ ps aux | grep httpd
root     *  0.3  0.0 220444  4956 ?        Ss   15:46   0:00 /usr/sbin/httpd -DFOREGROUND
apache   *  0.0  0.0 220444  2492 ?        S    15:46   0:00 /usr/sbin/httpd -DFOREGROUND
apache   *  0.0  0.0 220444  2488 ?        S    15:46   0:00 /usr/sbin/httpd -DFOREGROUND
apache   *  0.0  0.0 220444  2488 ?        S    15:46   0:00 /usr/sbin/httpd -DFOREGROUND
apache   *  0.0  0.0 220444  2488 ?        S    15:46   0:00 /usr/sbin/httpd -DFOREGROUND
apache   *  0.0  0.0 220444  2488 ?        S    15:46   0:00 /usr/sbin/httpd -DFOREGROUND

# 停止服务
$ sudo systemctl stop httpd.service

# 重启服务
$ sudo systemctl restart httpd.service

启动服务后,可以在外网通过服务器的IP地址访问。可以看到如下界面:

2. 启动Tomcat的相关配置

首先需要给Tomcat的bin目录下的sh文件赋予可执行权限,命令如下:

$ sudo chmod 755 ~/MyEclipse/apache-tomcat-7.0.70/bin/*.sh
  • Demo

2. Maven安装

下载地址:https://maven.apache.org/download.cgi,解压之后找到Readme.txt按照说明安装即可。也可以按照Maven官网https://maven.apache.org/install.html安装。
作者是在Mac上使用brew install maven命令安装的。

安装成功之后,可以运行mvn -v命令来查看:

# 查看java版本
$ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

# 查看mvn版本,确认安装成功
$ mvn -v/-version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /usr/***/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"

注:Maven安装之前要确保你的系统中已经安装了JDK,可用java -version查看。

3. 配置自己可以在外部访问的内容

可以在/var/www/html下创建一个软链接,链接到你想要在外部访问的内容,同时要修改要访问目录的权限。

$ sudo ln -s your_path/images /var/www/html
$ sudo chmod 755 images

注:需要确保images的所有父目录都有权限,同时images的路径应该是全路径。


0


0

查看评论

文章作者:Tyan 博客:noahsnail.com | CSDN | 简书 本文使用的Linux系统为CentOS 7,下面将介绍apache服务的启...

3. 启动和关闭Tomcat

启动和关闭Tomcat,即运行startup.sh,shutdown.sh文件有两种方式,命令如下:

  • 方法一:
# 启动Tomcat
$ cd MyEclipse/apache-tomcat-7.0.70/bin/
$ sh startup.sh
Using CATALINA_BASE:   /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_HOME:   /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_TMPDIR: /Users/***/MyEclipse/apache-tomcat-7.0.70/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
Using CLASSPATH:       /Users/***/MyEclipse/apache-tomcat-7.0.70/bin/bootstrap.jar:/Users/***/MyEclipse/apache-tomcat-7.0.70/bin/tomcat-juli.jar
Tomcat started.

# 关闭Tomcat
$ sh shutdown.sh
Using CATALINA_BASE:   /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_HOME:   /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_TMPDIR: /Users/***/MyEclipse/apache-tomcat-7.0.70/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
Using CLASSPATH:       /Users/***/MyEclipse/apache-tomcat-7.0.70/bin/bootstrap.jar:/Users/***/MyEclipse/apache-tomcat-7.0.70/bin/tomcat-juli.jar
  • 方法二:
# 启动Tomcat
$ ./startup.sh start
Using CATALINA_BASE:   /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_HOME:   /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_TMPDIR: /Users/***/MyEclipse/apache-tomcat-7.0.70/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
Using CLASSPATH:       /Users/***/MyEclipse/apache-tomcat-7.0.70/bin/bootstrap.jar:/Users/***/MyEclipse/apache-tomcat-7.0.70/bin/tomcat-juli.jar
Tomcat started.

# 关闭Tomcat
$ ./shutdown.sh shutdown
Using CATALINA_BASE:   /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_HOME:   /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_TMPDIR: /Users/***/MyEclipse/apache-tomcat-7.0.70/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
Using CLASSPATH:       /Users/***/MyEclipse/apache-tomcat-7.0.70/bin/bootstrap.jar:/Users/***/MyEclipse/apache-tomcat-7.0.70/bin/tomcat-juli.jar
usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ]  { -help | start | stop }

3. Maven目录结构

Maven是一个项目管理和构建自动化工具。Maven使用惯例优于配置的原则。Maven项目的目录结构如下:

目录 目的
${basedir} 存放 pom.xml和所有的子目录
${basedir}/src/main/java 项目的 java源代码
${basedir}/src/main/resources 项目的资源,比如说 property文件
${basedir}/src/test/java 项目的测试类,比如说 JUnit代码
${basedir}/src/test/resources 测试使用的资源
${basedir}/target 项目输出目录

maven项目编译的classes文件会放在${basedir}/target/classes目录下,打包的文件会放在${basedir}/target目录下。

4. 配置Tomcat

在启动Tomcat后,发现进入不了Manage APP,需要在Tomcat中配置用户名和密码,找到Tomcat目下的conf目录,编辑tomcat-users.xml,在<tomcat-users>标签下加入下面两行代码,即配置了Manage APP的用户名和密码为tomcat,tomcat:

<tomcat-users>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
</tomcat-users>

至此,Tomcat就在Mac下配置完成了,能启动关闭,当然也可以在Manage APP中发布应用,也可以直接将应用放到Tomcat下的webapps目录下。

注:当然可以把Tomcat配置在环境变量中,这个可以自行Google或百度。

import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_digits
from sklearn.cross_validation import train_test_split
from sklearn.svm import SVC
from sklearn.learning_curve import learning_curve
from sklearn.model_selection import cross_val_score 


# 加载数据集
digits = load_digits()
X = digits.data
y = digits.target
# 用SVM进行学习并记录loss
train_sizes, train_loss, test_loss = learning_curve(SVC(gamma = 0.001), 
                                                    X, y, cv = 10, scoring = 'neg_mean_squared_error',
                                                    train_sizes = [0.1, 0.25, 0.5, 0.75, 1])

# 训练误差均值
train_loss_mean = -np.mean(train_loss, axis = 1)
# 测试误差均值
test_loss_mean = -np.mean(test_loss, axis = 1)

# 绘制误差曲线
plt.plot(train_sizes, train_loss_mean, 'o-', color = 'r', label = 'Training')
plt.plot(train_sizes, test_loss_mean, 'o-', color = 'g', label = 'Cross-Validation')

plt.xlabel('Training data size')
plt.ylabel('Loss')
plt.legend(loc = 'best')
plt.show()

4. Maven命令

测试mvn命令的项目为Spring Boot项目,项目创建参考我的文章:Spring Boot 2.0.0参考手册_中英文对照_Part II_11-12

链接为:CSND | 简书 | 个人博客

  • 结果

4.1 mvn compile 编译项目,编译的内容在target目录(默认)

$ mvn compile
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/1.4.1.RELEASE/spring-boot-starter-parent-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/1.4.1.RELEASE/spring-boot-starter-parent-1.4.1.RELEASE.pom (8 KB at 2.1 KB/sec)
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-web/1.4.1.RELEASE/spring-boot-starter-web-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-web/1.4.1.RELEASE/spring-boot-starter-web-1.4.1.RELEASE.pom (2 KB at 2.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starters/1.4.1.RELEASE/spring-boot-starters-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starters/1.4.1.RELEASE/spring-boot-starters-1.4.1.RELEASE.pom (7 KB at 9.1 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter/1.4.1.RELEASE/spring-boot-starter-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter/1.4.1.RELEASE/spring-boot-starter-1.4.1.RELEASE.pom (2 KB at 2.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot/1.4.1.RELEASE/spring-boot-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot/1.4.1.RELEASE/spring-boot-1.4.1.RELEASE.pom (10 KB at 12.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-autoconfigure/1.4.1.RELEASE/spring-boot-autoconfigure-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-autoconfigure/1.4.1.RELEASE/spring-boot-autoconfigure-1.4.1.RELEASE.pom (20 KB at 16.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-logging/1.4.1.RELEASE/spring-boot-starter-logging-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-logging/1.4.1.RELEASE/spring-boot-starter-logging-1.4.1.RELEASE.pom (2 KB at 0.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-tomcat/1.4.1.RELEASE/spring-boot-starter-tomcat-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-tomcat/1.4.1.RELEASE/spring-boot-starter-tomcat-1.4.1.RELEASE.pom (2 KB at 1.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-test/1.4.1.RELEASE/spring-boot-starter-test-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-test/1.4.1.RELEASE/spring-boot-starter-test-1.4.1.RELEASE.pom (4 KB at 2.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-test/1.4.1.RELEASE/spring-boot-test-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-test/1.4.1.RELEASE/spring-boot-test-1.4.1.RELEASE.pom (5 KB at 2.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-test-autoconfigure/1.4.1.RELEASE/spring-boot-test-autoconfigure-1.4.1.RELEASE.pom
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-test-autoconfigure/1.4.1.RELEASE/spring-boot-test-autoconfigure-1.4.1.RELEASE.pom (6 KB at 3.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-web/1.4.1.RELEASE/spring-boot-starter-web-1.4.1.RELEASE.jar
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter/1.4.1.RELEASE/spring-boot-starter-1.4.1.RELEASE.jar
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot/1.4.1.RELEASE/spring-boot-1.4.1.RELEASE.jar
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-autoconfigure/1.4.1.RELEASE/spring-boot-autoconfigure-1.4.1.RELEASE.jar
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-logging/1.4.1.RELEASE/spring-boot-starter-logging-1.4.1.RELEASE.jar
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-web/1.4.1.RELEASE/spring-boot-starter-web-1.4.1.RELEASE.jar (3 KB at 3.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-tomcat/1.4.1.RELEASE/spring-boot-starter-tomcat-1.4.1.RELEASE.jar
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-tomcat/1.4.1.RELEASE/spring-boot-starter-tomcat-1.4.1.RELEASE.jar (3 KB at 1.6 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter/1.4.1.RELEASE/spring-boot-starter-1.4.1.RELEASE.jar (3 KB at 1.1 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-logging/1.4.1.RELEASE/spring-boot-starter-logging-1.4.1.RELEASE.jar (3 KB at 0.9 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot/1.4.1.RELEASE/spring-boot-1.4.1.RELEASE.jar (642 KB at 29.2 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-autoconfigure/1.4.1.RELEASE/spring-boot-autoconfigure-1.4.1.RELEASE.jar (946 KB at 37.0 KB/sec)
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/***/demo/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 41.975 s
[INFO] Finished at: 2016-10-30T18:27:22+08:00
[INFO] Final Memory: 23M/156M
[INFO] ------------------------------------------------------------------------

本文由必威发布于必威-运维,转载请注明出处:本文使用的Linux系统为CentOS必威手机官网

相关阅读