mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
5ff9785288
215
published/20191007 7 Java tips for new developers.md
Normal file
215
published/20191007 7 Java tips for new developers.md
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
[#]: collector: (lujun9972)
|
||||||
|
[#]: translator: (robsean)
|
||||||
|
[#]: reviewer: (wxy)
|
||||||
|
[#]: publisher: (wxy)
|
||||||
|
[#]: url: (https://linux.cn/article-11620-1.html)
|
||||||
|
[#]: subject: (7 Java tips for new developers)
|
||||||
|
[#]: via: (https://opensource.com/article/19/10/java-basics)
|
||||||
|
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||||
|
|
||||||
|
给新手 Java 开发者的 7 点提示
|
||||||
|
======
|
||||||
|
|
||||||
|
> 如果你才刚开始学习 Java 编程,这里有七个你需要知道的基础知识。
|
||||||
|
|
||||||
|
![](https://img.linux.net.cn/data/attachment/album/201911/28/120421di3744urqnyyr6xi.jpg)
|
||||||
|
|
||||||
|
Java 是一个多功能的编程语言,在某种程度上,它用在几乎所有可能涉及计算机的行业了里。Java 的最大优势是,它运行在一个 Java 虚拟机(JVM)中,这是一个翻译 Java 代码为与操作系统兼容的字节码的层。只要有 JVM 存在于你的操作系统上 —— 不管这个操作系统是在一个服务器(或“[无服务器][2]”,也是同样的)、桌面电脑、笔记本电脑、移动设备,或嵌入式设备 —— 那么,Java 应用程序就可以运行在它上面。
|
||||||
|
|
||||||
|
这使得 Java 成为程序员和用户的一种流行语言。程序员知道,他们只需要写一个软件版本就能最终得到一个可以运行在任何平台上的应用程序;用户知道,应用程序可以运行在他们的计算机上,而不用管他们使用的是什么样的操作系统。
|
||||||
|
|
||||||
|
很多语言和框架是跨平台的,但是没有实现同样的抽象层。使用 Java,你针对的是 JVM,而不是操作系统。对于程序员,当面对一些编程难题时,这是阻力最小的线路,但是它仅在当你知道如何编程 Java 时有用。如果你刚开始学习 Java 编程,这里有你需要知道的七个基础的提示。
|
||||||
|
|
||||||
|
但是,首先,如果你不确定是否你安装了 Java ,你可以在一个终端(例如 [Bash][3] 或 [PowerShell][4])中找出来,通过运行:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ java --version
|
||||||
|
openjdk 12.0.2 2019-07-16
|
||||||
|
OpenJDK Runtime Environment 19.3 (build 12.0.2+9)
|
||||||
|
OpenJDK 64-Bit Server VM 19.3 (build 12.0.2+9, mixed mode, sharing)
|
||||||
|
```
|
||||||
|
|
||||||
|
如果你得到一个错误,或未返回任何东西,那么你应该安装 [Java 开发套件][5](JDK)来开始 Java 开发。或者,安装一个 Java 运行时环境(JRE),如果你只是需要来运行 Java 应用程序。
|
||||||
|
|
||||||
|
### 1、Java 软件包
|
||||||
|
|
||||||
|
在 Java 语言中,相关的类被分组到一个*软件包*中。当你下载 JDK 时所获得的 Java 基础库将被分组到以 `java` 或 `javax` 开头的软件包中。软件包提供一种类似于计算机上的文件夹的功能:它们为相关的元素提供结构和定义(以编程术语说,*命名空间*)。额外的软件包可以从独立开发者、开源项目和商业供应商获得,就像可以为任何编程语言获得库一样。
|
||||||
|
|
||||||
|
当你写一个 Java 程序时,你应该在你的代码是顶部声明一个软件包名称。如果你只是编写一个简单的应用程序来入门 Java,你的软件包名称可以简单地用你的项目名称。如果你正在使用一个 Java 集成开发环境,如 [Eclipse][6],当你启动一个新的项目时,它为你生成一个合乎情理的软件包名称。
|
||||||
|
|
||||||
|
```
|
||||||
|
package helloworld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author seth
|
||||||
|
* An application written in Java.
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
除此之外,你可以通过查找它相对于你的项目整体的路径来确定你的软件包名称。例如,如果你正在写一组类来帮助游戏开发,并且该集合被称为 `jgamer`,那么你可能在其中有一些唯一的类。
|
||||||
|
|
||||||
|
```
|
||||||
|
package jgamer.avatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author seth
|
||||||
|
* An imaginary game library.
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
你的软件包的顶层是 `jgamer`,并且在其内部中每个软件包都是一个独立的派生物,例如 `jgamer.avatar` 和 `jgamer.score` 等等。在你的文件系统里,其目录结构反映了这一点,`jgamer` 是包含文件 `avatar.java` 和 `score.java` 的顶级目录。
|
||||||
|
|
||||||
|
### 2、Java 导入
|
||||||
|
|
||||||
|
作为一名通晓多种语言的程序员,最大的乐趣是找出是否用 `include`、`import`、`use`、`require`,或一些其它术语来引入你不管使用何种编程语言编写的库。在 Java 中,顺便说一句,当导入你的代码的需要的库时,使用 `import` 关键字。
|
||||||
|
|
||||||
|
```
|
||||||
|
package helloworld;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author seth
|
||||||
|
* A GUI hello world.
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
导入是基于该环境的 Java 路径。如果 Java 不知道 Java 库存储在系统上的何处,那么,就不能成功导入。只要一个库被存储在系统的 Java 路径中,那么导入能够成功,并且库能够被用于构建和运行一个 Java 应用程序。
|
||||||
|
|
||||||
|
如果一个库并不在 Java 路径中(因为,例如,你正在写你自己的库),那么该库可以与你的应用程序绑定在一起(协议许可),以便导入可以按预期地工作。
|
||||||
|
|
||||||
|
### 3、Java 类
|
||||||
|
|
||||||
|
Java 类使用关键字 `public class` 声明,以及一个唯一的对应于它的文件名的类名。例如,在项目 `helloworld` 中的一个文件 `Hello.java` 中:
|
||||||
|
|
||||||
|
```
|
||||||
|
package helloworld;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author seth
|
||||||
|
* A GUI hello world.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Hello {
|
||||||
|
// this is an empty class
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
你可以在一个类内部声明变量和函数。在 Java 中,在一个类中的变量被称为*字段*。
|
||||||
|
|
||||||
|
### 4、Java 方法
|
||||||
|
|
||||||
|
Java 的方法本质上是对象中的函数。基于预期返回的数据类型(例如 `void`、`int`、`float` 等等),它们被定义为 `public`(意味着它们可以被任何其它类访问)或 `private`(限制它们的使用)。
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
public void helloPrompt(ActionEvent event) {
|
||||||
|
String salutation = "Hello %s";
|
||||||
|
|
||||||
|
string helloMessage = "World";
|
||||||
|
message = String.format(salutation, helloMessage);
|
||||||
|
JOptionPane.showMessageDialog(this, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int someNumber (x) {
|
||||||
|
return x*2;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
当直接调用一个方法时,以其类和方法名称来引用。例如,`Hello.someNumber` 指向在 `Hello` 类中的 `someNumber` 方法。
|
||||||
|
|
||||||
|
### 5、static
|
||||||
|
|
||||||
|
Java 中的 `static` 关键字使代码中的成员可以独立于包含其的对象而被访问。
|
||||||
|
|
||||||
|
在面向对象编程中,你编写的代码用作“对象”的模板,这些对象在应用程序运行时产生。例如,你不需要编写一个具体的窗口,而是编写基于 Java 中的窗口类的窗口实例(并由你的代码修改)。由于在应用程序生成它的实例之前,你编写的所有代码都不会“存在”,因此在创建它们所依赖的对象之前,大多数方法和变量(甚至是嵌套类)都无法使用。
|
||||||
|
|
||||||
|
然而,有时,在对象被通过应用程序创建前,你需要访问或使用其中的数据。(例如,除非事先知道球是红色时,应用程序无法生成一个红色的球)。对于这些情况,请使用 `static` 关键字。
|
||||||
|
|
||||||
|
### 6、try 和 catch
|
||||||
|
|
||||||
|
Java 擅长捕捉错误,但是,只有你告诉它遇到错误时该做什么,它才能优雅地恢复。在 Java 中,尝试执行一个动作的级联层次结构以 `try` 开头,出现错误时回落到 `catch`,并以 `finally` 结束。如果 `try` 子句失败,则将调用 `catch`,最后,不管结果如何,总是由 `finally` 来执行一些合理的动作。这里是一个示例:
|
||||||
|
|
||||||
|
```
|
||||||
|
try {
|
||||||
|
cmd = parser.parse(opt, args);
|
||||||
|
|
||||||
|
if(cmd.hasOption("help")) {
|
||||||
|
HelpFormatter helper = new HelpFormatter();
|
||||||
|
helper.printHelp("Hello <options>", opt);
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(cmd.hasOption("shell") || cmd.hasOption("s")) {
|
||||||
|
String target = cmd.getOptionValue("tgt");
|
||||||
|
} // else
|
||||||
|
} // fi
|
||||||
|
} catch (ParseException err) {
|
||||||
|
System.out.println(err);
|
||||||
|
System.exit(1);
|
||||||
|
} //catch
|
||||||
|
finally {
|
||||||
|
new Hello().helloWorld(opt);
|
||||||
|
} //finally
|
||||||
|
} //try
|
||||||
|
```
|
||||||
|
|
||||||
|
这是一个健壮的系统,它试图避免无法挽回的错误,或者,至少,为你提供让用户提交有用的反馈的选项。经常使用它,你的用户将会感谢你!
|
||||||
|
|
||||||
|
### 7、运行 Java 应用程序
|
||||||
|
|
||||||
|
Java 文件,通常以 `.java` 结尾,理论上说,可以使用 `java` 命令运行。然而,如果一个应用程序很复杂,运行一个单个文件是否会产生有意义的结果是另外一个问题。
|
||||||
|
|
||||||
|
来直接运行一个 `.java` 文件:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ java ./Hello.java
|
||||||
|
```
|
||||||
|
|
||||||
|
通常,Java 应用程序以 Java 存档(JAR)文件的形式分发,以 `.jar` 结尾。一个 JAR 文件包含一个清单文件(可以指定主类、项目结构的一些元数据),以及运行应用程序所需的所有代码部分。
|
||||||
|
|
||||||
|
要运行一个 JAR 文件,你可以双击它的图标(取决于你的操作系统设置),你也可以从终端中启动它:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ java -jar ./Hello.jar
|
||||||
|
```
|
||||||
|
|
||||||
|
### 适合所有人的 Java
|
||||||
|
|
||||||
|
Java 是一种强大的语言,由于有了 [OpenJDK][12] 项目及其它的努力,它是一种开放式规范,允许像 [IcedTea][13]、[Dalvik][14] 和 [Kotlin][15] 项目的茁壮成长。学习 Java 是一种准备在各种行业中工作的好方法,而且,[使用 Java 的理由很多][16]。
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://opensource.com/article/19/10/java-basics
|
||||||
|
|
||||||
|
作者:[Seth Kenlon][a]
|
||||||
|
选题:[lujun9972][b]
|
||||||
|
译者:[robsean](https://github.com/robsean)
|
||||||
|
校对:[wxy](https://github.com/wxy)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://opensource.com/users/seth
|
||||||
|
[b]: https://github.com/lujun9972
|
||||||
|
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coffee_cafe_brew_laptop_desktop.jpg?itok=G-n1o1-o (Coffee and laptop)
|
||||||
|
[2]: https://www.redhat.com/en/resources/building-microservices-eap-7-reference-architecture
|
||||||
|
[3]: https://www.gnu.org/software/bash/
|
||||||
|
[4]: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-6
|
||||||
|
[5]: http://openjdk.java.net/
|
||||||
|
[6]: http://www.eclipse.org/
|
||||||
|
[7]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+actionevent
|
||||||
|
[8]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
|
||||||
|
[9]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+joptionpane
|
||||||
|
[10]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
|
||||||
|
[11]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+parseexception
|
||||||
|
[12]: https://openjdk.java.net/
|
||||||
|
[13]: https://icedtea.classpath.org/wiki/Main_Page
|
||||||
|
[14]: https://source.android.com/devices/tech/dalvik/
|
||||||
|
[15]: https://kotlinlang.org/
|
||||||
|
[16]: https://opensource.com/article/19/9/why-i-use-java
|
@ -0,0 +1,70 @@
|
|||||||
|
[#]: collector: (lujun9972)
|
||||||
|
[#]: translator: ( )
|
||||||
|
[#]: reviewer: ( )
|
||||||
|
[#]: publisher: ( )
|
||||||
|
[#]: url: ( )
|
||||||
|
[#]: subject: (Nvidia quietly unveils faster, lower power Tesla GPU accelerator)
|
||||||
|
[#]: via: (https://www.networkworld.com/article/3482097/nvidia-quietly-unveils-faster-lower-power-tesla-gpu-accelerator.html)
|
||||||
|
[#]: author: (Andy Patrizio https://www.networkworld.com/author/Andy-Patrizio/)
|
||||||
|
|
||||||
|
Nvidia quietly unveils faster, lower power Tesla GPU accelerator
|
||||||
|
======
|
||||||
|
Nvidia has upgraded its Volta line of Tesla GPU-accelerator cards to work faster using the same power as its old model.
|
||||||
|
client
|
||||||
|
|
||||||
|
Nvidia was all over Supercomputing 19 last week, not surprisingly, and made a lot of news which we will get into later. But overlooked was perhaps the most interesting news of all: a new generation graphics-acceleration card that is faster and way more power efficient.
|
||||||
|
|
||||||
|
Multiple attendees and news sites spotted it at the show, and Nvidia confirmed to me that this is indeed a new card. Nvidia’s “Volta” generation of Tesla GPU-accelerator cards has been out since 2017, so an upgrade was well overdue.
|
||||||
|
|
||||||
|
[[Get regularly scheduled insights by signing up for Network World newsletters.]][1]
|
||||||
|
|
||||||
|
The V100S comes only in PCI Express 3 form factor for now but is expected to eventually support Nvidia’s SXM2 interface. SXM is a dual-slot card design by Nvidia that requires no connection to the power supply, unlike the PCIe cards. SXM2 allows the GPU to communicate either with each other or to the CPU through Nvidia’s NVLink, a high-bandwidth, energy-efficient interconnect that can transfer data up to ten times faster than PCIe.
|
||||||
|
|
||||||
|
[][2]
|
||||||
|
|
||||||
|
BrandPost Sponsored by HPE
|
||||||
|
|
||||||
|
[Take the Intelligent Route with Consumption-Based Storage][2]
|
||||||
|
|
||||||
|
Combine the agility and economics of HPE storage with HPE GreenLake and run your IT department with efficiency.
|
||||||
|
|
||||||
|
With this card, Nvidia is claiming 16.4 single-precision TFLOPS, 8.2 double-precision TFLOPS, and Tensor Core performance of up to 130 TFLOPS. That is only a 4-to-5 percent improvement over the V100 SXM2 design, but 16-to-17 percent faster than the PCIe V100 variant.
|
||||||
|
|
||||||
|
Memory capacity remains at 32GB but Nvidia added High Bandwidth Memory 2 (HBM2) to increase memory performance to 1,134GB/s, a 26 percent improvement over both PCIe and SXM2.
|
||||||
|
|
||||||
|
Now normally a performance boost would see a concurrent increase in power demand, but in this case, the power envelope for the PCIe card is 250 watts, same as the prior generation PCIe card. So this card delivers 16-to-17 percent more compute performance and 26 percent more memory bandwidth at the same power draw.
|
||||||
|
|
||||||
|
**Other News**
|
||||||
|
|
||||||
|
Nvidia made some other news at the conference:
|
||||||
|
|
||||||
|
* A new reference design and ecosystem support for its GPU-accelerated Arm-based reference servers for high-performance computing. The company says it has support from HPE/Cray, Marvell, Fujitsu, and Ampere, the startup led by former Intel executive Renee James looking to build Arm-based server processors.
|
||||||
|
* These companies will use Nvidia's reference design, which consists of hardware and software components, to build their own GPU-accelerated servers for everything from hyperscale cloud providers to high-performance storage and exascale supercomputing. The design also comes with CUDA-X, a special version of Nvidia’s CUDA GPU development language for Arm processors.
|
||||||
|
* Launch of Nvidia Magnum IO suite of software designed to help data scientists and AI and high-performance-computing researchers process massive amounts of data in minutes rather than hours. It is optimized to eliminate storage and I/O bottlenecks to deliver up to 20x faster data processing for multi-server, multi-GPU computing nodes.
|
||||||
|
* Nvidia and DDN, developer of AI and multicloud data management, announced a bundling of DDN’s A3ITM data management system with Nvidia’s DGX SuperPOD systems with so customers can deploy HPC infrastructure with minimal complexity and reduced timelines. The SuperPODs would also come with the new NVIDIA Magnum IO software stack.
|
||||||
|
* DDN said that SuperPOD was able to be deployed within hours and a single appliance could scale all to 80 nodes. Benchmarks over a variety of different deep-learning models showed that the DDN system could keep a DGXSuperPOD system fully saturated with data.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**Now see** [**10 of the world's fastest supercomputers**][3]
|
||||||
|
|
||||||
|
Join the Network World communities on [Facebook][4] and [LinkedIn][5] to comment on topics that are top of mind.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://www.networkworld.com/article/3482097/nvidia-quietly-unveils-faster-lower-power-tesla-gpu-accelerator.html
|
||||||
|
|
||||||
|
作者:[Andy Patrizio][a]
|
||||||
|
选题:[lujun9972][b]
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://www.networkworld.com/author/Andy-Patrizio/
|
||||||
|
[b]: https://github.com/lujun9972
|
||||||
|
[1]: https://www.networkworld.com/newsletters/signup.html
|
||||||
|
[2]: https://www.networkworld.com/article/3440100/take-the-intelligent-route-with-consumption-based-storage.html?utm_source=IDG&utm_medium=promotions&utm_campaign=HPE20773&utm_content=sidebar ( Take the Intelligent Route with Consumption-Based Storage)
|
||||||
|
[3]: https://www.networkworld.com/article/3236875/embargo-10-of-the-worlds-fastest-supercomputers.html
|
||||||
|
[4]: https://www.facebook.com/NetworkWorld/
|
||||||
|
[5]: https://www.linkedin.com/company/network-world
|
@ -0,0 +1,89 @@
|
|||||||
|
[#]: collector: (lujun9972)
|
||||||
|
[#]: translator: ( )
|
||||||
|
[#]: reviewer: ( )
|
||||||
|
[#]: publisher: ( )
|
||||||
|
[#]: url: ( )
|
||||||
|
[#]: subject: (Open Source Music Notations Software MuseScore 3.3 Released!)
|
||||||
|
[#]: via: (https://itsfoss.com/musescore/)
|
||||||
|
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||||
|
|
||||||
|
Open Source Music Notations Software MuseScore 3.3 Released!
|
||||||
|
======
|
||||||
|
|
||||||
|
_**Brief: MuseScore is an open-source software to help you create, play, and print sheet music. They released a major update recently. So, we take a look at what MuseScore has to offer**_ _**overall.**_
|
||||||
|
|
||||||
|
### MuseScore: A Music Composition and Notation Software
|
||||||
|
|
||||||
|
![][1]
|
||||||
|
|
||||||
|
[MuseScore][2] is open-source software that lets you create, play, and print [sheet music][3].
|
||||||
|
|
||||||
|
You can even use a MIDI keyboard as input and simply play the tune you want to create the notation of.
|
||||||
|
|
||||||
|
In order to make use of it, you need to know how sheet music notations work. In either case, you can just play something using your MIDI keyboard or any other instrument and learn how the music notations work while using it.
|
||||||
|
|
||||||
|
So, it should come in handy for beginners and experts as well.
|
||||||
|
|
||||||
|
You can download and use MuseScore for free. However, if you want to share your music/composition and reach out to a wider community on the MuseScore platform, you can opt to create a free or premium account on [MuseScore.com][4].
|
||||||
|
|
||||||
|
### Features of MuseScore
|
||||||
|
|
||||||
|
![Musescore 3 Screenshot][5]
|
||||||
|
|
||||||
|
MuseScore includes a lot of things that can be highlighted. If you are someone who is not involved in making music notations for your compositions – you might have to dig deeper just like me.
|
||||||
|
|
||||||
|
Usually, I just head over to any [DAW available on Linux][6] and start playing something to record/loop it without needing to create the music notations. So, for me, MuseScore definitely presents a learning curve with all the features offered.
|
||||||
|
|
||||||
|
I’ll just list out the features with some brief descriptions – so you can explore them if it sounds interesting to you.
|
||||||
|
|
||||||
|
* Supports Input via MIDI keyboard
|
||||||
|
* You can transfer to/from other programs via [MusicXML][7], MIDI, and other options.
|
||||||
|
* A Huge collection of palettes (music symbols) to choose from.
|
||||||
|
* You also get the ability to re-arrange the palettes and create your own list of most-used palettes or edit them.
|
||||||
|
* Some plugins supported to extend the functionality
|
||||||
|
* Import PDFs to read and play notations
|
||||||
|
* Several instruments supported
|
||||||
|
* Basic or Advanced layout of palettes to get started
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Some of the recent key changes include the palettes redesign, accessibility, and the not input workflow. For reference, you can check out how the new palettes work:
|
||||||
|
|
||||||
|
### Installing MuseScore 3.3.3 on Ubuntu/Linux
|
||||||
|
|
||||||
|
The latest version of MuseScore is 3.3.3 with all the bug fixes and improvements to its recent [MuseScore 3.3 release][8].
|
||||||
|
|
||||||
|
You may find an older release in your Software Center (or your official repo). So, you can either opt for a Flatpak package, Snap, or maybe an AppImage from its [download page][9] with links for different Linux distributions.
|
||||||
|
|
||||||
|
[Download MuseScore][9]
|
||||||
|
|
||||||
|
**Wrapping Up**
|
||||||
|
|
||||||
|
I was quite fascinated to learn about MuseScore being an open-source and free solution to create, play, and print sheet music.
|
||||||
|
|
||||||
|
It may not be the most easy-to-use software there is – but when considering the work with music notations, it will help you learn more about it and help you with your work as well.
|
||||||
|
|
||||||
|
What do you think about MuseScore? Do share your thoughts in the comments below.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://itsfoss.com/musescore/
|
||||||
|
|
||||||
|
作者:[Ankush Das][a]
|
||||||
|
选题:[lujun9972][b]
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://itsfoss.com/author/ankush/
|
||||||
|
[b]: https://github.com/lujun9972
|
||||||
|
[1]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/11/musescore-3.jpg?ssl=1
|
||||||
|
[2]: https://musescore.org/en
|
||||||
|
[3]: https://en.wikipedia.org/wiki/Sheet_music
|
||||||
|
[4]: https://musescore.com/
|
||||||
|
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/11/musescore-3-screenshot.jpg?ssl=1
|
||||||
|
[6]: https://itsfoss.com/best-audio-editors-linux/
|
||||||
|
[7]: https://en.wikipedia.org/wiki/MusicXML
|
||||||
|
[8]: https://musescore.org/en/3.3
|
||||||
|
[9]: https://musescore.org/en/download
|
70
sources/talk/20191127 Is your code inclusive.md
Normal file
70
sources/talk/20191127 Is your code inclusive.md
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
[#]: collector: (lujun9972)
|
||||||
|
[#]: translator: ( )
|
||||||
|
[#]: reviewer: ( )
|
||||||
|
[#]: publisher: ( )
|
||||||
|
[#]: url: ( )
|
||||||
|
[#]: subject: (Is your code inclusive?)
|
||||||
|
[#]: via: (https://opensource.com/article/19/11/inclusive-design-code)
|
||||||
|
[#]: author: (Peter Cheer https://opensource.com/users/petercheer)
|
||||||
|
|
||||||
|
Is your code inclusive?
|
||||||
|
======
|
||||||
|
Learn how developers can support assistive technology projects and
|
||||||
|
inclusivity.
|
||||||
|
![plastic game pieces on a board][1]
|
||||||
|
|
||||||
|
I have been involved with assistive technology for about ten years now, beginning with a stint as an assistive technology tutor with the [Kenya Society for the Blind][2].
|
||||||
|
|
||||||
|
Assistive technology helps improve the lives of people with cognitive, physical or sensory challenges. It comprises a wide range of hardware, specialist software such as screen readers, as well as accessibility features in general software.
|
||||||
|
|
||||||
|
Over the ten years that I have worked with assistive technology, it has vastly improved. This is due in part to the advent of more powerful technologies, as well as better education and stronger disability rights legislation across much of the world. However, progress has been uneven and much of the legislation, well-meaning as it is, is poorly enforced, so there is still work to be done.
|
||||||
|
|
||||||
|
[The Association for the Advancement of Assistive Technology in Europe (AAATE)][3] is an interdisciplinary pan-European association devoted to all aspects of assistive technology, such as use, research, development, manufacture, supply, provision, and policy. Following the AAATE 2019 Conference in Bologna, the association published ["The Bologna Declaration."][4]
|
||||||
|
|
||||||
|
The declaration is a call to action "to improve access to quality assistive technology for realizing fundamental human rights and achieving the sustainable development goals in a fully inclusive manner."
|
||||||
|
|
||||||
|
It includes a list of ten important steps in an agenda for action. These points are not specifically aimed at the open source community; they are intended for policymakers and the whole assistive technology sector. This agenda for action is well thought out and deserves to be widely read across the technology sector.
|
||||||
|
|
||||||
|
### Examples of open source assistive technology
|
||||||
|
|
||||||
|
A look at the projects listed at [Open Assistive][5] offers an idea of the range of open source assistive technology projects that are already out there. A good example of mainstream open source software embracing accessibility is the Mozilla Firefox web browser "reader view" feature, which removes ads, background images, and other clutter for distraction-free viewing. The spoken text option in "reader view" also aids accessibility. This feature has certainly improved my user experience and has the great advantage of being a standard option rather than an add-on.
|
||||||
|
|
||||||
|
Some of the open source assistive tools that I have used with my clients include:
|
||||||
|
|
||||||
|
* [Vinux][6] — a Linux distro that is optimized for users with visual impairments
|
||||||
|
* [NVDA][7] — a capable screen reader for MS Windows
|
||||||
|
* [Autohotkey][8] — automates almost anything in MS Windows by sending keystrokes and mouse clicks
|
||||||
|
* [Mulberry symbol set][9] — Mulberry symbols, or pictograms, are a set of scalable SVG graphic images designed for communications use. They are ideal for software, devices, or any online accessibility use.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
There is a huge range of open source assistive technology projects; one large subset that I am interested to explore is the growing list of open source assistive technology hardware projects. If you have a favorite project that you use or contribute to, share it with us in the comments!
|
||||||
|
|
||||||
|
You can support assistive technology by encouraging users to try it, by contributing coding work to assistive technology projects, or by working on documentation and user guides. Even if they’re not working specifically on assistive technology, all developers should keep in mind the need for inclusive design in their projects. If you would like to endorse the Bologna Declaration "to raise awareness so people take action and do everything in their power to actively implementing the points on the agenda," please visit <https://aaate.net/endorse-bologna-declaration/>.
|
||||||
|
|
||||||
|
Assistive technology such as Augmented/Assisted Communication (AAC), Text-to-Speech and Speech-to-...
|
||||||
|
|
||||||
|
Assistive technology software is any program or operating system feature designed to let a user...
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://opensource.com/article/19/11/inclusive-design-code
|
||||||
|
|
||||||
|
作者:[Peter Cheer][a]
|
||||||
|
选题:[lujun9972][b]
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://opensource.com/users/petercheer
|
||||||
|
[b]: https://github.com/lujun9972
|
||||||
|
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/team-game-play-inclusive-diversity-collaboration.png?itok=8sUXV7W1 (plastic game pieces on a board)
|
||||||
|
[2]: http://www.ksblind.org/
|
||||||
|
[3]: https://opensource.com/article/19/11/www.aaate.net
|
||||||
|
[4]: https://aaate.net/the-bologna-declaration/
|
||||||
|
[5]: https://openassistive.org
|
||||||
|
[6]: https://wiki.vinuxproject.org/
|
||||||
|
[7]: https://www.nvaccess.org/
|
||||||
|
[8]: https://www.autohotkey.com/
|
||||||
|
[9]: https://mulberrysymbols.org/
|
@ -0,0 +1,97 @@
|
|||||||
|
[#]: collector: (lujun9972)
|
||||||
|
[#]: translator: ( )
|
||||||
|
[#]: reviewer: ( )
|
||||||
|
[#]: publisher: ( )
|
||||||
|
[#]: url: ( )
|
||||||
|
[#]: subject: (Why do we contribute to open source software?)
|
||||||
|
[#]: via: (https://opensource.com/article/19/11/why-contribute-open-source-software)
|
||||||
|
[#]: author: (Gordon Haff https://opensource.com/users/ghaff)
|
||||||
|
|
||||||
|
Why do we contribute to open source software?
|
||||||
|
======
|
||||||
|
Dive into the research supporting the open source ecosystem and
|
||||||
|
developers’ motivations for participating.
|
||||||
|
![question mark in chalk][1]
|
||||||
|
|
||||||
|
Organizations as a whole contribute to open source software projects for a variety of reasons.
|
||||||
|
|
||||||
|
One of the most important is that the open source development model is such an effective way to collaborate with other companies on projects of mutual interest. But they also want to better understand the technologies they use. They also want to influence direction.
|
||||||
|
|
||||||
|
The specific rationale will vary by organization but it usually boils down to the simple fact that working in open source benefits their business.
|
||||||
|
|
||||||
|
But why do individuals contribute to open source? They mostly see some kind of personal benefit too, but what specifically motivates them?
|
||||||
|
|
||||||
|
### The types of motivation
|
||||||
|
|
||||||
|
When we talk about motivations, one common way to do so is in terms of incentive theory. This theory began to emerge during the 1940s and 1950s, building on the earlier drive-reduction theories established by psychologists such as Clark Hull and Kenneth Spence. Incentive theory was originally based on the idea that motivation is largely fueled by the prospect of an external reward or incentive.
|
||||||
|
|
||||||
|
Money is a classic extrinsic motivator. So is winning an award, getting a grade, or obtaining a certification that is likely to lead to a better job.
|
||||||
|
|
||||||
|
However, in the 1970s, researchers began to also consider intrinsic motivations, which do not require an apparent reward other than the activity itself. Self-determination theory, developed by Edward Deci and Richard Ryan, would later evolve from studies comparing intrinsic and extrinsic motives, and from a growing understanding of the dominant role intrinsic motivations can play in behavior.
|
||||||
|
|
||||||
|
While intrinsic motivations can come from a number of different sources, the most straightforward one is the simple enjoyment of a particular activity. You play in a softball league after work because you like playing softball. You enjoy the exercise, the camaraderie, the game itself.
|
||||||
|
|
||||||
|
Researchers have also proposed a further distinction between this enjoyment-based intrinsic motivation and obligation/community-based intrinsic motivation, which is more about adherence to social or community norms. Maybe you don’t really like having the relatives over for Thanksgiving but you do it anyway because you know you should.
|
||||||
|
|
||||||
|
Today’s psychology literature also includes the idea of internalized extrinsic motivations. These are extrinsic motivations such as gaining skills to enhance career opportunities—but they’ve been internalized so that the motivation comes from within rather than the desire for whatever carrot is being dangled by someone else.
|
||||||
|
|
||||||
|
### What motivates open source developers?
|
||||||
|
|
||||||
|
In 2012, four researchers at [ETH Zurich][2] surveyed the prior ten years of study into open source software contribution. Among their results, they were able to group study findings into the following three categories: extrinsic motivation, intrinsic motivation, and internalized extrinsic motivation—as well as some common sub-groupings within those broader categories.
|
||||||
|
|
||||||
|
No surprise that money showed up as an extrinsic motivator. During the period studied, there were fewer large projects associated with successful commercially-supported products than is the case today. Even so, most of the open source projects the researchers examined had a significant number of contributors whose companies had paid them to work on open source.
|
||||||
|
|
||||||
|
Career obviously goes hand in hand with pay, but is open source software any different from proprietary software development in this regard? There’s some evidence that it is.
|
||||||
|
|
||||||
|
Lerner and Tirole [first suggested in 2002][3] that "individual developers would be motivated by career concerns when developing open source software. By publishing software that was free for all to inspect, they could signal their talent to potential employers and thus increase their value in the labor market."
|
||||||
|
|
||||||
|
More recently, there’s been significant empirical evidence that there are career advantages to developing code and making it available for others to see and work with. It has become almost an expectation in some industry segments for job applicants to have public GitHub code repositories, which are effectively part of their resume.
|
||||||
|
|
||||||
|
It’s reasonable to ask whether this trend has gone too far. After all, many highly qualified developers work on proprietary code. But it’s clear that, fair or not, at least some career prospects can come specifically from being an open source developer.
|
||||||
|
|
||||||
|
Among intrinsic motivators, ideology and altruism often seem closely related.
|
||||||
|
|
||||||
|
Free software was primarily an ideological statement at first, even if user control also had an important practical side; several researchers have found support for ideological motives in developer surveys.
|
||||||
|
|
||||||
|
Altruism can also be a developer motive, though research on this is mixed. One paper identified the “desire to give a present to the programmer community” as a crucial pattern in open source software. But other studies have qualified the importance of altruism as a motive, especially among programmers getting a paycheck. Other work found that altruism could be a motivator but only among developers who were otherwise satisfied.
|
||||||
|
|
||||||
|
There’s also the motivational power of fun and enjoyment, a classic intrinsic motivator. This should come as no surprise to anyone who hangs around open source developers. Almost all of them like working on open source projects. One large 2007 study determined that fun accounted for 28 percent of the effort (in terms of number of hours) dedicated to projects. One implication of this research is that activities developers typically enjoy less–tech support often tops this list–may require alternative forms of motivation.
|
||||||
|
|
||||||
|
Much of the research into reputation as an internalized extrinsic motivator has focused specifically on peer recognition. Your reputation among your peers can be a source of your own pride, but it also signals your talent to community insiders and potential employers. The suggestion that reputation could be an important motivator in contributing to open source goes back at least as far as 1998, in Eric Raymond’s essay ["Homesteading the Noosphere."][4] However, since then, a variety of surveys have supported the idea that peer reputation is a driver for participation.
|
||||||
|
|
||||||
|
Another motivator in this category is what researchers call "own-use value" but is more recognizably described as something like "scratch your own itch"–develop something that you want for yourself and in the process, create something valuable to others. The initial motivation essentially comes from a selfish need but that can evolve into more of an internalized desire to contribute.
|
||||||
|
|
||||||
|
Its unsurprising research would identify own-use value as a good motivator. Certainly, the folk wisdom is that many developers get into open source by developing something they themselves need—such as when Linus Torvalds wrote Git because Linux needed an appropriate distributed version control system.
|
||||||
|
|
||||||
|
As we’ve seen, contributors to open source software have a variety of different motivations but there are a few general threads worth highlighting in closing.
|
||||||
|
|
||||||
|
Motivators can actually be counterproductive when a single motivator is relied upon too heavily. One study reported that developers scratching their own itch worked "eclectically," fixing bugs that annoyed them and then quitting until the next time.
|
||||||
|
|
||||||
|
In particular, don’t expect non-extrinsic motivators to carry too much of the load. Fun isn’t a good motivator if the task is not actually fun. Altruism motivates some but it also doesn’t pay their bills.
|
||||||
|
|
||||||
|
That said, developers do contribute for reasons that aren’t purely about money or other extrinsic reasons. Learning, peer reputation, and recognition are important to many (and not just in open source development.) Organizations should not neglect the role these can play in motivating developers and should implement incentive programs around them, such as peer reward systems.
|
||||||
|
|
||||||
|
* * *
|
||||||
|
|
||||||
|
This post is based on material from _[How Open Source Ate Software][5]_ (Apress, 2018) by the author.
|
||||||
|
|
||||||
|
There are lots of non-code ways to contribute to open source: Here are three alternatives.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://opensource.com/article/19/11/why-contribute-open-source-software
|
||||||
|
|
||||||
|
作者:[Gordon Haff][a]
|
||||||
|
选题:[lujun9972][b]
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://opensource.com/users/ghaff
|
||||||
|
[b]: https://github.com/lujun9972
|
||||||
|
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/question-mark_chalkboard.jpg?itok=DaG4tje9 (question mark in chalk)
|
||||||
|
[2]: https://pdfs.semanticscholar.org/7712/3726f65f8fd88126357c12cad230cc832f41.pdf
|
||||||
|
[3]: https://onlinelibrary.wiley.com/doi/abs/10.1111/1467-6451.00174
|
||||||
|
[4]: https://pdfs.semanticscholar.org/98a6/c566a7e28a48facb664c8689607a52c57a5d.pdf
|
||||||
|
[5]: https://www.apress.com/gp/book/9781484238936
|
@ -1,200 +0,0 @@
|
|||||||
[#]: collector: (lujun9972)
|
|
||||||
[#]: translator: (robsean)
|
|
||||||
[#]: reviewer: ( )
|
|
||||||
[#]: publisher: ( )
|
|
||||||
[#]: url: ( )
|
|
||||||
[#]: subject: (How to Install LEMP (Linux, Nginx, MariaDB, PHP) on Fedora 30 Server)
|
|
||||||
[#]: via: (https://www.linuxtechi.com/install-lemp-stack-fedora-30-server/)
|
|
||||||
[#]: author: (Pradeep Kumar https://www.linuxtechi.com/author/pradeep/)
|
|
||||||
|
|
||||||
How to Install LEMP (Linux, Nginx, MariaDB, PHP) on Fedora 30 Server
|
|
||||||
======
|
|
||||||
|
|
||||||
In this article, we’ll be looking at how to install **LEMP** stack on Fedora 30 Server. LEMP Stands for:
|
|
||||||
|
|
||||||
* L -> Linux
|
|
||||||
* E -> Nginx
|
|
||||||
* M -> Maria DB
|
|
||||||
* P -> PHP
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
I am assuming **[Fedora 30][1]** is already installed on your system.
|
|
||||||
|
|
||||||
![LEMP-Stack-Fedora30][2]
|
|
||||||
|
|
||||||
LEMP is a collection of powerful software setup that is installed on a Linux server to help in developing popular development platforms to build websites, LEMP is a variation of LAMP wherein instead of **Apache** , **EngineX (Nginx)** is used as well as **MariaDB** used in place of **MySQL**. This how-to guide is a collection of separate guides to install Nginx, Maria DB and PHP.
|
|
||||||
|
|
||||||
### Install Nginx, PHP 7.3 and PHP-FPM on Fedora 30 Server
|
|
||||||
|
|
||||||
Let’s take a look at how to install Nginx and PHP along with PHP FPM on Fedora 30 Server.
|
|
||||||
|
|
||||||
### Step 1) Switch to root user
|
|
||||||
|
|
||||||
First step in installing Nginx in your system is to switch to root user. Use the following command :
|
|
||||||
|
|
||||||
```
|
|
||||||
root@linuxtechi ~]$ sudo -i
|
|
||||||
[sudo] password for pkumar:
|
|
||||||
[root@linuxtechi ~]#
|
|
||||||
```
|
|
||||||
|
|
||||||
### Step 2) Install Nginx, PHP 7.3 and PHP FPM using dnf command
|
|
||||||
|
|
||||||
Install Nginx using the following dnf command:
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# dnf install nginx php php-fpm php-common -y
|
|
||||||
```
|
|
||||||
|
|
||||||
### Step 3) Install Additional PHP modules
|
|
||||||
|
|
||||||
The default installation of PHP only comes with the basic and the most needed modules installed. If you need additional modules like GD, XML support for PHP, command line interface Zend OPCache features etc, you can always choose your packages and install everything in one go. See the sample command below:
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# sudo dnf install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml -y
|
|
||||||
```
|
|
||||||
|
|
||||||
### Step 4) Start & Enable Nginx and PHP-fpm Service
|
|
||||||
|
|
||||||
Start and enable Nginx service using the following command
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# systemctl start nginx && systemctl enable nginx
|
|
||||||
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
|
|
||||||
[root@linuxtechi ~]#
|
|
||||||
```
|
|
||||||
|
|
||||||
Use the following command to start and enable PHP-FPM service
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# systemctl start php-fpm && systemctl enable php-fpm
|
|
||||||
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
|
|
||||||
[root@linuxtechi ~]#
|
|
||||||
```
|
|
||||||
|
|
||||||
**Verify Nginx (Web Server) and PHP installation,**
|
|
||||||
|
|
||||||
**Note:** In case OS firewall is enabled and running on your Fedora 30 system, then allow 80 and 443 ports using beneath commands,
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# firewall-cmd --permanent --add-service=http
|
|
||||||
success
|
|
||||||
[root@linuxtechi ~]#
|
|
||||||
[root@linuxtechi ~]# firewall-cmd --permanent --add-service=https
|
|
||||||
success
|
|
||||||
[root@linuxtechi ~]# firewall-cmd --reload
|
|
||||||
success
|
|
||||||
[root@linuxtechi ~]#
|
|
||||||
```
|
|
||||||
|
|
||||||
Open the web browser, type the following URL: http://<Your-Server-IP>
|
|
||||||
|
|
||||||
[![Test-Page-HTTP-Server-Fedora-30][3]][4]
|
|
||||||
|
|
||||||
Above screen confirms that NGINX is installed successfully.
|
|
||||||
|
|
||||||
Now let’s verify PHP installation, create a test php page(info.php) using the beneath command,
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php
|
|
||||||
[root@linuxtechi ~]#
|
|
||||||
```
|
|
||||||
|
|
||||||
Type the following URL in the web browser,
|
|
||||||
|
|
||||||
http://<Your-Server-IP>/info.php
|
|
||||||
|
|
||||||
[![Php-info-page-fedora30][5]][6]
|
|
||||||
|
|
||||||
Above page confirms that PHP 7.3.5 has been installed successfully. Now let’s install MariaDB database server.
|
|
||||||
|
|
||||||
### Install MariaDB on Fedora 30
|
|
||||||
|
|
||||||
MariaDB is a great replacement for MySQL DB as it is works much similar to MySQL and also compatible with MySQL steps too. Let’s look at the steps to install MariaDB on Fedora 30 Server
|
|
||||||
|
|
||||||
### Step 1) Switch to Root User
|
|
||||||
|
|
||||||
First step in installing MariaDB in your system is to switch to root user or you can use a local user who has root privilege. Use the following command below:
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# sudo -i
|
|
||||||
[root@linuxtechi ~]#
|
|
||||||
```
|
|
||||||
|
|
||||||
### Step 2) Install latest version of MariaDB (10.3) using dnf command
|
|
||||||
|
|
||||||
Use the following command to install MariaDB on Fedora 30 Server
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# dnf install mariadb-server -y
|
|
||||||
```
|
|
||||||
|
|
||||||
### Step 3) Start and enable MariaDB Service
|
|
||||||
|
|
||||||
Once the mariadb is installed successfully in step 2), next step is to start the MariaDB service. Use the following command:
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# systemctl start mariadb.service ; systemctl enable mariadb.service
|
|
||||||
```
|
|
||||||
|
|
||||||
### Step 4) Secure MariaDB Installation
|
|
||||||
|
|
||||||
When we install MariaDB server, so by default there is no root password, also anonymous users are created in database. So, to secure MariaDB installation, run the beneath “mysql_secure_installation” command
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# mysql_secure_installation
|
|
||||||
```
|
|
||||||
|
|
||||||
Next you will be prompted with some question, just answer the questions as shown below:
|
|
||||||
|
|
||||||
![Secure-MariaDB-Installation-Part1][7]
|
|
||||||
|
|
||||||
![Secure-MariaDB-Installation-Part2][8]
|
|
||||||
|
|
||||||
### Step 5) Test MariaDB Installation
|
|
||||||
|
|
||||||
Once you have installed, you can always test if MariaDB is successfully installed on the server. Use the following command:
|
|
||||||
|
|
||||||
```
|
|
||||||
[root@linuxtechi ~]# mysql -u root -p
|
|
||||||
Enter password:
|
|
||||||
```
|
|
||||||
|
|
||||||
Next you will be prompted for a password. Enter the password same password that you have set during MariaDB secure installation, then you can see the MariaDB welcome screen.
|
|
||||||
|
|
||||||
```
|
|
||||||
Welcome to the MariaDB monitor. Commands end with ; or \g.
|
|
||||||
Your MariaDB connection id is 17
|
|
||||||
Server version: 10.3.12-MariaDB MariaDB Server
|
|
||||||
|
|
||||||
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
|
|
||||||
|
|
||||||
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
|
|
||||||
|
|
||||||
MariaDB [(none)]>
|
|
||||||
```
|
|
||||||
|
|
||||||
And finally, we’ve completed everything to install LEMP (Linux, Nginx, MariaDB and PHP) on your server successfully. Please post all your comments and suggestions in the feedback section below and we’ll respond back at the earliest.
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
via: https://www.linuxtechi.com/install-lemp-stack-fedora-30-server/
|
|
||||||
|
|
||||||
作者:[Pradeep Kumar][a]
|
|
||||||
选题:[lujun9972][b]
|
|
||||||
译者:[译者ID](https://github.com/译者ID)
|
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
||||||
|
|
||||||
[a]: https://www.linuxtechi.com/author/pradeep/
|
|
||||||
[b]: https://github.com/lujun9972
|
|
||||||
[1]: https://www.linuxtechi.com/fedora-30-workstation-installation-guide/
|
|
||||||
[2]: https://www.linuxtechi.com/wp-content/uploads/2019/06/LEMP-Stack-Fedora30.jpg
|
|
||||||
[3]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Test-Page-HTTP-Server-Fedora-30-1024x732.jpg
|
|
||||||
[4]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Test-Page-HTTP-Server-Fedora-30.jpg
|
|
||||||
[5]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Php-info-page-fedora30-1024x732.jpg
|
|
||||||
[6]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Php-info-page-fedora30.jpg
|
|
||||||
[7]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Secure-MariaDB-Installation-Part1.jpg
|
|
||||||
[8]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Secure-MariaDB-Installation-Part2.jpg
|
|
@ -1,5 +1,5 @@
|
|||||||
[#]: collector: (lujun9972)
|
[#]: collector: (lujun9972)
|
||||||
[#]: translator: ( )
|
[#]: translator: (lnrCoder)
|
||||||
[#]: reviewer: ( )
|
[#]: reviewer: ( )
|
||||||
[#]: publisher: ( )
|
[#]: publisher: ( )
|
||||||
[#]: url: ( )
|
[#]: url: ( )
|
||||||
@ -129,7 +129,7 @@ via: https://opensource.com/article/19/11/intermediate-awk-scripting
|
|||||||
|
|
||||||
作者:[Seth Kenlon][a]
|
作者:[Seth Kenlon][a]
|
||||||
选题:[lujun9972][b]
|
选题:[lujun9972][b]
|
||||||
译者:[译者ID](https://github.com/译者ID)
|
译者:[译者ID](https://github.com/lnrCoder)
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[#]: collector: (lujun9972)
|
[#]: collector: (lujun9972)
|
||||||
[#]: translator: ( )
|
[#]: translator: (robsean)
|
||||||
[#]: reviewer: ( )
|
[#]: reviewer: ( )
|
||||||
[#]: publisher: ( )
|
[#]: publisher: ( )
|
||||||
[#]: url: ( )
|
[#]: url: ( )
|
||||||
|
@ -0,0 +1,99 @@
|
|||||||
|
[#]: collector: (lujun9972)
|
||||||
|
[#]: translator: ( )
|
||||||
|
[#]: reviewer: ( )
|
||||||
|
[#]: publisher: ( )
|
||||||
|
[#]: url: ( )
|
||||||
|
[#]: subject: (Create virtual machines with Cockpit in Fedora)
|
||||||
|
[#]: via: (https://fedoramagazine.org/create-virtual-machines-with-cockpit-in-fedora/)
|
||||||
|
[#]: author: (Karlis KavacisPaul W. Frields https://fedoramagazine.org/author/karlisk/https://fedoramagazine.org/author/pfrields/)
|
||||||
|
|
||||||
|
Create virtual machines with Cockpit in Fedora
|
||||||
|
======
|
||||||
|
|
||||||
|
![][1]
|
||||||
|
|
||||||
|
This article shows you how to install the software you need to use Cockpit to create and manage virtual machines on Fedora 31. Cockpit is [an interactive admin interface][2] that lets you access and manage systems from any supported web browser. With [virt-manager being deprecated][3] users are encouraged to use Cockpit instead, which is meant to replace it.
|
||||||
|
|
||||||
|
Cockpit is an actively developed project, with many plugins available that extend how it works. For example, one such plugin is “Machines,” which interacts with libvirtd and lets users create and manage virtual machines.
|
||||||
|
|
||||||
|
### Installing software
|
||||||
|
|
||||||
|
The required software prerequisites are _libvirt_, _cockpit_ and _cockpit-machines_. To install them on Fedora 31, run the following command from a terminal [using sudo][4]:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo dnf install libvirt cockpit cockpit-machines
|
||||||
|
```
|
||||||
|
|
||||||
|
Cockpit is also included as part of the “Headless Management” package group. This group is useful for a Fedora based server that you only access through a network. In that case, to install it, use this command:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo dnf groupinstall "Headless Management"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setting up Cockpit services
|
||||||
|
|
||||||
|
After installing the necessary packages it’s time to enable the services. The _libvirtd_ service runs the virtual machines, while Cockpit has a socket activated service to let you access the Web GUI:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo systemctl enable libvirtd --now
|
||||||
|
$ sudo systemctl enable cockpit.socket --now
|
||||||
|
```
|
||||||
|
|
||||||
|
This should be enough to run virtual machines and manage them through Cockpit. Optionally, if you want to access and manage your machine from another device on your network, you need to expose the service to the network. To do this, add a new rule in your firewall configuration:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo firewall-cmd --zone=public --add-service=cockpit --permanent
|
||||||
|
$ sudo firewall-cmd --reload
|
||||||
|
```
|
||||||
|
|
||||||
|
To confirm the services are running and no issues occurred, check the status of the services:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo systemctl status libvirtd
|
||||||
|
$ sudo systemctl status cockpit.socket
|
||||||
|
```
|
||||||
|
|
||||||
|
At this point everything should be working. The Cockpit web GUI should be available at <https://localhost:9090> or <https://127.0.0.1:9090>. Or, enter the local network IP in a web browser on any other device connected to the same network. (Without SSL certificates setup, you may need to allow a connection from your browser.)
|
||||||
|
|
||||||
|
### Creating and installing a machine
|
||||||
|
|
||||||
|
Log into the interface using the user name and password for that system. You can also choose whether to allow your password to be used for administrative tasks in this session.
|
||||||
|
|
||||||
|
Select _Virtual Machines_ and then select _Create VM_ to build a new box. The console gives you several options:
|
||||||
|
|
||||||
|
* Download an OS using Cockpit’s built in library
|
||||||
|
* Use install media already downloaded on the system you’re managing
|
||||||
|
* Point to a URL for an OS installation tree
|
||||||
|
* Boot media over the network via the [PXE][5] protocol
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Enter all the necessary parameters. Then select _Create_ to power up the new virtual machine.
|
||||||
|
|
||||||
|
At this point, a graphical console appears. Most modern web browsers let you use your keyboard and mouse to interact with the VM console. Now you can complete your installation and use your new VM, just as you would [via virt-manager in the past][6].
|
||||||
|
|
||||||
|
* * *
|
||||||
|
|
||||||
|
_Photo by [Miguel Teixeira][7] on [Flickr][8] (CC BY-SA 2.0)._
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://fedoramagazine.org/create-virtual-machines-with-cockpit-in-fedora/
|
||||||
|
|
||||||
|
作者:[Karlis KavacisPaul W. Frields][a]
|
||||||
|
选题:[lujun9972][b]
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://fedoramagazine.org/author/karlisk/https://fedoramagazine.org/author/pfrields/
|
||||||
|
[b]: https://github.com/lujun9972
|
||||||
|
[1]: https://fedoramagazine.org/wp-content/uploads/2019/11/create-vm-cockpit-816x345.jpg
|
||||||
|
[2]: https://cockpit-project.org/
|
||||||
|
[3]: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/8.0_release_notes/rhel-8_0_0_release#virtualization_4
|
||||||
|
[4]: https://fedoramagazine.org/howto-use-sudo/
|
||||||
|
[5]: https://en.wikipedia.org/wiki/Preboot_Execution_Environment
|
||||||
|
[6]: https://fedoramagazine.org/full-virtualization-system-on-fedora-workstation-30/
|
||||||
|
[7]: https://flickr.com/photos/miguelteixeira/
|
||||||
|
[8]: https://flickr.com/photos/miguelteixeira/2964851828/
|
@ -0,0 +1,233 @@
|
|||||||
|
[#]: collector: (lujun9972)
|
||||||
|
[#]: translator: ( )
|
||||||
|
[#]: reviewer: ( )
|
||||||
|
[#]: publisher: ( )
|
||||||
|
[#]: url: ( )
|
||||||
|
[#]: subject: (How to Manage Remote Windows Host using Ansible)
|
||||||
|
[#]: via: (https://www.linuxtechi.com/manage-windows-host-using-ansible/)
|
||||||
|
[#]: author: (James Kiarie https://www.linuxtechi.com/author/james/)
|
||||||
|
|
||||||
|
How to Manage Remote Windows Host using Ansible
|
||||||
|
======
|
||||||
|
|
||||||
|
**Ansible** is increasingly becoming the go-to platform for application deployment, and software provisioning among developers owing to its ease of use and flexibility. Furthermore, it is easy to set up and no agent is required to be installed on remote nodes, instead, Ansible uses password less SSH authentication to manage remote Unix/Linux hosts. In this topic, however, we are going to see how you can manage Windows Host using Ansible.
|
||||||
|
|
||||||
|
[![Manage-Windows-Hosts-using-Ansible][1]][2]
|
||||||
|
|
||||||
|
**Lab setup**
|
||||||
|
|
||||||
|
We shall use the setup below to accomplish our objective
|
||||||
|
|
||||||
|
* Ansible Control node – CentOS 8 – IP: 192.168.43.13
|
||||||
|
* Windows 10 node – Windows 10 – IP: 192.168.43.147
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Part 1: Installing Ansible on the Control node (CentOS 8)
|
||||||
|
|
||||||
|
Before anything else, we need to get Ansible installed on the Control node which is the CentOS 8 system.
|
||||||
|
|
||||||
|
#### Step 1: Verify that Python3 is installed on Ansible control node
|
||||||
|
|
||||||
|
Firstly, we need to confirm if Python3 is installed. CentOS 8 ships with Python3 but if it’s missing for any reason, install using the command:
|
||||||
|
|
||||||
|
```
|
||||||
|
# sudo dnf install python3
|
||||||
|
```
|
||||||
|
|
||||||
|
Next, make Python3 the default Python version by running:
|
||||||
|
|
||||||
|
```
|
||||||
|
# sudo alternatives --set python /usr/bin/python3
|
||||||
|
```
|
||||||
|
|
||||||
|
To verify if python3 is installed, run the command:
|
||||||
|
|
||||||
|
```
|
||||||
|
# python --version
|
||||||
|
```
|
||||||
|
|
||||||
|
**![check-python-version][1] **
|
||||||
|
|
||||||
|
**Read Also :** **[How to Install Ansible (Automation Tool) on CentOS 8/RHEL 8][3]**
|
||||||
|
|
||||||
|
#### Step 2: Install a virtual environment for running Ansible
|
||||||
|
|
||||||
|
For this exercise, an isolated environment for running and testing Ansible is preferred. This will keep at bay issues such as dependency problems and package conflicts. The isolated environment we are going to create is called a virtual environment.
|
||||||
|
|
||||||
|
Firstly, let’s begin with the installation of the virtual environment on CentOS 8.
|
||||||
|
|
||||||
|
```
|
||||||
|
# sudo dnf install python3-virtualenv
|
||||||
|
```
|
||||||
|
|
||||||
|
![install-python3-virtualenv][1]
|
||||||
|
|
||||||
|
After the installation of the virtual environment, create a virtual workspace by running:
|
||||||
|
|
||||||
|
```
|
||||||
|
# virtualenv env
|
||||||
|
```
|
||||||
|
|
||||||
|
![virtualenv-env-ansible][1]
|
||||||
|
|
||||||
|
```
|
||||||
|
# source env/bin/activate
|
||||||
|
```
|
||||||
|
|
||||||
|
![source-env-bin-activate-ansible][1]
|
||||||
|
|
||||||
|
Great! Observer that the prompt has now changed to (env).
|
||||||
|
|
||||||
|
#### Step 3: Install Ansible
|
||||||
|
|
||||||
|
After the creation of the virtual environment, proceed and install Ansible automation tool using pip as shown:
|
||||||
|
|
||||||
|
```
|
||||||
|
# pip install ansible
|
||||||
|
```
|
||||||
|
|
||||||
|
![pip-install-Ansible][1]
|
||||||
|
|
||||||
|
You can later confirm the installation of Ansible using the command:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ansible --version
|
||||||
|
```
|
||||||
|
|
||||||
|
![check-ansible-version][1]
|
||||||
|
|
||||||
|
To test Ansible and see if it’s working on our Ansible Control server run:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ansible localhost -m ping
|
||||||
|
```
|
||||||
|
|
||||||
|
![Test-ansible-for-connectivity][1]
|
||||||
|
|
||||||
|
Great! Next, we need to define the Windows host or system on a host file on the Ansible control node. Therefore, open the default hosts file
|
||||||
|
|
||||||
|
```
|
||||||
|
# vim /etc/ansible/hosts
|
||||||
|
```
|
||||||
|
|
||||||
|
Define the Windows hosts as shown below.
|
||||||
|
|
||||||
|
![Ansible-hosts-file][1]
|
||||||
|
|
||||||
|
**Note:** The username and password point to the user on the Windows host system.
|
||||||
|
|
||||||
|
Next, save and exit the configuration file.
|
||||||
|
|
||||||
|
#### Step 4: Install Pywinrm
|
||||||
|
|
||||||
|
Unlike in Unix systems where Ansible uses SSH to communicate with remote hosts, with Windows it’s a different story altogether. To communicate with Windows hosts, you need to install Winrm.
|
||||||
|
|
||||||
|
To install winrm, once again, use pip tool as shown:
|
||||||
|
|
||||||
|
```
|
||||||
|
# pip install pywinrm
|
||||||
|
```
|
||||||
|
|
||||||
|
![install-pywinrm][1]
|
||||||
|
|
||||||
|
### Part 2: Configuring Windows Host
|
||||||
|
|
||||||
|
In this section, we are going to configure our Windows 10 remote host system to connect with the Ansible Control node. We are going to install the **WinRM listener-** short for **Windows Remote** – which will allow the connection between the Windows host system and the Ansible server.
|
||||||
|
|
||||||
|
But before we do so, your Windows host system needs to fulfill a few requirements for the installation to succeed:
|
||||||
|
|
||||||
|
* Your Windows host system should be **Windows 7 or later**. For Servers, ensure that you are using **Windows Server 2008** and later versions.
|
||||||
|
* Ensure your system is running **.NET Framework 4.0** and later.
|
||||||
|
* Windows **PowerShell** should be Version 3.0 & later
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
With all the requirements met, now follow the steps stipulated below:
|
||||||
|
|
||||||
|
#### Step 1: Download the WinRM script on Windows 10 host
|
||||||
|
|
||||||
|
WinRM can be installed using a script that you can download from this [link][4]. Copy the entire script and paste it onto the notepad editor. Thereafter, ensure you save the WinRM script at the most convenient location. In our case, we have saved the file on the Desktop under the name ConfigureRemotingForAnsible.ps1
|
||||||
|
|
||||||
|
#### Step 2: Run the WinRM script on Windows 10 host
|
||||||
|
|
||||||
|
Next, run PowerShell as the Administrator
|
||||||
|
|
||||||
|
![Run-PowerShell-as-Administrator][1]
|
||||||
|
|
||||||
|
Navigate to the script location and run it. In this case, we have navigated to the Desktop location where we saved the script. Next, proceed and execute the WinRM script on the WIndows host:
|
||||||
|
|
||||||
|
```
|
||||||
|
.\ConfigureRemotingForAnsible.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
This takes about a minute and you should get the output shown below. The output shows that WinRM has successfully been installed.
|
||||||
|
|
||||||
|
![set-up-WinRM-on-Windows10][1]
|
||||||
|
|
||||||
|
### Part 3: Connecting to Windows Host from Ansible Control Node
|
||||||
|
|
||||||
|
To test connectivity to the Windows 10 host, run the command:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ansible winhost -m win_ping
|
||||||
|
```
|
||||||
|
|
||||||
|
![Ansible-ping-windows-host-machine][1]
|
||||||
|
|
||||||
|
The output shows that we have indeed established a connection to the remote Windows 10 host from the Ansible Control node. This implies that we can now manage the remote Windows host using Ansible Playbooks. Let’s create a sample playbook for the Windows host system.
|
||||||
|
|
||||||
|
### Part 4: Creating and running a playbook for Windows 10 host
|
||||||
|
|
||||||
|
In this final section, we shall create a playbook and create a task that will install Chocolatey on the remote host. Chocolatey is a package manager for Windows system. The play is defined as shown:
|
||||||
|
|
||||||
|
```
|
||||||
|
# vim chocolatey.yml
|
||||||
|
---
|
||||||
|
- host: winhost
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- name: Install Chocolatey on Windows10
|
||||||
|
win_chocolatey: name=procexp status=present
|
||||||
|
```
|
||||||
|
|
||||||
|
![Ansible-Playbook-install-chocolatey][1]
|
||||||
|
|
||||||
|
Save and close the yml file. Next, execute the playbook as shown
|
||||||
|
|
||||||
|
```
|
||||||
|
# ansible-playbook chocolatey.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
![Ansible-playBook-succeeded][1]
|
||||||
|
|
||||||
|
The output is a pointer that all went well. And this concludes this topic on how you can manage Windows host using Ansible.
|
||||||
|
|
||||||
|
* [Facebook][5]
|
||||||
|
* [Twitter][6]
|
||||||
|
* [LinkedIn][7]
|
||||||
|
* [Reddit][8]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://www.linuxtechi.com/manage-windows-host-using-ansible/
|
||||||
|
|
||||||
|
作者:[James Kiarie][a]
|
||||||
|
选题:[lujun9972][b]
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://www.linuxtechi.com/author/james/
|
||||||
|
[b]: https://github.com/lujun9972
|
||||||
|
[1]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||||
|
[2]: http://www.linuxtechi.com/wp-content/uploads/2019/11/Manage-Windows-Hosts-using-Ansible.jpg
|
||||||
|
[3]: http://www.linuxtechi.com/install-ansible-centos-8-rhel-8/
|
||||||
|
[4]: https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1
|
||||||
|
[5]: http://www.facebook.com/sharer.php?u=https%3A%2F%2Fwww.linuxtechi.com%2Fmanage-windows-host-using-ansible%2F&t=How%20to%20Manage%20Remote%20Windows%20Host%20using%20Ansible
|
||||||
|
[6]: http://twitter.com/share?text=How%20to%20Manage%20Remote%20Windows%20Host%20using%20Ansible&url=https%3A%2F%2Fwww.linuxtechi.com%2Fmanage-windows-host-using-ansible%2F&via=Linuxtechi
|
||||||
|
[7]: http://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.linuxtechi.com%2Fmanage-windows-host-using-ansible%2F&title=How%20to%20Manage%20Remote%20Windows%20Host%20using%20Ansible
|
||||||
|
[8]: http://www.reddit.com/submit?url=https%3A%2F%2Fwww.linuxtechi.com%2Fmanage-windows-host-using-ansible%2F&title=How%20to%20Manage%20Remote%20Windows%20Host%20using%20Ansible
|
@ -0,0 +1,146 @@
|
|||||||
|
[#]: collector: (lujun9972)
|
||||||
|
[#]: translator: ( )
|
||||||
|
[#]: reviewer: ( )
|
||||||
|
[#]: publisher: ( )
|
||||||
|
[#]: url: ( )
|
||||||
|
[#]: subject: (How to write a Python web API with Flask)
|
||||||
|
[#]: via: (https://opensource.com/article/19/11/python-web-api-flask)
|
||||||
|
[#]: author: (Rachel Waston https://opensource.com/users/rachelwaston)
|
||||||
|
|
||||||
|
How to write a Python web API with Flask
|
||||||
|
======
|
||||||
|
Use Flask, one of the fastest-growing Python frameworks, to fetch data
|
||||||
|
from a server, in this quick tutorial.
|
||||||
|
![spiderweb diagram][1]
|
||||||
|
|
||||||
|
[Python][2] is a high-level, object-oriented programming language known for its simple syntax. It is consistently among the top-rated programming languages for building RESTful APIs.
|
||||||
|
|
||||||
|
[Flask][3] is a customizable Python framework that gives developers complete control over how users access data. Flask is a "micro-framework" based on Werkzeug's [WSGI][4] toolkit and Jinja 2's templating engine. It is designed as a web framework for RESTful API development.
|
||||||
|
|
||||||
|
Flask is one of the fastest-growing Python frameworks, and popular websites, including Netflix, Pinterest, and LinkedIn, have incorporated Flask into their development stacks. Here's an example of how Flask can permit users to fetch data from a server using the HTTP GET method.
|
||||||
|
|
||||||
|
### Set up a Flask application
|
||||||
|
|
||||||
|
First, create a structure for your Flask application. You can do this at any location on your system.
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
$ mkdir tutorial
|
||||||
|
$ cd tutorial
|
||||||
|
$ touch main.py
|
||||||
|
$ python3 -m venv env
|
||||||
|
$ source env/bin/activate
|
||||||
|
(env) $ pip3 install flask-restful
|
||||||
|
Collecting flask-restful
|
||||||
|
Downloading <https://files.pythonhosted.org/packages/17/44/6e49...8da4/Flask\_RESTful-0.3.7-py2.py3-none-any.whl>
|
||||||
|
Collecting Flask>=0.8 (from flask-restful)
|
||||||
|
[...]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Import the Flask modules
|
||||||
|
|
||||||
|
Next, import the **flask** module and its **flask_restful** library into your **main.py** code:
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
from flask import Flask
|
||||||
|
from flask_restful import Resource, Api
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
api = Api(app)
|
||||||
|
|
||||||
|
class Quotes(Resource):
|
||||||
|
def get(self):
|
||||||
|
return {
|
||||||
|
'William Shakespeare': {
|
||||||
|
'quote': ['Love all,trust a few,do wrong to none',
|
||||||
|
'Some are born great, some achieve greatness, and some greatness thrust upon them.']
|
||||||
|
},
|
||||||
|
'Linus': {
|
||||||
|
'quote': ['Talk is cheap. Show me the code.']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
api.add_resource(Quotes, '/')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run the app
|
||||||
|
|
||||||
|
Flask includes a built-in HTTP server for testing. Test the simple API you built:
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
(env) $ python main.py
|
||||||
|
* Serving Flask app "main" (lazy loading)
|
||||||
|
* Environment: production
|
||||||
|
WARNING: This is a development server. Do not use it in a production deployment.
|
||||||
|
Use a production WSGI server instead.
|
||||||
|
* Debug mode: on
|
||||||
|
* Running on <http://127.0.0.1:5000/> (Press CTRL+C to quit)
|
||||||
|
```
|
||||||
|
|
||||||
|
Starting the development server starts your Flask application, which contains a method named **get** to respond to a simple HTTP GET request. You can test it using **wget** or **curl** or any web browser. The URL to use is provided in Flask's output after you start the server.
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
$ curl <http://localhost:5000>
|
||||||
|
{
|
||||||
|
"William Shakespeare": {
|
||||||
|
"quote": [
|
||||||
|
"Love all,trust a few,do wrong to none",
|
||||||
|
"Some are born great, some achieve greatness, and some greatness thrust upon them."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Linus": {
|
||||||
|
"quote": [
|
||||||
|
"Talk is cheap. Show me the code."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To see a more complex version of a similar web API using Python and Flask, navigate to the Library of Congress' [Chronicling America][5] website, which provides access to information about historic newspapers and digitized newspaper pages.
|
||||||
|
|
||||||
|
### Why use Flask?
|
||||||
|
|
||||||
|
Flask has several major benefits:
|
||||||
|
|
||||||
|
1. Python is popular and widely used, so anyone who knows Python can develop for Flask.
|
||||||
|
2. It's lightweight and minimalistic.
|
||||||
|
3. Built with security in mind.
|
||||||
|
4. Great documentation with plenty of clear, working example code.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
There are also some potential drawbacks:
|
||||||
|
|
||||||
|
1. It's lightweight and minimalistic. If you're looking for a framework with lots of bundled libraries and prefabricated components, this may not be your best option.
|
||||||
|
2. If you have to build your own framework around Flask, you might find that the cost of maintaining your customization negates the benefit of using Flask.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
If you're looking to build a web app or API, Flask is a good option to consider. It's powerful and robust, and the project documentation makes it easy to get started. Try it out, evaluate it, and see if it's right for your project.
|
||||||
|
|
||||||
|
Learn more in this lesson in Python exception handling and how to do it in a secure manner.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://opensource.com/article/19/11/python-web-api-flask
|
||||||
|
|
||||||
|
作者:[Rachel Waston][a]
|
||||||
|
选题:[lujun9972][b]
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://opensource.com/users/rachelwaston
|
||||||
|
[b]: https://github.com/lujun9972
|
||||||
|
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/web-cms-build-howto-tutorial.png?itok=bRbCJt1U (spiderweb diagram)
|
||||||
|
[2]: https://www.python.org/
|
||||||
|
[3]: https://palletsprojects.com/p/flask/
|
||||||
|
[4]: https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface
|
||||||
|
[5]: https://chroniclingamerica.loc.gov/about/api
|
@ -0,0 +1,200 @@
|
|||||||
|
[#]: collector: (lujun9972)
|
||||||
|
[#]: translator: (robsean)
|
||||||
|
[#]: reviewer: ( )
|
||||||
|
[#]: publisher: ( )
|
||||||
|
[#]: url: ( )
|
||||||
|
[#]: subject: (How to Install LEMP (Linux, Nginx, MariaDB, PHP) on Fedora 30 Server)
|
||||||
|
[#]: via: (https://www.linuxtechi.com/install-lemp-stack-fedora-30-server/)
|
||||||
|
[#]: author: (Pradeep Kumar https://www.linuxtechi.com/author/pradeep/)
|
||||||
|
|
||||||
|
如何在 Fedora 30 Server 上安装 LEMP (Linux, Nginx, MariaDB, PHP)
|
||||||
|
======
|
||||||
|
|
||||||
|
在这篇文章中,我们将看看如何在 Fedora 30 Server 上安装 **LEMP** 。LEMP 代表:
|
||||||
|
|
||||||
|
* L -> Linux
|
||||||
|
* E -> Nginx
|
||||||
|
* M -> Maria DB
|
||||||
|
* P -> PHP
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
我假设 **[Fedora 30][1]** 已经安装在你的电脑系统上。
|
||||||
|
|
||||||
|
![LEMP-Stack-Fedora30][2]
|
||||||
|
|
||||||
|
LEMP 是一组强大的软件设置集合,它安装在一个 Linux 服务器上以帮助使用流行的开发平台来构建网站,LEMP 是 LAMP 的一个变种,在其中不是 **Apache** ,而是使用 **EngineX (Nginx)** , 此外,使用 **MariaDB** 代替 **MySQL** 。这篇入门指南是一个安装 Nginx, Maria DB 和 PHP 的独立指南的作品集合。
|
||||||
|
|
||||||
|
### 在 Fedora 30 Server 上安装 Nginx ,PHP 7.3 和 PHP-FPM
|
||||||
|
|
||||||
|
让我们看看如何在 Fedora 30 Server 上安装 Nginx 和 PHP 以及 PHP FPM 。
|
||||||
|
|
||||||
|
### 步骤 1) 切换到 root 用户
|
||||||
|
|
||||||
|
在系统上安装 Nginx 的第一步是切换到 root 用户。使用下面的命令:
|
||||||
|
|
||||||
|
```
|
||||||
|
root@linuxtechi ~]$ sudo -i
|
||||||
|
[sudo] password for pkumar:
|
||||||
|
[root@linuxtechi ~]#
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤 2) 使用 dnf 命令安装 Nginx ,PHP 7.3 和 PHP FPM
|
||||||
|
|
||||||
|
使用下面的 dnf 命令安装 Nginx :
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# dnf install nginx php php-fpm php-common -y
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤 3) 安装额外的 PHP 模块
|
||||||
|
|
||||||
|
PHP 的默认安装仅自带基本模块和最需要的模块,如果你需要额外的模块,像 PHP 支持的 GD ,XML ,命令行接口 Zend OPCache 功能等等,你总是能够选择你的软件包,并一次性安装所有的东西。查看下面的示例命令:
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# sudo dnf install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml -y
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤 4) 开始 & 启用 Nginx 和 PHP-fpm 服务
|
||||||
|
|
||||||
|
使用下面的命令来开始并启用 Nginx 服务
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# systemctl start nginx && systemctl enable nginx
|
||||||
|
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
|
||||||
|
[root@linuxtechi ~]#
|
||||||
|
```
|
||||||
|
|
||||||
|
使用下面的命令来开始并启用 PHP-FPM 服务
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# systemctl start php-fpm && systemctl enable php-fpm
|
||||||
|
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
|
||||||
|
[root@linuxtechi ~]#
|
||||||
|
```
|
||||||
|
|
||||||
|
**核实 Nginx (Web 服务) 和 PHP 安装,**
|
||||||
|
|
||||||
|
**注意:** 假使操作系统防火墙是启用的,并运行在你的 Fedora 30 系统上,那么使用下面的命令来准许 80 和 443 端口,
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# firewall-cmd --permanent --add-service=http
|
||||||
|
success
|
||||||
|
[root@linuxtechi ~]#
|
||||||
|
[root@linuxtechi ~]# firewall-cmd --permanent --add-service=https
|
||||||
|
success
|
||||||
|
[root@linuxtechi ~]# firewall-cmd --reload
|
||||||
|
success
|
||||||
|
[root@linuxtechi ~]#
|
||||||
|
```
|
||||||
|
|
||||||
|
打开网页浏览器,输入下面的 URL: http://<Your-Server-IP>
|
||||||
|
|
||||||
|
[![Test-Page-HTTP-Server-Fedora-30][3]][4]
|
||||||
|
|
||||||
|
上面的屏幕证实 NGINX 已经成功地安装。
|
||||||
|
|
||||||
|
现在,让我们核实 PHP 安装,使用下面的命令创建一个测试 php 页(info.php),
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php
|
||||||
|
[root@linuxtechi ~]#
|
||||||
|
```
|
||||||
|
|
||||||
|
在网页浏览器中输入下面的 URL ,
|
||||||
|
|
||||||
|
http://<Your-Server-IP>/info.php
|
||||||
|
|
||||||
|
[![Php-info-page-fedora30][5]][6]
|
||||||
|
|
||||||
|
上面的页面验证 PHP 7.3.5 已经被成功地安装。现在,让我们安装 MariaDB 数据库服务器。
|
||||||
|
|
||||||
|
### 在 Fedora 30 上安装 MariaDB
|
||||||
|
|
||||||
|
MariaDB 是 MySQL 数据库的一个极好的替代品,因为它的工作方式与 MySQL 非常类似,并且兼容性也与 MySQL 一致。让我们看看在 Fedora 30 Server 上安装 MariaDB 的步骤。
|
||||||
|
|
||||||
|
### 步骤 1) 切换到 root 用户
|
||||||
|
|
||||||
|
在系统上安装 MariaDB 的第一步是切换到 root 用户,或者你可以使用有 root 权限的本地用户。使用下面的命令:
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# sudo -i
|
||||||
|
[root@linuxtechi ~]#
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤 2) 使用 dnf 命令安装 MariaDB (10.3) 的最新版本
|
||||||
|
|
||||||
|
在 Fedora 30 Server 上使用下面的命令来安装 MariaDB
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# dnf install mariadb-server -y
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤 3) 开启并启用 MariaDB 服务
|
||||||
|
|
||||||
|
在步骤2中成功地安装 mariadb 后,接下来的步骤是开启 MariaDB 服务。使用下面的命令:
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# systemctl start mariadb.service ; systemctl enable mariadb.service
|
||||||
|
```
|
||||||
|
|
||||||
|
### 步骤 4) 保护 MariaDB 安装
|
||||||
|
|
||||||
|
当我们安装 MariaDB 服务器时,因为默认情况下没有 root密码,在数据库中也创建匿名用户。因此,来保护 MariaDB 安装,运行下面的 “mysql_secure_installation” 命令
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# mysql_secure_installation
|
||||||
|
```
|
||||||
|
|
||||||
|
接下来你将被提示一些问题,仅回答下面展示的问题:
|
||||||
|
|
||||||
|
![Secure-MariaDB-Installation-Part1][7]
|
||||||
|
|
||||||
|
![Secure-MariaDB-Installation-Part2][8]
|
||||||
|
|
||||||
|
### 步骤 5) 测试 MariaDB 安装
|
||||||
|
|
||||||
|
在你安装后,你总是能够测试是否 MariaDB 被成功地安装在 Fedora 30 Server 上。使用下面的命令:
|
||||||
|
|
||||||
|
```
|
||||||
|
[root@linuxtechi ~]# mysql -u root -p
|
||||||
|
Enter password:
|
||||||
|
```
|
||||||
|
|
||||||
|
接下来,你将被提示一个密码。输入在 MariaDB 保护安装期间你设置的密码,接下来你可以看到 MariaDB 欢迎屏幕。
|
||||||
|
|
||||||
|
```
|
||||||
|
Welcome to the MariaDB monitor. Commands end with ; or \g.
|
||||||
|
Your MariaDB connection id is 17
|
||||||
|
Server version: 10.3.12-MariaDB MariaDB Server
|
||||||
|
|
||||||
|
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
|
||||||
|
|
||||||
|
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
|
||||||
|
|
||||||
|
MariaDB [(none)]>
|
||||||
|
```
|
||||||
|
|
||||||
|
最后,我们已经在你的 Fedora 30 Server 上成功地完成安装 LEMP (Linux, Nginx, MariaDB and PHP) 的所有工作。请在下面的反馈部分发布你的评论和建议,我们将尽快在后面回应。
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://www.linuxtechi.com/install-lemp-stack-fedora-30-server/
|
||||||
|
|
||||||
|
作者:[Pradeep Kumar][a]
|
||||||
|
选题:[lujun9972][b]
|
||||||
|
译者:[robsean](https://github.com/robsean)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://www.linuxtechi.com/author/pradeep/
|
||||||
|
[b]: https://github.com/lujun9972
|
||||||
|
[1]: https://www.linuxtechi.com/fedora-30-workstation-installation-guide/
|
||||||
|
[2]: https://www.linuxtechi.com/wp-content/uploads/2019/06/LEMP-Stack-Fedora30.jpg
|
||||||
|
[3]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Test-Page-HTTP-Server-Fedora-30-1024x732.jpg
|
||||||
|
[4]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Test-Page-HTTP-Server-Fedora-30.jpg
|
||||||
|
[5]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Php-info-page-fedora30-1024x732.jpg
|
||||||
|
[6]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Php-info-page-fedora30.jpg
|
||||||
|
[7]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Secure-MariaDB-Installation-Part1.jpg
|
||||||
|
[8]: https://www.linuxtechi.com/wp-content/uploads/2019/06/Secure-MariaDB-Installation-Part2.jpg
|
@ -1,221 +0,0 @@
|
|||||||
[#]: collector: (lujun9972)
|
|
||||||
[#]: translator: (robsean)
|
|
||||||
[#]: reviewer: ( )
|
|
||||||
[#]: publisher: ( )
|
|
||||||
[#]: url: ( )
|
|
||||||
[#]: subject: (7 Java tips for new developers)
|
|
||||||
[#]: via: (https://opensource.com/article/19/10/java-basics)
|
|
||||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
|
||||||
|
|
||||||
给新 Java 开发者的 7 点提示
|
|
||||||
======
|
|
||||||
如果你只是刚刚开始 Java 编程,这里有七个你需要知道的基础知识。
|
|
||||||
![Coffee and laptop][1]
|
|
||||||
|
|
||||||
Java 是一个多功能的编程语言,在某种程度上,是一种通用的编程语言,在某种程度上,在几乎所有可能涉及计算机的行业。 Java 的最大优势是,它运行在一个 Java 虚拟机(JVM)中,一个翻译 Java 代码为操作系统兼容的字节码的层。只要有一个 JVM 存在于你的操作系统上,不管这个操作系统是在一个服务器 (或 [无服务器][2], 也是同样的), 桌面电脑,笔记本电脑,移动设备,或嵌入式设备,那么,一个 Java 应用程序可以运行在它上面。
|
|
||||||
|
|
||||||
这使得 Java 成为程序员和用户中间的一种流行语言。程序员知道,他们只需要写一个软件版本就能最终得到一个在任何平台上运行是应用程序,用户知道,一个应用程序将运行在他们的计算机上运行,而不用管他们使用什么样的操作系统。
|
|
||||||
|
|
||||||
很多语言和框架是跨平台的,但是没有实现同样的抽象层。使用 Java ,你的目标是 JVM ,而不是操作系统。对于程序员,当面对一些编程难题时,这些是阻力最小的线路,但是它仅在当你知道如何编程 Java 时有用。如果你刚开始 Java 编程,这里有你需要知道是七个基础的提示。
|
|
||||||
|
|
||||||
但是,首先,如果你不确定是否你安装了 Java ,你可以在一个终端(例如 [Bash][3] 或 [PowerShell][4]) 中找出来,通过运行:
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
$ java --version
|
|
||||||
openjdk 12.0.2 2019-07-16
|
|
||||||
OpenJDK Runtime Environment 19.3 (build 12.0.2+9)
|
|
||||||
OpenJDK 64-Bit Server VM 19.3 (build 12.0.2+9, mixed mode, sharing)
|
|
||||||
```
|
|
||||||
|
|
||||||
如果你获得一个错误,或未返回任何东西,那么你应该安装 [Java Development Kit][5] (JDK) 来开始 Java 开发。或者,安装一个 Java 运行时环境 ****(JRE) ,如果你只需要来运行 Java 应用程序。
|
|
||||||
|
|
||||||
### 1\. Java 软件包
|
|
||||||
|
|
||||||
在 Java 语言中,相关的类被分组到一个 _软件包_ 中。当你下载 JDK 时所获得的基本的 Java 库将被分组到以 **java** 或 **javax** 开头的软件包中。软件包提供一种类似于计算机上的文件夹的功能:它们为相关的元素提供结构和定义 (在编程术语中, _命名空间_)。额外的软件包可以从独立的代码,开源项目和商业供应商获得,就想可以为任何编程语言获得库一样。
|
|
||||||
|
|
||||||
当你写一个 Java 程序时,你应该在你的代码是顶部声明一个软件包。 如果你只是编写一个简单的应用程序来开始 Java ,你的软件包名称可以和你的项目的名称一样简单。如果你正在使用一个 Java 集成开发环境,像 [Eclipse][6] ,当你启动一个新的项目时,它为你生成一个合乎情理的软件包名称。
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
package helloworld;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author seth
|
|
||||||
* An application written in Java.
|
|
||||||
*/
|
|
||||||
```
|
|
||||||
|
|
||||||
除此之外,你可以通过查找它的关系到你的项目的广泛定义的路径来查明你的软件包的名称。例如,如果你正在写一组类来帮助游戏开发,并且集合被称为 **jgamer** ,那么你可能在其中有一些唯一的类。
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
package jgamer.avatar;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author seth
|
|
||||||
* An imaginary game library.
|
|
||||||
*/
|
|
||||||
```
|
|
||||||
|
|
||||||
你的软件包的顶层是 **jgamer** ,并且在其内部中每个软件包都是一个独立的派生物,例如 **jgamer.avatar** 和 **jgamer.score** 等等。在你的文件系统找那个,该结构反映这一点,**jgamer** 是包含文件 **avatar.java** 和 **score.java** 的顶级目录。
|
|
||||||
|
|
||||||
### 2\. Java 导入
|
|
||||||
|
|
||||||
作为一名通晓多种语言的程序员,最大的乐趣是尝试是否跟踪 **include** , **import** , **use** , **require** ,或 **一些其它术语** 。无论你正在使用何种编程语言编写一个库。在 Java 中,对于记录,当导入你的代码的需要的库时,使用 **import** 关键字。
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
package helloworld;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author seth
|
|
||||||
* A GUI hello world.
|
|
||||||
*/
|
|
||||||
```
|
|
||||||
|
|
||||||
导入工作基于一个环境的 Java 路径。如果 Java 不知道Java 库存储在系统上的何处,那么,导入可能不成功。只要一个库被存储在系统的 Java 路径中,那么导入能够成功,并且库能够被用于构建和运行一个 Java 应用程序。
|
|
||||||
|
|
||||||
如果不希望一个库在 Java 路径中(因为,例如,你正在写你自己的库),那么库可以与你的应用程序绑定在一起(协议许可),以便导入工作按预期工作。
|
|
||||||
|
|
||||||
### 3\. Java 类
|
|
||||||
|
|
||||||
一个 Java 类被使用关键字 **public class** 声明,以及一个唯一的反应它的文件名称的类名称。例如,在项目 **helloworld** 中的一个文件**Hello.java** 中:
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
package helloworld;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author seth
|
|
||||||
* A GUI hello world.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Hello {
|
|
||||||
// this is an empty class
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
你可以在一个类内部声明变量和函数。在 Java 中,在一个类中的变量被称为 _终端_ 。
|
|
||||||
|
|
||||||
### 4\. Java 方法
|
|
||||||
|
|
||||||
Java 方法本质上是在一个对象中的函数。 基于预期返回的数据类型,它们被定义为 **public** (意味着它们可以被任何其它类访问) 或 **private** (限制它们使用),例入 **void** , **int** , **float** 等等。
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
public void helloPrompt([ActionEvent][7] event) {
|
|
||||||
[String][8] salutation = "Hello %s";
|
|
||||||
|
|
||||||
string helloMessage = "World";
|
|
||||||
message = [String][8].format(salutation, helloMessage);
|
|
||||||
[JOptionPane][9].showMessageDialog(this, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int someNumber (x) {
|
|
||||||
return x*2;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
当直接调用一个方法时,它被它的类和方法名称引用。例如, **Hello.someNumber** 指向在 **Hello** 类中的 **someNumber** 方法。
|
|
||||||
|
|
||||||
### 5\. 静态的
|
|
||||||
|
|
||||||
在 Java 中的 **static** 关键字使在你的代码中的一个成员独立地访问包含它的对象。
|
|
||||||
|
|
||||||
在面向对象编程中,在应用程序运行时,你所编写代码将作为所生成“对象”的一个模板。你不需要编写一个明确的窗口,例如,在 Java(和你所修改的代码)中,基于一个窗口类的一个窗口的一个 _实例_ 。因为,你所编码的东西将不“存在”,直到应用程序生成它的一个实例为止,大多数的方法和变量(和甚至嵌套类)将不能被使用,直到它们依赖的对象在被创建为止。
|
|
||||||
|
|
||||||
然而,有时,在它被通过应用程序创建前,你需要访问或使用在一个对象中的数据。(例如,没有事先知道球是红色时,一个应用程序不能生成一个红色的球)。对于这些情况,这里有 **static** 关键字。
|
|
||||||
|
|
||||||
### 6\. Try 和 catch
|
|
||||||
|
|
||||||
Java 擅长捕捉错误,但是,你告诉它做什么,它才能优雅地恢复。在 Java 中,以 **try** 开头来尝试级联层次结构执行一个动作,略微退回到 **catch** ,并以 **finally** 结尾。可能 **try** 分句会不执行,那么 **catch** 被引用,在结尾,不管结果如何,总是由 **finally** 来执行一些合理的动作。这里是一个示例:
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
try {
|
|
||||||
cmd = parser.parse(opt, args);
|
|
||||||
|
|
||||||
if(cmd.hasOption("help")) {
|
|
||||||
HelpFormatter helper = new HelpFormatter();
|
|
||||||
helper.printHelp("Hello <options>", opt);
|
|
||||||
[System][10].exit(0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(cmd.hasOption("shell") || cmd.hasOption("s")) {
|
|
||||||
[String][8] target = cmd.getOptionValue("tgt");
|
|
||||||
} // else
|
|
||||||
} // fi
|
|
||||||
} catch ([ParseException][11] err) {
|
|
||||||
[System][10].out.println(err);
|
|
||||||
[System][10].exit(1);
|
|
||||||
} //catch
|
|
||||||
finally {
|
|
||||||
new Hello().helloWorld(opt);
|
|
||||||
} //finally
|
|
||||||
} //try
|
|
||||||
```
|
|
||||||
|
|
||||||
它是一个健壮的系统,它试图避免无法挽回的错误,或者,至少,向你提供给予用户有用的反馈的选项。经常使用它,你的用户将会感谢你!
|
|
||||||
|
|
||||||
### 7\. 运行一个 Java 应用程序
|
|
||||||
|
|
||||||
Java 文件,通常以 **.java** 结尾,理论上说,可以使用 **java** 命令运行。然而,如果一个应用程序是复杂的,运行一个单个文件是否会造成有意义的事将是另外一个问题。
|
|
||||||
|
|
||||||
来直接运行一个 **.java** 文件:
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
`$ java ./Hello.java`
|
|
||||||
```
|
|
||||||
|
|
||||||
通常,Java 应用程序以 Java 存档 (JAR) 文件的形式分发,以 **.jar** 结尾。一个 JAR 文件包含一个 manifest 文件,指定主类,项目结构的一些元数据,以及运行应用程序所需的你的代码的所有部分。
|
|
||||||
|
|
||||||
为运行一个 JAR 文件,你可以双击它的图标(取决于你的操作系统设置), 或者,你可以从一个终端中启动它:
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
`$ java -jar ./Hello.jar`
|
|
||||||
```
|
|
||||||
|
|
||||||
### 面向所有人的 Java
|
|
||||||
|
|
||||||
Java 是一种强大的的原因,归因于 [OpenJDK][12] 项目和其它的新方案,它是一种开放式规范,允许像 [IcedTea][13], [Dalvik][14],和 [Kotlin][15] 项目的茁壮成长。学习 Java 是一种准备在各种行业中工作的极好的方法,另外,这里有很多[极好的原因来使用它][16]。
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
via: https://opensource.com/article/19/10/java-basics
|
|
||||||
|
|
||||||
作者:[Seth Kenlon][a]
|
|
||||||
选题:[lujun9972][b]
|
|
||||||
译者:[robsean](https://github.com/robsean)
|
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
||||||
|
|
||||||
[a]: https://opensource.com/users/seth
|
|
||||||
[b]: https://github.com/lujun9972
|
|
||||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coffee_cafe_brew_laptop_desktop.jpg?itok=G-n1o1-o (Coffee and laptop)
|
|
||||||
[2]: https://www.redhat.com/en/resources/building-microservices-eap-7-reference-architecture
|
|
||||||
[3]: https://www.gnu.org/software/bash/
|
|
||||||
[4]: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-6
|
|
||||||
[5]: http://openjdk.java.net/
|
|
||||||
[6]: http://www.eclipse.org/
|
|
||||||
[7]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+actionevent
|
|
||||||
[8]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
|
|
||||||
[9]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+joptionpane
|
|
||||||
[10]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
|
|
||||||
[11]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+parseexception
|
|
||||||
[12]: https://openjdk.java.net/
|
|
||||||
[13]: https://icedtea.classpath.org/wiki/Main_Page
|
|
||||||
[14]: https://source.android.com/devices/tech/dalvik/
|
|
||||||
[15]: https://kotlinlang.org/
|
|
||||||
[16]: https://opensource.com/article/19/9/why-i-use-java
|
|
Loading…
Reference in New Issue
Block a user