Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2020-07-02 20:52:40 +08:00
commit a748d35af6
10 changed files with 1293 additions and 104 deletions

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12373-1.html)
[#]: subject: (Missing Photoshop on Linux? Use PhotoGIMP and Convert GIMP into Photoshop)
[#]: via: (https://itsfoss.com/photogimp/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
@ -18,7 +18,7 @@
但是,习惯了 Photoshop 的人们发现在切换到 GIMP 的时很难忘记他们反复学习的肌肉记忆。这可能会使某些人感到沮丧,因为使用新的界面意味着要学习大量的键盘快捷键,并花时间在查找工具位于何处。
为了帮助从 Photoshop 切换到 GIMP 的人,[Diolinux][4] 介绍了一个在 GIMP 中模仿 Adobe Photoshop 的工具。
为了帮助从 Photoshop 切换到 GIMP 的人,[Diolinux][4] 推出了一个在 GIMP 中模仿 Adobe Photoshop 的工具。
### PhotoGIMP在 Linux 中为 GIMP 提供 Adobe Photoshop 的外观
@ -34,29 +34,25 @@
* 添加新的默认设置以最大化画布空间
* 添加类似于 Adobe Photoshop 的键盘快捷键
PhotoGIMP 还在自定义 .desktop 文件中添加新的图标和名称。让我们看看如何使用它。
PhotoGIMP 还在自定义 `.desktop` 文件中添加新的图标和名称。让我们看看如何使用它。
### 在 Linux 上安装 PhotoGIMP (适合中级到专业用户)
PhotoGIMP 本质是一个补丁。在 Linux 中下载并[解压 zip 文件][7]。你将在解压的文件夹中找到以下隐藏的文件夹:
* icons其中包含新的 PhotoGIMP 图标
* .local包含个性化的 .desktop 文件,以便你在系统菜单中看到的是 PhotoGIMP 而不是 GIMP
* .var包含 GIMP 补丁的主文件夹
* `.icons`:其中包含新的 PhotoGIMP 图标
* `.local`:包含个性化的 `.desktop` 文件,以便你在系统菜单中看到的是 PhotoGIMP 而不是 GIMP
* `.var`:包含 GIMP 补丁的主文件夹
你应该[使用 Ctrl+H 快捷键在 Ubuntu 中显示隐藏文件][8]。
警告:建议你备份 GIMP 配置文件,以便在不喜欢 PhotoGIMP 时可以还原。只需将 GIMP 配置文件复制到其他位置。
警告:建议你备份 GIMP 配置文件,以便在不喜欢 PhotoGIMP 时可以还原。只需将 GIMP 配置文件复制到其他位置即可备份
目前PhotoGIMP 主要与通过 [Flatpak][9] 安装的 GIMP 兼容。如果你使用 Flatpak 安装了 GIMP那么只需将这些隐藏的文件夹复制粘贴到家目录中它将 GIMP 转换为 Adobe Photoshop 类似的设置。
但是,如果你通过 apt、snap 或发行版的包管理器安装了 GIMP那么必须找到 GIMP 的配置文件夹,然后粘贴 PhotoGIMP 的 .var 目录的内容。当出现询问时,请选择合并选项并替换同名的现有文件。
但是,如果你通过 apt、snap 或发行版的包管理器安装了 GIMP那么必须找到 GIMP 的配置文件夹,然后粘贴 PhotoGIMP 的 `.var` 目录的内容。当出现询问时,请选择合并选项并替换同名的现有文件。
我[使用 apt 在 Ubuntu 20.04 中安装了 GIMP][10]。对我来说GIMP 配置文件在 \~/.config/GIMP/2.10。我复制了 .var/app/org.gimp.GIMP/config/GIMP/2.10 目录,并启动 GIMP 查看 PhotoGIMP 的启动页。
我[使用 apt 在 Ubuntu 20.04 中安装了 GIMP][10]。对我来说GIMP 配置文件在 `~/.config/GIMP/2.10`。我复制了 `.var/app/org.gimp.GIMP/config/GIMP/2.10` 目录,并启动 GIMP 查看 PhotoGIMP 的启动页。
这是打了 PhotoGIMP 补丁后的 GIMP 界面:
@ -64,15 +60,15 @@ PhotoGIMP 本质是一个补丁。在 Linux 中下载并[解压 zip 文件][7]
我尝试了几个 Photoshop 快捷键来检查它所做的更改,一切似乎可以正常工作。
[下载 PhotoGIMP][12]
- [下载 PhotoGIMP][12]
我还找到了 [Snap 包形式的 PhotoGIMP][13],但它是 2019 年的,我不确定它是否可以在所有地方使用,或者仅适用于 snap 安装。
**总结**
### 总结
这不是类似的第一个项目。几年前,我们有一个类似的项目叫 Gimpshop。Gimpshop 项目在过去的几年中没有任何进展,可以肯定地认为该项目已经死亡。有一个名为 Gimpshop 的网站,但该网站来自冒名者试图以 Gimpshop 的名义获利。
我不是 Adobe Photoshop 用户。我甚至不是 GIMP 专家,这就是为什么 Its FOSS 上的 [GIMP 教程][14] 用 Dimitrios 的原因。
我不是 Adobe Photoshop 用户。我甚至不是 GIMP 专家,这就是为什么我们的 [GIMP 教程][14] 用 Dimitrios 的原因。
因此,我无法评论 PhotoGIMP 项目的实用性。如果你熟悉这两种软件,那么应该能够比我更好地进行判断。
@ -85,7 +81,7 @@ via: https://itsfoss.com/photogimp/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,84 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to crop images in GIMP [Quick Tip])
[#]: via: (https://itsfoss.com/crop-images-gimp/)
[#]: author: (Dimitrios Savvopoulos https://itsfoss.com/author/dimitrios/)
How to crop images in GIMP [Quick Tip]
======
There are many reasons you may want to crop an image in [GIMP][1]. You may want to remove useless borders or information to improve your image, or you may want the focus of the final image to be a specific detail for example.
In this tutorial, I will demonstrate how to cut out an image in GIMP quickly and without compromising the precision. Lets see.
### How to crop images in GIMP
![][2]
#### Method 1
Cropping is just an operation to trim the image down to a smaller region than the original one. The procedure to crop an image is straightforward.
You can get to the Crop Tool through the Tools palette like this:
![Use Crop Tool for cropping images in GIMP][3]
You can also access the crop tool through the menus:
**Tools → Transform Tools → Crop**
Once the tool is activated, youll notice that your mouse cursor on the canvas will change to indicate the Crop Tool is being used.
Now you can Left-Click anywhere on your image canvas, and drag the mouse to a location to create the cropping boundaries. You dont have to worry about the precision at this point, as you will be able to modify the final selection before actually cropping.
![Crop Selection][4]
At this point hovering your mouse cursor over any of the four corners of the selection will change the mouse cursor, and highlight that region. This allows you to now fine-tune the selection for cropping. You can click and drag any side or corner to move that portion of the selection.
Once the region is good enough to be cropped, you can just press the “**Enter**” key on your keyboard to crop.
If at any time youd like to start over or decide not to crop at all, you can press the “**Esc**” key on your keyboard.
#### Method 2
Another way to crop an image is to make a selection first, using the **Rectangle Select Tool**.
**Tools → Selection Tools → Rectangle Select**
![][5]
You can then highlight a selection the same way as the **Crop Tool**, and adjust the selection as well. Once you have a selection you like, you can crop the image to fit that selection through
**Image → Crop to Selection**
![][6]
#### Conclusion
Cropping precisely an image can be considered a fundamental asset for a GIMP user. You may choose which method fits better to your needs and explore its potential.
If you have any questions about the procedure, please let me know in the comments below. If you are “craving” more [GIMP tutorials][7], make sure to subscribe on your favorite social media platforms!
--------------------------------------------------------------------------------
via: https://itsfoss.com/crop-images-gimp/
作者:[Dimitrios Savvopoulos][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/dimitrios/
[b]: https://github.com/lujun9972
[1]: https://www.gimp.org/
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/06/Crop-images-in-GIMP.png?ssl=1
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/06/Crop-tool.png?ssl=1
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/06/Crop-selection.jpg?ssl=1
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/06/select-1.gif?ssl=1
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/06/crop.gif?ssl=1
[7]: https://itsfoss.com/tag/gimp-tips/

View File

@ -0,0 +1,101 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (entr: rerun your build when files change)
[#]: via: (https://jvns.ca/blog/2020/06/28/entr/)
[#]: author: (Julia Evans https://jvns.ca/)
entr: rerun your build when files change
======
This is going to be a pretty quick post I found out about [`entr`][1] relatively recently and I felt like WHY DID NOBODY TELL ME ABOUT THIS BEFORE?!?! So Im telling you about it in case youre in the same boat as I was.
Theres a great explanation of the tool with lots of examples on [entrs website][1].
The summary is in the headline: `entr` is a command line tool that lets you run a arbitrary command every time you change any of a set of specified files. You pass it the list of files to watch on stdin, like this:
```
git ls-files | entr bash my-build-script.sh
```
or
```
find . -name *.rs | entr cargo test
```
or whatever you want really.
### quick feedback is amazing
Like possibly every single programmer in the universe, I find it Very Annoying to have to manually rerun my build / tests every time I make a change to my code.
A lot of tools (like hugo and flask) have a built in system to automatically rebuild when you change your files, which is great!
But often I have some hacked together custom build process that I wrote myself (like `bash build.sh`), and `entr` lets me have a magical build experience where I get instant feedback on whether my change fixed the weird bug with just one line of bash. Hooray!
### restart a server (`entr -r`)
Okay, but what if youre running a server, and the server needs to be restarted every time you? entrs got you if you pass `-r`, then
```
git ls-files | entr -r python my-server.py
```
### clear the screen (`entr -c`)
Another neat flag is `-c`, which lets you clear the screen before rerunning the command, so that you dont get distracted/confused by the previous builds output.
### use it with `git ls-files`
Usually the set of files I want to track is about the same list of files I have in git, so `git ls-files` is a natural thing to pipe to `entr`.
I have a project right now where sometimes I have files that Ive just created that arent in git just yet. So what if you want to include untracked files? Heres a little bash incantation I put together that does this:
```
{ git ls-files; git ls-files . --exclude-standard --others; } | entr your-build-scriot
```
Theres probably a way to do this with just one git command but I dont know what it is.
### restart every time a new file is added: `entr -d`
The other problem with this `git ls-files` thing is that sometimes I add a new file, and of course its not in git yet. entr has a nice feature for this if you pass `-d`, then if you add a new file in any of the directories entr is tracking, then itll exit.
Im using this paired with a little while loop that will restart `entr` to include the new files, like this:
```
while true
do
{ git ls-files; git ls-files . --exclude-standard --others; } | entr -d your-build-scriot
done
```
### how entr works on Linux: inotify
On Linux, entr works using `inotify` (a system for tracking filesystem events like file changes) if you strace it, youll see an `inotify_add_watch` system call for each file you ask it to watch, like this:
```
inotify_add_watch(3, "static/stylesheets/screen.css", IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE_SELF|IN_MOVE_SELF) = 1152
```
### thats all!
I hope this helps a few people learn about `entr`!
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2020/06/28/entr/
作者:[Julia Evans][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://jvns.ca/
[b]: https://github.com/lujun9972
[1]: http://eradman.com/entrproject/

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,228 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Back up your phone's storage with this Linux utility)
[#]: via: (https://opensource.com/article/20/7/gphoto2-linux)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Back up your phone's storage with this Linux utility
======
Take as many shots as you want; gphoto2 makes transferring photos from
your device to your Linux computer quick and easy.
![A person looking at a phone][1]
One of the great failings of mobile devices is how difficult it can be to transfer data from your device to your computer. Mobile devices have a long history of this. Early mobiles, like Pilot and Handspring PDA devices, required special synchronization software (which you had to do religiously for fear of your device running out of batteries and losing all of your data forever). Old iPods required a platform-specific interface. Modern mobile devices default to sending your data to an online account so you can download it again on your computer.
Good news—if you're running Linux, you can probably interface with your mobile device using the `gphoto2` command. Originally developed as a way to communicate with digital cameras back when a digital camera was just a camera, `gphoto2` can talk to many different kinds of mobile devices now. Don't let the name fool you, either. It can handle all types of files, not just photos. Better yet, it's scriptable, flexible, and a lot more powerful than most GUI interfaces.
If you've ever struggled with finding a comfortable way to sync your data between your computer and mobile, take a look at `gphoto2`.
### Install gPhoto2
Chances are your Linux system already has libgphoto2 installed, because it's a key library for interfacing with mobile devices. You may have to install the command `gphoto2`, however, which is probably available from your repository.
On Fedora or RHEL:
```
$ sudo dnf install gphoto2
```
On Debian or Ubuntu:
```
$ sudo apt install gphoto2
```
### Verify compatibility
To verify that your mobile device is supported, use the `--list-cameras` piped through `less`:
```
`$ gPhoto2 --list-cameras | less`
```
Or you can pipe it through `grep` to search for a term. For example, if you have a Samsung Galaxy, then use `grep` with case sensitivity turned off with the `-i` switch:
```
$ gphoto2 --list-cameras | grep -i galaxy
  "Samsung Galaxy models (MTP)"
  "Samsung Galaxy models (MTP+ADB)"
  "Samsung Galaxy models Kies mode"
```
This confirms that Samsung Galaxy devices are supported through MTP and MTP with ADB.
If you can't find your device listed, you can still try using `gphoto2` on the off chance that your device is actually something on the list masquerading as a different brand.
### Find your mobile device
To use gPhoto2, you first have to have a mobile device plugged into your computer, set to MTP mode, and you probably need to give your computer permission to interact with it. This usually requires physical interaction with your device, specifically pressing a button in the UI to permit its filesystem to be accessed by the computer it's just been attached to.
![Screenshot of allow access message][2]
If you don't give your computer access to your mobile, then gPhoto2 detects your device, but it isn't unable to interact with it.
To ensure your computer detects the device you've attached, use the `--auto-detect` option:
```
$ gphoto2 --auto-detect
Model                       Port
\---------------------------------------
Samsung Galaxy models (MTP) usb:002,010
```
If your device isn't detected, check your cables first, and then check that your device is configured to interface over MTP or ADB, or whatever protocol gPhoto2 supports for your device, as shown in the output of `--list-cameras`.
### Query your device for features
With modern devices, there's usually a plethora of potential features, but not all features are supported. You can find out for sure with the `--abilities` option, which I find rather intuitive.
```
$ gphoto2 --abilities
Abilities for camera            : Samsung Galaxy models (MTP)
Serial port support             : no
USB support                     : yes
Capture choices                 : Capture not supported by driver
Configuration support           : no
Delete selected files on camera : yes
Delete all files on camera      : no
File preview (thumbnail) support: no
File upload support             : yes
```
There's no need to specify what device you're querying as long as you only have one device attached. If you have attached more than one device that gPhoto2 can interact with, though, you can specify the device by port, camera model, or usbid.
### Interacting with your device
If your device supports capture, then you can grab media through your camera from your computer. For instance, to capture an image:
```
$ gphoto2 --capture-image
```
To capture an image and immediately transfer it to the computer you're on:
```
$ gphoto2 --capture-image-and-download
```
You can also capture video and sound. If you have more than one camera attached, you can specify which device you want to use by port, camera model, or usbid:
```
$ gphoto2 --camera "Samsung Galaxy models (MTP)" \
\--capture-image-and-download
```
### Files and folders
To interact with files on your device intelligently, you need to understand the structure of the filesystem being exposed to gPhoto2.
You can view available folders with the `--get-folders` option:
```
$ gphoto2 --list-folders
There are 2 folders in folder '/'.                                            
 - store_00010001
 - store_00020002
There are 0 folders in folder '/store_00010001'.
There are 0 folders in folder '/store_00020002'.
```
Each of these folders represents a storage destination on the device. In this example, `store_00010001` is the internal storage and `store_00020002` is an SD card. Your device may be structured differently.
### Getting files
Now that you know the folder layout of your device, you can ingest photos from your device. There are many different options you can use, depending on what you want to take from the device.
You can get a specific file, providing you know the full path:
```
`$ gphoto2 --get-file IMG_0001.jpg --folder /store_00010001/myphotos`
```
You can get all files at once:
```
`$ gphoto2 --get-all-files --folder /store_00010001/myfiles`
```
You can get just audio files:
```
`gphoto2 --get-all-audio-data --folder /store_00010001/mysounds`
```
There are other options, too, and most of them depend on what your device, and the protocol you're using, support.
### Uploading files
Now that you know your potential target folders, you can upload files from your computer to your device. For example, assuming there's a file called `example.epub` in your current directory, you can send the file to your device with the `--upload-file` option combined with the `--folder` option to specify which storage location you want to upload to:
```
$ gphoto2 --upload file example.epub \
\--folder store_00010001
```
You can make a directory on your device, should you prefer to upload several files to a consolidated location:
```
$ gphoto2 --mkdir books \
\--folder store_00010001
$ gphoto2 --upload-file *.epub \
\--folder store_00010001/books
```
### Listing files
To see files uploaded to your device, use the `--list-files` option:
```
$ gphoto2 --list-files --folder /store_00010001
There is 1 file in folder '/store_00010001'
#1     example.epub 17713 KB application/x-unknown
$ gphoto2 --list-files --folder /store_00010001/books
There is 1 file in folder '/store_00010001'
#1    example0.epub 17713 KB application/x-unknown
#2    example1.epub 12264 KB application/x-unknown
[...]
```
### Exploring your options
Much of gPhoto2's power depends on your device, so your experience will be different than anyone else's. There are many operations listed in `gphoto2 --help` for you to explore. Use gPhoto2 and never struggle with transferring files from your device to your computer ever again!
These open source photo libraries help you stay organized while making your pictures look great.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/7/gphoto2-linux
作者:[Seth Kenlon][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/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/idea_innovation_mobile_phone.png?itok=RqVtvxkd (A person looking at a phone)
[2]: https://opensource.com/sites/default/files/uploads/gphoto2-mtp-allow.jpg (Screenshot of allow access message)

View File

@ -0,0 +1,292 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Customizing Bash)
[#]: via: (https://fedoramagazine.org/customizing-bash/)
[#]: author: (Stephen Snow https://fedoramagazine.org/author/jakfrost/)
Customizing Bash
======
![][1]
The outermost layer of your operating system the part you interact with is called the [shell][2]. Fedora comes with several preinstalled shells. Shells can be either graphical or text-based. In documentation, you will often see the acronyms GUI (Graphical User Interface) and CLI (Command-Line Interface) used to distinguish between graphical and text-based shells/interfaces. Other [GUI][3] and [CLI][4] shells can be used, but [GNOME][5] is Fedoras default GUI and [Bash][6] is its default CLI.
The remainder of this article will cover recommended dotfile practices for the Bash CLI.
### Bash overview
From the Bash reference manual:
> At its base, a shell is simply a macro processor that executes commands. The term macro processor means functionality where text and symbols are expanded to create larger expressions.
>
> Reference Documentation for Bash
> Edition 5.0, for Bash Version 5.0.
> May 2019
In addition to helping the user start and interact with other programs, the Bash shell also includes several built-in commands and keywords. Bashs built-in functionality is extensive enough that it is considered a [high-level programming language][7] in its own right. Several of Bashs keywords and operators resemble those of [the C programming language][8].
Bash can be invoked in either interactive or non-interactive mode. Bashs interactive mode is the typical terminal/command-line interface that most people are familiar with. [GNOME Terminal][9], by default, launches Bash in interactive mode. An example of when Bash runs in non-interactive mode is when commands and data are [piped][10] to it from a file or shell script. Other modes of operation that Bash can operate in include: login, non-login, remote, POSIX, unix sh, restricted, and with a different UID/GID than the user. Various combinations of these modes are possible. For example interactive+restricted+POSIX or non-interactive+non-login+remote. Which startup files Bash will process depends on the combination of modes that are requested when it is invoked. Understanding these modes of operation is necessary when modifying the startup files.
According to the Bash reference manual, Bash …
> 1\. Reads its input from a file …, from a string supplied as an argument to the -c invocation option …, or from the users terminal.
>
> 2\. Breaks the input into words and operators, obeying [its] quoting rules. … These tokens are separated by metacharacters. Alias expansion is performed by this step.
>
> 3\. Parses the tokens into simple and compound commands.
>
> 4\. Performs the various shell expansions …, breaking the expanded tokens into lists of filenames … and commands and arguments.
>
> 5\. Performs any necessary redirections … and removes the redirection operators and their operands from the argument list.
>
> 6\. Executes the command.
>
> 7\. Optionally waits for the command to complete and collects its exit status.
>
> Reference Documentation for Bash
> Edition 5.0, for Bash Version 5.0.
> May 2019
When a user starts a terminal emulator to access the command line, an interactive shell session is started. GNOME Terminal, by default, launches the users shell in non-login mode. Whether GNOME Terminal launches the shell in login or non-login mode can be configured under _Edit__Preferences__Profiles__Command_. Login mode can also be requested by passing the _login_ flag to Bash on startup. Also note that Bashs _login_ and _non-interactive_ modes are not exclusive. It is possible to run Bash in both _login_ and _non-interactive_ mode at the same time.
### Invoking Bash
Unless it is passed the ***—***_noprofile_ flag, a Bash login shell will read and execute the commands found in certain initialization files. The first of those files is _/etc/profile_ if it exists, followed by one of _~/.bash_profile_, _~/.bash_login_, or _~/.profile_; searched in that order. When the user exits the login shell, or if the script calls the _exit_ built-in in the case of a non-interactive login shell, Bash will read and execute the commands found in _~/.bash_logout_ followed by _/etc/bash_logout_ if it exists. The file _/etc/profile_ will normally source _/etc/bashrc_, reading and executing commands found there, then search through _/etc/profile.d_ for any files with an _sh_ extension to read and execute. As well, the file _~/.bash_profile_ will normally source the file _~/.bashrc_. Both _/etc/bashrc_ and _~/.bashrc_ have checks to prevent double sourcing.
An interactive shell that is not a login shell, will source the _~/.bashrc_ file when it is first invoked. This is the usual type of shell a user will enter when opening a terminal on Fedora. When Bash is started in non-interactive mode as it is when running a shell script it will look for the _BASH_ENV_ variable in the environment. If it is found, will expand the value, and use the expanded value as the name of a file to read and execute. Bash behaves just as if the following command were executed:
```
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
```
It is important to note that the value of the _PATH_ variable is not used to search for the filename.
### Important user-specific dotfiles
Bashs best-known user dotfile is _~/.bashrc_. Most user customization is done by editing this file. Most user customization, may be a stretch since there are reasons to modify all of the mentioned files; as well as other files that have not been mentioned. Bashs environment is designed to be highly customizable in order to suit the needs of many different users with many different tastes.
![][11]
When a Bash login shell exits cleanly, _~/.bash_logout_ and then _/etc/bash_logout_ will be called if they exist. The next diagram is a sequence diagram showing the process Bash follows when being invoked as an interactive shell. The below sequence is followed, for example, when the user opens a terminal emulator from their desktop environment.
![][12]
Armed with the knowledge of how Bash behaves under different invocation methods, it becomes apparent that there are only a few typical invocation methods to be most concerned with. These are the non-interactive and interactive login shell, and the non-interactive and interactive non-login shell. If global environment customizations are needed, then the desired settings should be placed in a uniquely-named file with a _.sh_ extension (_custom.sh_, for example) and that file should be placed in the _/etc/profile.d_ directory.
The non-interactive, non-login invocation method needs special attention. This invocation method causes Bash to check the _BASH_ENV_ variable. If this variable is defined, the file it references will be sourced. Note that the values stored in the _PATH_ environment variable are not utilized when processing _BASH_ENV_. So it must contain the full path to the file to be sourced. For example, if someone wanted the settings from their _~/.bashrc_ file to be available to shell scripts they run non-interactively, they could place something like the following in a file named _/etc/profile.d/custom.sh_
```
# custom.sh
.
.
.
#If Fedora Workstation
BASH_ENV="/home/username/.bashrc"
.
.
.
#If Fedora Silverblue Workstation
BASH_ENV="/var/home/username/.bashrc"
export BASH_ENV
```
The above profile drop-in script will cause the users _~/.bashrc_ file to be sourced just before every shell script is executed.
Users typically customizie their system environment so that it will better fit their work habits and preferences. An example of the sort of customization that a user can make is an alias. Commands frequently run with the same set of starting parameters are good candidates for aliases. Some example aliases are provided in the _~/.bashrc_ file shown below.
```
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ];
then . /etc/bashrc
fi
.
.
.
# User specific aliases and functions
alias ls='ls -hF --color=auto'
alias la='ls -ahF --color=auto'
# make the dir command work kinda like in windows (long format)
alias dir='ls --color=auto --format=long'
# make grep highlight results using color
alias grep='grep --color=auto'
```
Aliases are a way to customize various commands on your system. They can make commands more convenient to use and reduce your keystrokes. Per-user aliases are often configured in the users _~/.bashrc_ file.
If you find you are looking back through your command line history a lot, you may want to configure your history settings. Per-user history options can also be configured in _~/.bashrc_. For example, if you have a habit of using multiple terminals at once, you might want to enable the _histappend_ option. Bash-specific shell options that are [boolean][13] in nature (take either _on_ or _off_ as a value) are typically enabled or disabled using the _shopt_ built-in command. Bash settings that take a more complex value (for example, _HISTTIMEFORMAT_) tend to be configured by assigning the value to an environment variable. Customizing Bash with both shell options and environment variable is demonstrated below.
```
# Configure Bash History
# Expand dir env vars on tab and set histappend
shopt -s direxpand histappend
# - ignoreboth = ignorespace and ignoredup
HISTCONTROL='ignoreboth'
# Controls the format of the time in output of `history`
HISTTIMEFORMAT="[%F %T] "
# Infinite history
# NB: on newer bash, anything < 0 is the supported way, but on CentOS/RHEL
# at least, only this works
HISTSIZE=
HISTFILESIZE=
# or for those of us on newer Bash
HISTSIZE=-1
HISTFILESIZE=-1
```
The _direxpand_ option shown in the example above will cause Bash to replace directory names with the results of word expansion when performing filename completion. This will change the contents of the readline editing buffer, so what you typed is masked by what the completion expands it to.
The _HISTCONTROL_ variable is used to enable or disable some filtering options for the command history. Duplicate lines, lines with leading blank spaces, or both can be filtered from the command history by configuring this setting. To quote Dusty Mabe, the engineer I got the tip from:
> _ignoredup_ makes history not log duplicate entries (if you are running a command over and over). _ignorespace_ ignores entries with a space in the front, which is useful if you are setting an environment variable with a secret or running a command with a secret that you dont want logged to disk. _ignoreboth_ does both.
>
> Dusty Mabe Redhat Principle Software Engineer, June 19, 2020
For users who do a lot of work on the command line, Bash has the _CDPATH_ environment variable. If _CDPATH_ is configured with a list of directories to search, the _cd_ command, when provided a relative path as its first argument, will check all the listed directories in order for a matching subdirectory and change to the first one found.
```
# .bash_profile
# set CDPATH
CDPATH="/var/home/username/favdir1:/var/home/username/favdir2:/var/home/username/favdir3"
# or could look like this
CDPATH="/:~:/var:~/favdir1:~/favdir2:~/favdir3"
export CDPATH
```
_CDPATH_ should be updated the same way _PATH_ is typically updated by referencing itself on the right hand side of the assignment to preserve the previous values.
```
# .bash_profile
# set CDPATH
CDPATH="/var/home/username/favdir1:/var/home/username/favdir2:/var/home/username/favdir3"
# or could look like this
CDPATH="/:~:/var:~/favdir1:~/favdir2:~/favdir3"
CDPATH="$CDPATH:~/favdir4:~/favdir5"
export CDPATH
```
_PATH_ is another very important variable. It is the search path for commands on the system. Be aware that some applications require that their own directories be included in the _PATH_ variable to function properly. As with _CDPATH_, appending new values to _PATH_ can be done by referencing the old values on the right hand side of the assignment. If you want to prepend the new values instead, simply place the old values (_$PATH_) at the end of the list. Note that on Fedora, the list values are separated with the colon character (**:**).
```
# .bash_profile
# Add PATH values to the PATH Environment Variable
PATH="$PATH:~/bin:~:/usr/bin:/bin:~/jdk-13.0.2:~/apache-maven-3.6.3"
export PATH
```
The command prompt is another popular candidate for customization. The command prompt has seven customizable parameters:
> **PROMPT_COMMAND** If set, the value is executed as a command prior to issuing each primary prompt ($PS1).
>
> **PROMPT_DIRTRIM** If set to a number greater than zero, the value is used as the number of trailing directory components to retain when expanding the \w and \W prompt string escapes. Characters removed are replaced with an ellipsis.
>
> **PS0** The value of this parameter is expanded like _PS1_ and displayed by interactive shells after reading a command and before the command is executed.
>
> **PS1** The primary prompt string. The default value is **\s-\v\$** . …
>
> **PS2** The secondary prompt string. The default is _**&gt;**_ . _PS2_ is expanded in the same way as _PS1_ before being displayed.
>
> **PS3** The value of this parameter is used as the prompt for the _select_ command. If this variable is not set, the _select_ command prompts with **#?**
>
> **PS4** The value of this parameter is expanded like _PS1_ and the expanded value is the prompt printed before the command line is echoed when the _-x_ option is set. The first character of the expanded value is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is _**+**_ .
>
> Reference Documentation for Bash
> Edition 5.0, for Bash Version 5.0.
> May 2019
An entire article could be devoted to this one aspect of Bash. There are copious quantities of information and examples available. Some example dotfiles, including prompt reconfiguration, are provided in a repository linked at the end of this article. Feel free to use and experiment with the examples provided in the repository.
### Conclusion
Now that you are armed with a little knowledge about how Bash works, feel free to modify your Bash dotfiles to suit your own needs and preferences. Pretty up your prompt. Go nuts making aliases. Or otherwise make your computer truly yours. Examine the content of _/etc/profile_, _/etc/bashrc_, and _/etc/profile.d/_ for inspiration.
Some comments about terminal emulators are fitting here. There are ways to setup your favorite terminal to behave exactly as you want. You may have already realized this, but often this modification is done with a … wait for it … dotfile in the users home directory. The terminal emulator can also be started as a login session, and some people always use login sessions. How you use your terminal, and your computer, will have a bearing on how you modify (or not) your dotfiles.
If youre curious about what type session you are in at the command line the following script can help you determine that.
```
#!/bin/bash
case "$-" in
(*i*) echo This shell is interactive ;;
(*) echo This shell is not interactive ;;
esac
```
Place the above in a file, mark it executable, and run it to see what type of shell you are in. _$-_ is a variable in Bash that contains the letter **i** when the shell is interactive. Alternatively, you could just echo the $- variable and inspect the output for the presence of the **i** flag:
```
$ echo $-
```
### Reference information
The below references can be consulted for more information and examples. The Bash man page is also a great source of information. Note that your local man page is guaranteed to document the features of the version of Bash you are running whereas information found online can sometimes be either too old (outdated) or too new (not yet available on your system).
<https://opensource.com/tags/command-line>
<https://opensource.com/downloads/bash-cheat-sheet>
You will have to enter a valid email address at the above site, or sign up, to download from it.
<https://opensource.com/article/19/12/bash-script-template>
Community members who provided contributions to this article in the form of example dotfiles, tips, and other script files:
* Micah Abbott Principal Quality Engineer
* John Lebon Principal Software Engineer
* Dusty Mabe Principal Software Engineer
* Colin Walters Senior Principal Software Engineer
A repository of example dotfiles and scripts can be found here:
<https://github.com/TheOneandOnlyJakfrost/bash-article-repo>
Please carefully review the information provided in the above repository. Some of it may be outdated. There are many examples of not only dotfiles for Bash, but also custom scripts and pet container setups for development. I recommend starting with John Lebons dotfiles. They are some of the most detailed I have seen and contain very good descriptions throughout. Enjoy!
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/customizing-bash/
作者:[Stephen Snow][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/jakfrost/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2020/05/bashenvironment-816x346.png
[2]: https://en.wikipedia.org/wiki/Shell_(computing)
[3]: https://fedoramagazine.org/fedoras-gaggle-of-desktops/
[4]: https://en.wikipedia.org/wiki/Comparison_of_command_shells
[5]: https://en.wikipedia.org/wiki/GNOME
[6]: https://en.wikipedia.org/wiki/Bash_(Unix_shell)
[7]: https://en.wikipedia.org/wiki/High-level_programming_language
[8]: https://en.wikipedia.org/wiki/C_(programming_language)
[9]: https://en.wikipedia.org/wiki/GNOME_Terminal
[10]: https://en.wikipedia.org/wiki/Pipeline_(Unix)
[11]: https://fedoramagazine.org/wp-content/uploads/2020/06/bash-initialization-1-1024x711.png
[12]: https://fedoramagazine.org/wp-content/uploads/2020/06/bash-initialization-2-1024x544.png
[13]: https://en.wikipedia.org/wiki/Boolean_data_type

View File

@ -0,0 +1,205 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to install Java on a Mac)
[#]: via: (https://opensource.com/article/20/7/install-java-mac)
[#]: author: (Daniel Oh https://opensource.com/users/daniel-oh)
How to install Java on a Mac
======
macOS users can run the open source release of Java as well as newer
frameworks for cloud-native development.
![Coffee and laptop][1]
In late May, [Java][2] celebrated its 25th anniversary, and to commemorate the occasion, developers around the world used the hashtag [#MovedByJava][3] to share their achievements, memories, and insights with the programming language.
> My timeline:
>
> * 1999 Started learning Java
> * 2007 Created [@grailsframework][4]
> * 2008 Cofounded G2One
> * 2009 Acquired by SpringSource
> * 2015 Joined [@ObjectComputing][5]
> * 2018 Created [@micronautfw][6] / won [@groundbreakers][7] award
> * 2019 Became [@Java_Champions][8]
>
> Thank u [@java][9]![#MovedByJava][10]
>
> — Graeme Rocher (@graemerocher) [May 21, 2020][11]
Over the years, many technologies and trends have contributed to the Java stack's development, deployment, and ability to run multiple applications on standard application servers. Building container images for [Kubernetes][12] enables Java developers to package and deploy [microservices][13] in multiple cloud environments rather than running several application servers on virtual machines.
![Timeline of technology contributions to Java][14]
(Daniel Oh, [CC BY-SA 4.0][15])
With these technologies, the Java application stack has been optimized to run larger heaps and highly dynamic frameworks that can make decisions at runtime. Unfortunately, those efforts weren't good enough to make Java the preferred programming language for developers to implement cloud-native Java applications for serverless and event-driven platforms. Other languages filled in the space, particularly JavaScript, Python, and Go, with Rust and WebAssembly offering new alternatives.
Despite this competition, [cloud-native Java][16] is making an impact on cloud-centric software development. Luckily, new Java frameworks (e.g., [Quarkus][17], [Micronaut][18], and [Helidon][19]) have recently broken through the challenges by offering smaller applications that compile faster and are designed with distributed systems in mind.
### How to install Java on macOS
This future for Java development starts with more people installing and using Java. So I will walk through installing and getting started with the Java development environment on macOS. (If you are running Linux, please see Seth Kenlon's article [_How to install Java on Linux_][20].)
#### Install OpenJDK from a Brew repository
Homebrew is the de-facto standard package manager for macOS. If you haven't installed it yet, Matthew Broberg's [_Introduction to Homebrew_][21] walks you through the steps.
Once you have Homebrew on your Mac, use the `brew` command to install [OpenJDK][22], which is the open source way to write Java applications:
```
`$ brew cask install java`
```
In just a few minutes, you will see:
```
`🍺 java was successfully installed!`
```
Confirm that OpenJDK installed correctly with `$ java -version`:
```
$ java -version
openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment (build 14.0.1+7)
OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing
```
The output confirms OpenJDK 14 (the latest version, as of this writing) is installed.
#### Install OpenJDK from a binary
If you are not a fan of package management and prefer managing Java yourself, there's always the option to download and install it manually.
I found a download link to the latest version on the OpenJDK homepage. Download the OpenJDK 14 binary:
```
`$ wget https://download.java.net/java/GA/jdk14.0.1/664493ef4a6946b186ff29eb326336a2/7/GPL/openjdk-14.0.1_osx-x64_bin.tar.gz`
```
Move to the directory where you downloaded the binary file and extract it:
```
`$ tar -xf openjdk-14.0.1_osx-x64_bin.tar.gz`
```
Next, add Java to your PATH:
```
`$ export PATH=$PWD/jdk-14.0.1.jdk/Contents/Home/bin:$PATH`
```
Also, add this to the path to your dotfiles, `.bash_profile` or `.zshrc` depending on what shell you are running. You can learn more about configuring the `$PATH` variable in [_How to set your $PATH variable in Linux_][23].
Finally, verify your OpenJDK 14 installation:
```
$ java -version
openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment (build 14.0.1+7)
OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
```
### Write your first Java microservice on a Mac
Now you are ready to develop a cloud-native Java application with OpenJDK stack on macOS. In this how-to, you'll create a new Java project on [Quarkus][17] that exposes a REST API using dependency injection.
You will need [Maven][24], a popular Java dependency manager, to start. [Install][25] it from Maven's website or using Homebrew with `brew install maven`.
Execute the following Maven commands to configure a Quarkus project and create a simple web app:
```
$ mvn io.quarkus:quarkus-maven-plugin:1.5.1.Final:create \
    -DprojectGroupId=com.example \
    -DprojectArtifactId=getting-started \
    -DclassName="com.example.GreetingResource" \
    -Dpath="/hello"
cd getting-started
```
Run the application:
```
`$ ./mvnw quarkus:dev`
```
You will see this output when the application starts:
```
__  ____  __  _____   ___  __ ____  ______
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,&lt; / /_/ /\ \  
\--\\___\\_\\____/_/ |_/_/|_/_/|_|\\____/___/  
2020-06-13 00:03:06,413 INFO  [io.quarkus] (Quarkus Main Thread) getting-started 1.0-SNAPSHOT on JVM (powered by Quarkus 1.5.1.Final) started in 1.125s. Listening on: <http://0.0.0.0:8080>
2020-06-13 00:03:06,416 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2020-06-13 00:03:06,416 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy]
```
Access the REST endpoint using the `curl` command:
```
$ curl -w "\n" <http://localhost:8080/hello>
hello
```
Congratulations! You have quickly gone from not even having Java installed to building your first web application using Maven and Quarkus.
### What to do next with Java
Java is a mature programming language that continues to grow in popularity through new frameworks designed for cloud-native application development.
If you are on the path toward building that future, you may be interested in more practical Quarkus development lessons or other modern frameworks. No matter what you're building, the next step is configuring your text editor. Read my tutorial on [_Writing Java with Quarkus in VS Code_][26], then explore what else you can do.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/7/install-java-mac
作者:[Daniel Oh][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/daniel-oh
[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://opensource.com/resources/java
[3]: https://twitter.com/search?q=%23MovedByJava&src=typed_query
[4]: https://twitter.com/grailsframework?ref_src=twsrc%5Etfw
[5]: https://twitter.com/ObjectComputing?ref_src=twsrc%5Etfw
[6]: https://twitter.com/micronautfw?ref_src=twsrc%5Etfw
[7]: https://twitter.com/groundbreakers?ref_src=twsrc%5Etfw
[8]: https://twitter.com/Java_Champions?ref_src=twsrc%5Etfw
[9]: https://twitter.com/java?ref_src=twsrc%5Etfw
[10]: https://twitter.com/hashtag/MovedByJava?src=hash&ref_src=twsrc%5Etfw
[11]: https://twitter.com/graemerocher/status/1263484918157410304?ref_src=twsrc%5Etfw
[12]: https://opensource.com/resources/what-is-kubernetes
[13]: https://opensource.com/resources/what-are-microservices
[14]: https://opensource.com/sites/default/files/uploads/javatimeline.png (Timeline of technology contributions to Java)
[15]: https://creativecommons.org/licenses/by-sa/4.0/
[16]: https://opensource.com/article/20/1/cloud-native-java
[17]: https://quarkus.io/
[18]: https://micronaut.io/
[19]: https://helidon.io/#/
[20]: https://opensource.com/article/19/11/install-java-linux
[21]: https://opensource.com/article/20/6/homebrew-mac
[22]: https://openjdk.java.net/
[23]: https://opensource.com/article/17/6/set-path-linux
[24]: https://maven.apache.org/index.html
[25]: https://maven.apache.org/install.html
[26]: https://opensource.com/article/20/4/java-quarkus-vs-code

View File

@ -0,0 +1,282 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Install a Kubernetes load balancer on your Raspberry Pi homelab with MetalLB)
[#]: via: (https://opensource.com/article/20/7/homelab-metallb)
[#]: author: (Chris Collins https://opensource.com/users/clcollins)
Install a Kubernetes load balancer on your Raspberry Pi homelab with MetalLB
======
Assign real IPs from your home network to services running in your
cluster and access them from other hosts on your network.
![Science lab with beakers][1]
Kubernetes is designed to integrate with major cloud providers' load balancers to provide public IP addresses and direct traffic into a cluster. Some professional network equipment manufacturers also offer controllers to integrate their physical load-balancing products into Kubernetes installations in private data centers. For an enthusiast running a Kubernetes cluster at home, however, neither of these solutions is very helpful.
Kubernetes does not have a built-in network load-balancer implementation. A bare-metal cluster, such as a [Kubernetes cluster installed on Raspberry Pis for a private-cloud homelab][2], or really any cluster deployed outside a public cloud and lacking expensive professional hardware, needs another solution. [MetalLB][3] fulfills this niche, both for enthusiasts and large-scale deployments.
MetalLB is a network load balancer and can expose cluster services on a dedicated IP address on the network, allowing external clients to connect to services inside the Kubernetes cluster. It does this via either [layer 2 (data link)][4] using [Address Resolution Protocol][5] (ARP) or [layer 4 (transport)][6] using [Border Gateway Protocol][7] (BGP).
While Kubernetes does have something called [Ingress][8], which allows HTTP and HTTPS traffic to be exposed outside the cluster, it supports _only_ HTTP or HTTPS traffic, while MetalLB can support any network traffic. It is more of an apples-to-oranges comparison, however, because MetalLB provides resolution of an unassigned IP address to a particular cluster node and assigns that IP to a Service, while Ingress uses a specific IP address and internally routes HTTP or HTTPS traffic to a Service or Services based on routing rules.
MetalLB can be set up in just a few steps, works especially well in private homelab clusters, and within Kubernetes clusters, it behaves the same as public cloud load-balancer integrations. This is great for education purposes (i.e., learning how the technology works) and makes it easier to "lift-and-shift" workloads between on-premises and cloud environments.
### ARP vs. BGP
As mentioned, MetalLB works via either ARP or BGP to resolve IP addresses to specific hosts. In simplified terms, this means when a client attempts to connect to a specific IP, it will ask "which host has this IP?" and the response will point it to the correct host (i.e., the host's MAC address).
With ARP, the request is broadcast to the entire network, and a host that knows which MAC address has that IP address responds to the request; in this case, MetalLB's answer directs the client to the correct node.
With BGP, each "peer" maintains a table of routing information directing clients to the host handling a particular IP for IPs and the hosts the peer knows about, and it advertises this information to its peers. When configured for BGP, MetalLB peers each of the nodes in the cluster with the network's router, allowing the router to direct clients to the correct host.
In both instances, once the traffic has arrived at a host, Kubernetes takes over directing the traffic to the correct pods.
For the following exercise, you'll use ARP. Consumer-grade routers don't (at least easily) support BGP, and even higher-end consumer or professional routers that do support BGP can be difficult to set up. ARP, especially in a small home network, can be just as useful and requires no configuration on the network to work. It is considerably easier to implement.
### Install MetalLB
Installing MetalLB is straightforward. Download or copy two manifests from [MetalLB's GitHub repository][9] and apply them to Kubernetes. These two manifests create the namespace MetalLB's components will be deployed to and the components themselves: the MetalLB controller, a "speaker" daemonset, and service accounts.
#### Install the components
Once you create the components, a random secret is generated to allow encrypted communication between the speakers (i.e., the components that "speak" the protocol to make services reachable).
(Note: These steps are also available on MetalLB's website.)
The two manifests with the required MetalLB components are:
* <https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml>
* <https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml>
They can be downloaded and applied to the Kubernetes cluster using the `kubectl apply` command, either locally or directly from the web:
```
# Verify the contents of the files, then download and pipe then to kubectl with curl
# (output omitted)
$ kubectl apply -f <https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml>
$ kubectl apply -f <https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml>
```
After applying the manifests, create a random Kubernetes secret for the speakers to use for encrypted communications:
```
# Create a secret for encrypted speaker communications
$ kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
```
Completing the steps above will create and start all the MetalLB components, but they will not do anything until they are configured. To configure MetalLB, create a configMap that describes the pool of IP addresses the load balancer will use.
#### Configure the address pools
MetalLB needs one last bit of setup: a configMap with details of the addresses it can assign to the Kubernetes Service LoadBalancers. However, there is a small consideration. The addresses in use do not need to be bound to specific hosts in the network, but they must be free for MetalLB to use and not be assigned to other hosts.
In my home network, IP addresses are assigned by the DHCP server my router is running. This DHCP server should not attempt to assign the addresses that MetalLB will use. Most consumer routers allow you to decide how large your subnet will be and can be configured to assign only a subset of IPs in that subnet to hosts via DHCP.
In my network, I am using the subnet `192.168.2.1/24`, and I decided to give half the IPs to MetalLB. The first half of the subnet consists of IP addresses from `192.168.2.1` to `192.168.2.126`. This range can be represented by a `/25` subnet: `192.168.2.1/25`. The second half of the subnet can similarly be represented by a `/25` subnet: `192.168.2.128/25`. Each half contains 126 IPs—more than enough for the hosts and Kubernetes services. Make sure to decide on subnets appropriate to your own network and configure your router and MetalLB appropriately.
After configuring the router to ignore addresses in the `192.168.2.128/25` subnet (or whatever subnet you are using), create a configMap to tell MetalLB to use that pool of addresses:
```
# Create the config map
$ cat &lt;&lt;EOF | kubectl create -f -
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: address-pool-1
      protocol: layer2
      addresses:
      - 192.168.2.128/25
EOF
```
The example configMap above uses [CIDR][10] notation, but the list of addresses can also be specified as a range:
```
addresses:
 - 192.168.2.128-192.168.2.254
```
Once the configMap is created, MetalLB will be active. Time to try it out!
### Test MetalLB
You can test the new MetalLB configuration by creating an example web service, and you can use one from a [previous article][2] in this series: Kube Verify. Use the same image to test that MetalLB is working as expected: `quay.io/clcollins/kube-verify:01`. This image contains an Nginx server listening for requests on port 8080. You can [view the Containerfile][11] used to create the image. If you want, you can instead build your own container image from the Containerfile and use that for testing.
If you previously created a Kubernetes cluster on Raspberry Pis, you may already have a Kube Verify service running and can [skip to the section][12] on creating a LoadBalancer-type of service.
#### If you need to create a kube-verify namespace
If you do not already have a `kube-verify` namespace, create one with the `kubectl` command:
```
# Create a new namespace
$ kubectl create namespace kube-verify
# List the namespaces
$ kubectl get namespaces
NAME              STATUS   AGE
default           Active   63m
kube-node-lease   Active   63m
kube-public       Active   63m
kube-system       Active   63m
metallb-system    Active   21m
kube-verify       Active   19s
```
With the namespace created, create a deployment in that namespace:
```
# Create a new deployment
$ cat &lt;&lt;EOF | kubectl create -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kube-verify
  namespace: kube-verify
  labels:
    app: kube-verify
spec:
  replicas: 3
  selector:
    matchLabels:
      app: kube-verify
  template:
    metadata:
      labels:
        app: kube-verify
    spec:
      containers:
      - name: nginx
        image: quay.io/clcollins/kube-verify:01
        ports:
        - containerPort: 8080
EOF
deployment.apps/kube-verify created
```
#### Create a LoadBalancer-type Kubernetes service
Now expose the deployment by creating a LoadBalancer-type Kubernetes service. If you already have a service named `kube-verify`, this will replace that one:
```
# Create a LoadBalancer service for the kube-verify deployment
cat &lt;&lt;EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
  name: kube-verify
  namespace: kube-verify
spec:
  selector:
    app: kube-verify
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: LoadBalancer
EOF
```
You could accomplish the same thing with the `kubectl expose` command:
```
`kubectl expose deployment kube-verify -n kube-verify --type=LoadBalancer --target-port=8080 --port=80`
```
MetalLB is listening for services of type LoadBalancer and immediately assigns an external IP (an IP chosen from the range you selected when you set up MetalLB). View the new service and the external IP address MetalLB assigned to it with the `kubectl get service` command:
```
# View the new kube-verify service
$ kubectl get service kube-verify -n kube-verify
NAME          TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
kube-verify   LoadBalancer   10.105.28.147   192.168.2.129   80:31491/TCP   4m14s
# Look at the details of the kube-verify service
$ kubectl describe service kube-verify -n kube-verify
Name:                     kube-verify
Namespace:                kube-verify
Labels:                   app=kube-verify
Annotations:              &lt;none&gt;
Selector:                 app=kube-verify
Type:                     LoadBalancer
IP:                       10.105.28.147
LoadBalancer Ingress:     192.168.2.129
Port:                     &lt;unset&gt;  80/TCP
TargetPort:               8080/TCP
NodePort:                 &lt;unset&gt;  31491/TCP
Endpoints:                10.244.1.50:8080,10.244.1.51:8080,10.244.2.36:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason        Age    From                Message
  ----    ------        ----   ----                -------
  Normal  IPAllocated   5m55s  metallb-controller  Assigned IP "192.168.2.129"
  Normal  nodeAssigned  5m55s  metallb-speaker     announcing from node "gooseberry"
```
In the output from the `kubectl describe` command, note the events at the bottom, where MetalLB has assigned an IP address (yours will vary) and is "announcing" the assignment from one of the nodes in your cluster (again, yours will vary). It also describes the port, the external port you can access the service from (80), the target port inside the container (port 8080), and a node port through which the traffic will route (31491). The end result is that the Nginx server running in the pods of the `kube-verify` service is accessible from the load-balanced IP, on port 80, from anywhere on your home network.
For example, on my network, the service was exposed on `http://192.168.2.129:80`, and I can `curl` that IP from my laptop on the same network:
```
# Verify that you receive a response from Nginx on the load-balanced IP
$ curl 192.168.2.129
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"\&gt;][13]
&lt;html xmlns="<http://www.w3.org/1999/xhtml>" xml:lang="en" lang="en"&gt;
&lt;head&gt;
  &lt;title&gt;Test Page for the HTTP Server on Fedora&lt;/title&gt;
(further output omitted)
```
### MetalLB FTW
MetalLB is a great load balancer for a home Kubernetes cluster. It allows you to assign real IPs from your home network to services running in your cluster and access them from other hosts on your home network. These services can even be exposed outside the network by port-forwarding traffic through your home router (but please be careful with this!). MetalLB easily replicates cloud-provider-like behavior at home on bare-metal computers, Raspberry Pi-based clusters, and even virtual machines, making it easy to "lift-and-shift" workloads to the cloud or just familiarize yourself with how they work. Best of all, MetalLB is easy and convenient and makes accessing the services running in your cluster a breeze.
Have you used MetalLB, or do you use another load-balancer solution? Are you primarily using Nginx or HAProxy Ingress? Let me know in the comments!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/7/homelab-metallb
作者:[Chris Collins][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/clcollins
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/science_experiment_beaker_lab.png?itok=plKWRhlU (Science lab with beakers)
[2]: https://opensource.com/article/20/6/kubernetes-raspberry-pi
[3]: https://metallb.universe.tf/
[4]: https://en.wikipedia.org/wiki/Data_link_layer
[5]: https://en.wikipedia.org/wiki/Address_Resolution_Protocol
[6]: https://en.wikipedia.org/wiki/Transport_layer
[7]: https://en.wikipedia.org/wiki/Border_Gateway_Protocol
[8]: https://kubernetes.io/docs/concepts/services-networking/ingress/
[9]: https://github.com/metallb/metallb
[10]: https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
[11]: https://github.com/clcollins/homelabCloudInit/blob/master/simpleCloudInitService/data/Containerfile
[12]: tmp.A4L9yD76e5#loadbalancer
[13]: http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"\>

View File

@ -0,0 +1,85 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Ex-Solus Dev is Now Creating a Truly Modern Linux Distribution Called Serpent Linux)
[#]: via: (https://itsfoss.com/serpent-os-announcement/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
Ex-Solus Dev is Now Creating a Truly Modern Linux Distribution Called Serpent Linux
======
[Ikey Doherty][1], the developer who once created the independent Linux distribution Solus has announced his new project: Serpent OS.
[Serpent OS][2] is a Linux distribution that DOES NOT want to be categorized as “lightweight, user-friendly, privacy-focused Linux desktop distribution”.
Instead, Serpent OS has “different goals from the mainstream offering”. How? Read on.
### Serpent OS: The making of a “truly modern” Linux distribution
![][3]
Serpent takes distro-first, compatibility-later approach. This lets them take some really bold decisions.
Ikey says that it this project will not tolerate for negative actors holding Linux back. For example, NVIDIAs lack of support for accelerated Wayland support on their GPUs will not be tolerated and NVIDIA proprietary drivers will be blacklisted from the distribution.
Heres a proposed plan for the Serpent Linux project (taken from [their website][4]):
* No more usrbin split
* 100% clang-built throughout (including kernel)
* musl as libc, relying on compiler optimisations instead of inline asm
* libc++ instead of libstdc++
* LLVMs binutils variants (lld, as, etc.)
* Mixed source/binary distribution
* Moving away from x86_64-generic baseline to newer CPUs, including Intel and AMD specific optimisations
* Capability based subscriptions in package manager (Hardware/ user choice / etc)
* `UEFI` only. No more legacy boot.
* Completely open source, down to the bootstrap / rebuild scripts
* Seriously optimised for serious workloads.
* Third party applications reliant on containers only. No compat-hacks
* Wayland-only. X11 compatibility via containers will be investigated
* Fully stateless with management tools and upstreaming of patches
Ikey boldly claims that Serpent Linux is not Serpent GNU/Linux because it is not going to be dependent on a GNU toolchain or runtime.
The development for Serpent OS project starts by the end of July. There is no definite timeline of the final stable release.
### Too high claims? But Ikey has done it in the past
You may doubt if Serpent OS will see the light of the day and if it would be able to keep all the promises it made.
But Ikey Doherty has done it in the past. If I remember correctly, he first created SolusOS based on Debian. He discontinued the [Debian-based SolusOS][5] in 2013 before it even reached the beta stage.
He then went out to create [evolve OS][6] from scratch instead of using another distribution as base. Due to some naming copyright issues, the project name was changed to Solus (yes, the same old name). [Ikey quit the Solus projec][7][t][7] [in 2018][7] and other devs now handle the project.
Solus is an independent Linux distribution that gave us the beautiful Budgie desktop environment.
Ikey has done it in the past (with the help of other developers, of course). He should be able to pull this one off as well.
**Yay or Nay?**
What do you think of this Serpent Linux? Do you think it is time for developers to take a bold stand and develop the operating system with the future in the mind rather than holding on to the past? Do share your views.
--------------------------------------------------------------------------------
via: https://itsfoss.com/serpent-os-announcement/
作者:[Abhishek Prakash][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/abhishek/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/ikey-doherty-serpent-interview/
[2]: https://www.serpentos.com/
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/07/serpent-linux.png?ssl=1
[4]: https://www.serpentos.com/about/
[5]: https://distrowatch.com/table.php?distribution=solusos
[6]: https://itsfoss.com/beta-evolve-os-released/
[7]: https://itsfoss.com/ikey-leaves-solus/

View File

@ -0,0 +1,84 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to crop images in GIMP [Quick Tip])
[#]: via: (https://itsfoss.com/crop-images-gimp/)
[#]: author: (Dimitrios Savvopoulos https://itsfoss.com/author/dimitrios/)
如何使用 GIMP 裁剪图像(快速技巧)
======
你可能有很多原因要在 [GIMP][1] 中裁剪图像。例如,你可能希望删除无用的边框或信息来改善图像,或者你可能希望最终图像的焦点实在特定细节上。
在本教程中,我将演示如何在 GIMP 中快速裁剪图像而又不影响精度。让我们来看看。
### 如何在GIMP中裁剪图像
![][2]
#### 方法 1
裁剪只是一种将图像修整到比原始图像更小区域的操作。裁剪图像的过程很简单。
你可以通过“工具”面板访问“裁剪工具”,如下所示:
![Use Crop Tool for cropping images in GIMP][3]
你还可以通过菜单访问裁剪工具:
**Tools → Transform Tools → Crop**
激活该工具后,你会注意到画布上的鼠标光标将变化以指示正在使用“裁剪工具”。
现在,你可以在图像画布上的任意位置单击鼠标左键,并将鼠标拖到某个位置以创建裁剪边界。此时你不必担心精度,因为你可以在实际裁剪之前修改最终选择。
![Crop Selection][4]
此时,将鼠标光标悬停在所选内容的四个角上会更改鼠标光标并高亮显示该区域。现在,你可以微调裁剪的选区。你可以单击并拖动任何一侧或角落来移动部分选区。
选定完区域后,你只需按键盘上的“**回车**”键即可进行裁剪。
如果你想重新开始或者不裁剪,你可以按键盘上的 “**Esc**” 键。
#### 方法 2
裁剪图像的另一种方法是使用“矩形选择工具”进行选择。
**Tools → Selection Tools → Rectangle Select**
![][5]
然后,你可以使用与“裁剪工具”相同的方式高亮选区,并调整选区。选择好后,可以通过以下方式裁剪图像来适应选区。
**Image → Crop to Selection**
![][6]
#### 总结
对于 GIMP 用户而言,精确裁剪图像可以视为一项基本功能。你可以选择哪种方法更适合你的需求并探索其潜力。
如果你对过程有任何疑问,请在下面的评论中告诉我。如果你“渴望”更多 [GIMP 教程][7],请确保在你喜欢的社交媒体平台上订阅!
--------------------------------------------------------------------------------
via: https://itsfoss.com/crop-images-gimp/
作者:[Dimitrios Savvopoulos][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/dimitrios/
[b]: https://github.com/lujun9972
[1]: https://www.gimp.org/
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/06/Crop-images-in-GIMP.png?ssl=1
[3]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/06/Crop-tool.png?ssl=1
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/06/Crop-selection.jpg?ssl=1
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/06/select-1.gif?ssl=1
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/06/crop.gif?ssl=1
[7]: https://itsfoss.com/tag/gimp-tips/