Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2020-12-03 09:25:43 +08:00
commit 51137d7649
13 changed files with 1272 additions and 335 deletions

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12880-1.html)
[#]: subject: (How to rebase to Fedora 33 on Silverblue)
[#]: via: (https://fedoramagazine.org/how-to-rebase-to-fedora-33-on-silverblue/)
[#]: author: (Michal Konečný https://fedoramagazine.org/author/zlopez/)
@ -10,9 +10,9 @@
如何在 Silverblue 上变基到 Fedora 33
======
![][1]
![](https://img.linux.net.cn/data/attachment/album/202012/02/232440exewdbwdhde4mqhv.jpg)
Silverblue 是[一个建立在 Fedora 上的桌面操作系统][2]。它非常适合日常使用、开发和基于容器的工作流程。它提供了[众多的优势][3],例如在出现任何问题时能够回滚。如果你想在你的 Silverblue 系统上更新到 Fedora 33这篇文章会告诉你如何做。它不仅告诉你该怎么做还告诉你如果发生了不可预见的事情时该如何回退。
Silverblue 是[一个建立在 Fedora 上的桌面操作系统][2]。它非常适合日常使用、开发和基于容器的工作流程。它提供了[众多的优势][3],例如在出现任何问题时能够回滚。如果你想在你的 Silverblue 系统上更新到 Fedora 33这篇文章会告诉你如何做。它不仅告诉你该怎么做还告诉你如果发生了不可预见的事情时该如何回退。
在实际做变基到 Fedora 33 之前,你应该应用任何挂起的更新。在终端中输入以下内容:
@ -28,15 +28,15 @@ GNOME 软件中心会在更新界面显示有新版本的 Fedora 可用。
![Fedora 33 is available][4]
首先你需要做的是下载新镜像,点击 _Download_ 按钮。这将需要一些时间,完成后你会看到更新已经准备好安装了。
首先你需要做的是下载新镜像,点击 “Download” 按钮。这将需要一些时间,完成后你会看到更新已经准备好安装了。
![Fedora 33 is ready for installation][5]
点击 _Install_ 按钮。这一步只需要几分钟,然后会提示你重启电脑。
点击 “Install” 按钮。这一步只需要几分钟,然后会提示你重启电脑。
![Restart is needed to rebase to Fedora 33 Silverblue][6]
点击 _Restart_ 按钮就可以了。重启后,你将进入新的 Fedora 33 版本。很简单,不是吗?
点击 “Restart” 按钮就可以了。重启后,你将进入新的 Fedora 33 版本。很简单,不是吗?
### 使用终端变基
@ -79,7 +79,7 @@ via: https://fedoramagazine.org/how-to-rebase-to-fedora-33-on-silverblue/
作者:[Michal Konečný][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,104 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (robsean)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Dual booting Windows and Linux using UEFI)
[#]: via: (https://opensource.com/article/19/5/dual-booting-windows-linux-uefi)
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdoss/users/ckrzen)
Dual booting Windows and Linux using UEFI
======
A quick rundown of setting up Linux and Windows to dual boot on the same
machine, using the Unified Extensible Firmware Interface (UEFI).
![Linux keys on the keyboard for a desktop computer][1]
Rather than doing a step-by-step how-to guide to configuring your system to dual boot, Ill highlight the important points. As an example, I will refer to my new laptop that I purchased a few months ago. I first installed [Ubuntu Linux][2] onto the entire hard drive, which destroyed the pre-installed [Windows 10][3] installation. After a few months, I decided to install a different Linux distribution, and so also decided to re-install Windows 10 alongside [Fedora Linux][4] in a dual boot configuration. Ill highlight some essential facts to get started.
### Firmware
Dual booting is not just a matter of software. Or, it is, but it involves changing your firmware, which among other things tells your machine how to begin the boot process. Here are some firmware-related issues to keep in mind.
#### UEFI vs. BIOS
Before attempting to install, make sure your firmware configuration is optimal. Most computers sold today have a new type of firmware known as [Unified Extensible Firmware Interface (UEFI)][5], which has pretty much replaced the other firmware known as [Basic Input Output System (BIOS)][6], which is often included through the mode many providers call Legacy Boot.
I had no need for BIOS, so I chose UEFI mode.
#### Secure Boot
One other important setting is Secure Boot. This feature detects whether the boot path has been tampered with, and stops unapproved operating systems from booting. For now, I disabled this option to ensure that I could install Fedora Linux. According to the Fedora Project Wiki [Features/Secure Boot ][7] Fedora Linux will work with it enabled. This may be different for other Linux distributions —I plan to revisit this setting in the future.
In short, if you find that you cannot install your Linux OS with this setting active, disable Secure Boot and try again.
### Partitioning the boot drive
If you choose to dual boot and have both operating systems on the same drive, you have to break it into partitions. Even if you dual boot using two different drives, most Linux installations are best broken into a few basic partitions for a variety of reasons. Here are some options to consider.
#### GPT vs MBR
If you decide to manually partition your boot drive in advance, I recommend using the [GUID Partition Table (GPT)][8] rather than the older [Master Boot Record (MBR)][9]. Among the reasons for this change, there are two specific limitations of MBR that GPT doesnt have:
* MBR can hold up to 15 partitions, while GPT can hold up to 128.
* MBR only supports up to 2 terabytes, while GPT uses 64-bit addresses which allows it to support disks up to 8 million terabytes.
If you have shopped for hard drives recently, then you know that many of todays drives exceed the 2 terabyte limit.
#### The EFI system partition
If you are doing a fresh installation or using a new drive, there are probably no partitions to begin with. In this case, the OS installer will create the first one, which is the [EFI System Partition (ESP)][10]. If you choose to manually partition your drive using a tool such as [gdisk][11], you will need to create this partition with several parameters. Based on the existing ESP, I set the size to around 500MB and assigned it the ef00 (EFI System) partition type. The UEFI specification requires the format to be FAT32/msdos, most likely because it is supportable by a wide range of operating systems.
![Partitions][12]
### Operating System Installation
Once you accomplish the first two tasks, you can install your operating systems. While I focus on Windows 10 and Fedora Linux here, the process is fairly similar when installing other combinations as well.
#### Windows 10
I started the Windows 10 installation and created a 20 Gigabyte Windows partition. Since I had previously installed Linux on my laptop, the drive had an ESP, which I chose to keep. I deleted all existing Linux and swap partitions to start fresh, and then started my Windows installation. The Windows installer automatically created another small partition—16 Megabytes—called the [Microsoft Reserved Partition (MSR)][13]. Roughly 400 Gigabytes of unallocated space remained on the 512GB boot drive once this was finished.
I then proceeded with and completed the Windows 10 installation process. I then rebooted into Windows to make sure it was working, created my user account, set up wi-fi, and completed other tasks that need to be done on a first-time OS installation.
#### Fedora Linux
I next moved to install Linux. I started the process, and when it reached the disk configuration steps, I made sure not to change the Windows NTFS and MSR partitions. I also did not change the EPS, but I did set its mount point to **/boot/efi**. I then created the usual ext4 formatted partitions, **/** (root), **/boot** , and **/home**. The last partition I created was Linux **swap**.
As with Windows, I continued and completed the Linux installation, and then rebooted. To my delight, at boot time the [GRand][14] [Unified Boot Loader (GRUB)][14] menu provided the choice to select either Windows or Linux, which meant I did not have to do any additional configuration. I selected Linux and completed the usual steps such as creating my user account.
### Conclusion
Overall, the process was painless. In past years, there has been some difficulty navigating the changes from UEFI to BIOS, plus the introduction of features such as Secure Boot. I believe that we have now made it past these hurdles and can reliably set up multi-boot systems.
I dont miss the [Linux LOader (LILO)][15] anymore!
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/5/dual-booting-windows-linux-uefi
作者:[Alan Formy-Duval][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/alanfdoss/users/ckrzen
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/linux_keyboard_desktop.png?itok=I2nGw78_ (Linux keys on the keyboard for a desktop computer)
[2]: https://www.ubuntu.com
[3]: https://www.microsoft.com/en-us/windows
[4]: https://getfedora.org
[5]: https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface
[6]: https://en.wikipedia.org/wiki/BIOS
[7]: https://fedoraproject.org/wiki/Features/SecureBoot
[8]: https://en.wikipedia.org/wiki/GUID_Partition_Table
[9]: https://en.wikipedia.org/wiki/Master_boot_record
[10]: https://en.wikipedia.org/wiki/EFI_system_partition
[11]: https://sourceforge.net/projects/gptfdisk/
[12]: /sites/default/files/u216961/gdisk_screenshot_s.png
[13]: https://en.wikipedia.org/wiki/Microsoft_Reserved_Partition
[14]: https://en.wikipedia.org/wiki/GNU_GRUB
[15]: https://en.wikipedia.org/wiki/LILO_(boot_loader)

View File

@ -1,119 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Day 2: Rails associations & dragging divs around)
[#]: via: (https://jvns.ca/blog/2020/11/10/day-2--rails-associations---dragging-divs-around/)
[#]: author: (Julia Evans https://jvns.ca/)
Day 2: Rails associations & dragging divs around
======
null
Hello! Today was day 2 of building my toy project. Here are a few more notes on things that have been fun about Rails!
### the goal: make a refrigerator poetry forum
I wanted to make kind of a boring standard website to learn Rails, and that other people could interact with. Like a forum! But of course if people can actually type on a website that creates all kinds of problems (what if theyre spammers? or just mean?).
The first idea I came up with that would let people interact with the website but not actually be able to type things into it was a refrigerator poetry forum where you can write poems given only a fixed set of words.
So, thats the plan!
My goal with this project is to find out if I want to use Rails for other small web projects (instead of what I usually do, which is use something more basic like Flask, or give up on having a backend at all and write everything in Javascript).
### how do you drag the words around? jQuery UI draggable!
I wanted people to be able to drag the words around, but I didnt feel like writing a lot of Javascript. It turns out that this is SUPER easy theres a jQuery library to do it called “draggable”!
At first the dragging didnt work on mobile, but theres a hack to make jQuery UI work on mobile called [jQuery UI touch punch][1]. Heres what it looks like (you can view source if youre interested in seeing how it works, theres very little code).
banana forest cake is
### a fun Rails feature: “associations”
Ive never used a relational ORM before, and one thing I was excited about with Rails was to see what using Active Record is like! Today I learned about one of Rails ORM features: [associations][2]. Heres what thats about if you know absolutely nothing about ORMs like me.
In my forum, I have:
* users
* topics (I was going to call this “threads” but apparently thats a reserved word in Rails so theyre called “topics” for now)
* posts
When displaying a post, I need to show the username of the user who created the post. So I thought I might need to write some code to load the posts and load the user for each post like this: (in Rails, `Post.where` and `User.find` will run SQL statements and turn the results into Ruby objects)
```
@posts = Post.where(topic_id: id)
@posts.each do |post|
user = User.find(post.user_id)
post.user = user
end
```
This is no good though its doing a separate SQL query for every post! I knew there was a better way, and I found out that its called [Associations][2]. That link is to the guide from <https://guides.rubyonrails.org>, which has treated me well so far.
Basically all I needed to do was:
1. Add a `has_many :posts` line to the User model
2. Add a `belongs_to :user` line to the Post model
3. Rails now knows how to join these two tables even though I didnt tell it what columns to join on! I think this is because I named the `user_id` column in the `posts` table according to the convention it expects.
4. Do the exact same thing for `User` and `Topic` (a topic also `has_many :posts`)
And then my code to load every post along with its associated user becomes just one line! Heres the line:
```
@posts = @topic.posts.order(created_at: :asc).preload(:user)
```
More importantly than it being just one line, instead of doing a separate query to get the user for each post, it gets all the users in 1 query. Apparently there are a bunch of [different ways][3] to do similar things in Rails (preload, eager load, joins, and includes?). I dont know what all those are yet but maybe Ill learn that later.
### a fun Rails feature: scaffolding!
Rails has this command line tool called `rails` and it does a lot of code generation. For example, I wanted to add a Topic model / controller. Instead of having to go figure out where to add all the code, I could just run:
```
rails generate scaffold Topic title:text
```
and it generated a bunch of code, so that I already had basic endpoints to create / edit / delete Topics. For example, heres my [topic controller right now][4], most of which I did not write (I only wrote the highlighted 3 lines). Ill probably delete a lot of it, but it feels kinda nice to have a starting point where I can expand on the parts I want and delete the parts I dont want.
### database migrations!
The `rails` tool can also generate database migrations! For example, I decided I wanted to remove the `title` field from posts.
Heres what I had to do:
```
rails generate migration RemoveTitleFromPosts title:string
rails db:migrate
```
Thats it just run a couple of command line incantations! I ran a few of these migrations as I changed my mind about what I wanted my database schema to be and its been pretty straightforward so far it feels pretty magical.
It got a tiny bit more interesting when I tried to add a `not null` constraint to a column where some of the fields in that column were null the migration failed. But I could just fix the offending records and easily rerun the migration.
### thats all for today!
tomorrow maybe Ill put it on the internet if I make more progress.
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2020/11/10/day-2--rails-associations---dragging-divs-around/
作者:[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]: https://github.com/furf/jquery-ui-touch-punch
[2]: https://guides.rubyonrails.org/association_basics.html
[3]: https://blog.bigbinary.com/2013/07/01/preload-vs-eager-load-vs-joins-vs-includes.html
[4]: https://github.com/jvns/refrigerator-forum/blob/776b3227cfd7004cb1efb00ec7e3f82a511cbdc4/app/controllers/topics_controller.rb#L13-L15

View File

@ -1,102 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Keep track of multiple Git remote repositories)
[#]: via: (https://opensource.com/article/20/11/multiple-git-repositories)
[#]: author: (Peter Portante https://opensource.com/users/portante)
Keep track of multiple Git remote repositories
======
Having consistent naming standards is key to keeping local and upstream
Git repos straight.
![Digital hand surrounding by objects, bike, light bulb, graphs][1]
Working with remote repositories gets confusing when the names of the remote repositories in your local Git repo are inconsistent.
One approach to solving this issue is to standardize the use and meaning of two words: `origin`, referring to your personal `example.com/<USER>/*` repos, and `upstream`, referring to the `example.com` repo from which you forked the `origin` repo. In other words, `upstream` refers to the upstream repo where work is publicly submitted, while `origin` refers to your local fork of the upstream repo from which you generate pull requests (PRs), for example.
Using the [pbench][2] repo as an example, here is a step-by-step approach to set up a new local clone with `origin` and `upstream` defined consistently.
1. On most Git hosting services, you must fork a project when you want to work on it. When you run your own Git server, that's not necessary, but for a codebase that's open to the public, it's an easy way to transfer diffs among contributors.
Create a fork of a Git repository. For this example, assume your fork is located at `example.com/<USER>/pbench`.
2. Next, you must obtain a Uniform Resource Identifier ([URI][3]) for cloning over SSH. On most Git hosting services, such as GitLab or GitHub, it's in a button or panel labeled **Clone** or **Clone over SSH**. Copy the clone URI to your clipboard.
3. On your development system, clone the repo using the text you copied:
```
`$ git clone git@example.com:<USER>/pbench.git`
```
This clones the Git repository with the default name `origin` for your forked copy of the pbench repo.
4. Change directory to the repo you just cloned:
```
`$ cd ~/pbench`
```
5. Next, obtain the SSH URI of the source repo (the one you originally forked). This is probably done the same way as above: Find the **Clone** button or panel and copy the clone address. In software development, this is typically referred to as "upstream" because (in theory) this is where most commits happen, and you intend to let those commits flow downstream into your copy of the repository.
6. Add the URI to your local copy of the repository. Yes, there will be _two different_ remotes assigned to your local copy of the repository:
```
`$ git remote add upstream \ git@example.com:bigproject/pbench.git`
```
7. You now have two named remote repos: `origin` and `upstream`. You can see your remote repos with the remote subcommand:
```
`$ git remote -v`
```
Right now, your local `master` branch is tracking the `origin` master, which is not necessarily what you want. You probably want to track the `upstream` version of this branch because upstream is where most development takes place. The idea is that you are adding your changes on top of whatever you get from upstream.
8. Change your local master branch to track `upstream/master`:
```
$ git fetch upstream
$ git branch --set-upstream-to=upstream/master master
```
You can do this for any branch you want, not just `master`. For instance, some projects use a `dev` branch for all unstable changes, reserving `master` for code approved for release.
9. Once you've set your tracking branches, be sure to `rebase` your master to bring it up to date to any new changes made to the upstream repo:
```
$ git remote update
$ git checkout master
$ git rebase
```
This is a great way to keep your Git repositories synchronized between forks. If you want to automate this, read Seth Kenlon's article on [cohosting Git repositories with Ansible][4] to learn how.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/11/multiple-git-repositories
作者:[Peter Portante][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/portante
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003588_01_rd3os.combacktoschoolseriesk12_rh_021x_0.png?itok=fvorN0e- (Digital hand surrounding by objects, bike, light bulb, graphs)
[2]: https://github.com/distributed-system-analysis/pbench
[3]: https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
[4]: https://opensource.com/article/19/11/how-host-github-gitlab-ansible

View File

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

View File

@ -0,0 +1,125 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (5 collaboration tips for using an open source alternative to Google Docs)
[#]: via: (https://opensource.com/article/20/12/onlyoffice-docs)
[#]: author: (Nadya Knyazeva https://opensource.com/users/hellonadya)
5 collaboration tips for using an open source alternative to Google Docs
======
Collaborative writing and editing is a breeze when you put these
ONLYOFFICE features to work.
![Filing cabinet for organization][1]
ONLYOFFICE Docs is a self-hosted open source alternative to Microsoft Office and Google Docs for collaborating on documents, spreadsheets, and presentations in real time.
The following are the five most important ways [ONLYOFFICE Docs][2] helps organize my collaborative work.
### 1\. Integrate with document storage
ONLYOFFICE Docs is highly flexible in how you can store documents. By default, you can use ONLYOFFICE Docs within an ONLYOFFICE Workspace. This provides a productivity solution for managing documents and projects. It's the clear way to use ONLYOFFICE Docs because it's included; when you install one, you get the other.
However, the full ONLYOFFICE suite can be integrated with ownCloud, Nextcloud, and other popular sync and share platforms. Helpful [connectors][3] are available in your sharing platform's official app store or on GitHub.
Finally, since ONLYOFFICE is open source, web app developers are free to integrate ONLYOFFICE Docs into their applications using the [ONLYOFFICE API][4].
### 2\. Manage document permissions
In ONLYOFFFICE Docs, you can differentiate what your teammates can do when they open shared documents. You can grant them permission to view, edit, or share files or perform specific actions—leave comments, suggest changes in review mode, fill in determined fields, etc. Differentiating document permissions can help structure and secure your collaboration.
![ONLYOFFICE sharing options][5]
(Nadya Knyazeva, [CC BY-SA 4.0][6])
The permissions you have available depend on your document management system. In ONLYOFFICE Workspace and ownCloud, you can share files with all the permissions listed above, plus you'll get an additional permission for spreadsheets (Custom Filter in ONLYOFFICE or Modify Filter in ownCloud). The filtering permission allows you to decide whether filters applied by one user should affect only that person or everyone. If you're integrating with Nextcloud or, for example, Seafile, you get fewer permission options.
If you are integrating the suite and want to add more permissions, your app must allow registering new sharing attributes (such as the ability to restrict downloading, printing, or copying document content to the clipboard), as described in [the API documentation][7].
### 3\. True collaboration
The collaborative work toolset is basically the same for all environments. You have comments to add notes, suggestions, or questions for people working on a document together. ONLYOFFICE has this, of course, but it strives to provide a few extra features whenever possible. For instance, in ONLYOFFICE Workspace, you can quickly add mentions by typing + or @ followed by a user's name to draw a specific person's attention to your comment.
![ONLYOFFICE comments][8]
(Nadya Knyazeva, [CC BY-SA 4.0][6])
There's also a chat feature to quickly discuss something with teammates without switching to a messaging app (be aware that the chat history clears when you close a document).
Track changes enables reviewing documents by suggesting changes. All the changes made in this mode are highlighted, and the owner and users with full editing access can accept or reject them or preview the document with all the changes accepted or rejected.
What's important about collaborative work in ONLYOFFICE Docs is that users working simultaneously on the same docs can set individual preferences (e.g., enable track changes or spell checking, display non-printing characters, zoom the doc in and out, and so on) without disturbing each other.
### 4\. Version control
Versioning is so important that entire industries have developed around the process. For developers, writing without Git-style revision control can be unsettling. For content creators, emailing revisions back and forth to one another gets messy and confusing.
ONLYOFFICE Docs allows viewing a document's version history in the editor. Changes and the author who made them are highlighted in different colors. This feature's availability is determined by the doc management system you use; version history is available for ONLYOFFICE Workspace, Nextcloud, and ownCloud integration.
![ONLYOFFICE version history in Nextcloud][9]
(Nadya Knyazeva, [CC BY-SA 4.0][6])
### 5\. Change real-time co-editing mode
There are two ways to co-edit a document in real-time in ONLYOFFICE Docs. They are called Fast and Strict modes, and they're available regardless of how you integrate ONLYOFFICE into your toolchain.
Fast mode allows you to see your co-authors' changes as they are typing. Your changes are also shown to others immediately.
In Strict mode, you lock the document you are working on, and no one can see what you are typing until you click Save. You can see what parts of the document are locked by co-authors, but you can not see what they are doing until they save.
When collaborating on a document in one of these modes, the Ctrl+Z (undo) command affects only your work, so your co-authors' actions are unaffected.
### Bonus: Security options
Depending on your environment, you'll find different options to protect collaboration on documents.
ONLYOFFICE Workspace offers the standard security toolset, with HTTPS, backups, two-factor authentication, secure sign-on, and an option to encrypt data at rest. One feature that, according to ONLYOFFICE, has no counterpart is called _Private Rooms_.
A Private Room is a folder that can be accessed only through the desktop app. Each office file created and stored there is encrypted using the AES-265 algorithm. Everything you type—every letter, every number, every symbol—is encrypted immediately, even if you're collaborating in real time.
![ONLYOFFICE Private Rooms][10]
(Nadya Knyazeva, [CC BY-SA 4.0][6])
ONLYOFFICE Docs also uses JSON Web Tokens (JWT) for security. The editors request an encrypted signature to check who can access the document and what they can do with it. Currently, JWT is implemented for ONLYOFFICE Workspace and for Nextcloud, ownCloud, Alfresco, Confluence, HumHub, and Nuxeo integrations, in addition to their built-in security tools.
In a Nextcloud integration, you can also insert watermarks to protect sensitive docs. Watermarks are enabled by an admin and cannot be removed from a document.
![ONLYOFFICE Watermark in Nextcloud][11]
(Nadya Knyazeva, [CC BY-SA 4.0][6])
### So many features
There are many more features in ONLYOFFICE that will fit into one article. If you're looking for an open source alternative to Microsoft or Google collaboration tools, ONLYOFFICE is the most powerful option I know of. Give it a try and let me know in the comments what you think of ONLYOFFICE Docs as a collaboration tool.
Take a look at five great open source alternatives to Google Docs.
Sandstorm's Jade Wang shares some of her favorite open source web apps that are self-hosted...
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/onlyoffice-docs
作者:[Nadya Knyazeva][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/hellonadya
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/files_documents_organize_letter.png?itok=GTtiiabr (Filing cabinet for organization)
[2]: https://www.onlyoffice.com/office-suite.aspx
[3]: https://www.onlyoffice.com/all-connectors.aspx
[4]: https://api.onlyoffice.com/editors/basic
[5]: https://opensource.com/sites/default/files/uploads/1._sharing_window.png (ONLYOFFICE sharing options)
[6]: https://creativecommons.org/licenses/by-sa/4.0/
[7]: https://api.onlyoffice.com/editors/config/document/permissions
[8]: https://opensource.com/sites/default/files/uploads/2._comments.png (ONLYOFFICE comments)
[9]: https://opensource.com/sites/default/files/uploads/3._version_history_in_nextcloud.png (ONLYOFFICE version history in Nextcloud)
[10]: https://opensource.com/sites/default/files/uploads/4_privateroom.png (ONLYOFFICE Private Rooms)
[11]: https://opensource.com/sites/default/files/uploads/5._watermark.png (ONLYOFFICE Watermark in Nextcloud)

View File

@ -0,0 +1,246 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Set up OpenStack on a Raspberry Pi cluster)
[#]: via: (https://opensource.com/article/20/12/openstack-raspberry-pi)
[#]: author: (AJ Canlas https://opensource.com/users/ajscanlas)
Set up OpenStack on a Raspberry Pi cluster
======
Since Arm processors are "first-class citizens" in OpenStack, and
Raspberry Pis are built on Arm, why not combine them?
![Raspberries with pi symbol overlay][1]
In the year since the Raspberry Pi 4 was released, I've seen many tutorials (like [this][2] and [this][3]) and [articles][4] on how well the 4GB model works with container platforms such as Kubernetes (K8s), Lightweight Kubernetes (K3s), and Docker Swarm. As I was doing research, I read that Arm processors are "first-class citizens" in OpenStack. Since Raspberry Pi is built on Arm, I decided to test this theory by installing OpenStack on a Raspberry Pi cluster.
### Prerequisites
There are a few things I need to consider for this project:
1. Whether to use Ubuntu 64-bit or CentOS 64-bit for Raspberry Pi to boot headless; [Raspberry Pi OS][5] will not suffice, even as a Debian derivative, because there are no OpenStack packages for it.
2. I need the latest version of OpenStack that will run in my distribution because I don't think the latest versions have an AArch64 image.
3. I doubt that there is any documentation for automating a ground-up installation, so I will use a step-by-step process.
Materials used:
1. Four Raspberry Pi 4Bs, 4GB model (8GB recommended)
2. Four 32GB MicroSD cards
3. Four Raspberry Pi cases with fans and heatsinks (very important)
4. Four Raspberry Official Power supply
### Configure the base operating system
I used the CentOS AArch64 image; as I suspected, there is not a CentOS 8 image available for Raspberry Pi, so I used CentOS 7 AArch64 with this [prebuilt image][6]. It didn't work when I tried installing it with `dd`, but it worked like a charm when I used balenaEtcher.
![balenaEtcher][7]
(Aaron John Canlas, [CC BY-SA 4.0][8])
After burning the images on the SD cards, I plugged the Raspberry Pis into my router to check their IP addresses so I could remotely access them using SSH. I configured their WiFi and hostnames using `nmtui` to access them without any cables attached (except for their power source, of course). The default user is `root`, and the default password is `centos`.
![SSH console in CentOS 7 AArch64][9]
(Aaron John Canlas, [CC BY-SA 4.0][8])
I updated the operating system:
```
`[root@rpi4b4-0 ~]# yum update -y`
```
I repeated this process on all my Raspberry Pis then rebooted them.
### Install OpenStack
The latest OpenStack releases (Ussuri and Victoria) require CentOS 8, so I used Train, as it's the most recent version that uses CentOS 7.
![Confirming OpenStack Train's availability][10]
(Aaron John Canlas, [CC BY-SA 4.0][8])
I used the OpenStack Foundation's installation steps, but I encountered some issues with it. To make it easier for others to install OpenStack on CentOS 7, I compiled the following links and tips.
#### Prerequisites
1. Network Time Protocol (NTP)
1. [Controller node installation][11]
2. [Compute node installation][12]
3. [Verify operation][13]
2. OpenStack packages: [Run the Train version of the installation][14] (this link includes all versions)
3. SQL database: [Controller node installation][15]
4. Message queue: [Controller node installation][16]
5. Memcached: [Controller node installation][17]
6. Etcd: [Controller node installation][17]
#### OpenStack services
1. Identity service (Keystone)
1. [Controller node installation][18]
2. [Verify operation][19]
![Keystone verification][20]
(Aaron John Canlas, [CC BY-SA 4.0][8])
2. Imaging service (Glance)
1. [Controller node installation][21]
2. [Verify operation][22]
TIP: Instead of downloading the CirrOS image mentioned in the documents, make sure to use the [AArch64 CirrOS image][23] for Raspberry Pis.
![Glance verification][24]
(Aaron John Canlas, [CC BY-SA 4.0][8])
3. Placement service (Placement)
1. [Controller node installation][25]
2. [Verify operation][26]
![Placement verification][27]
(Aaron John Canlas, [CC BY-SA 4.0][8])
4. Compute service (Nova)
1. [Controller node installation][28]
2. [Compute node installation][29]
3. [Verify operation][30]
TIP: In the last part of the verify operation, `nova-status upgrade check` fails due to a packaging error. To fix it, edit the following file in the controller: [code]
[root@rpi4b4-0 ~]# vim /etc/httpd/conf.d/00-placement-api.conf
(…)
&lt;Directory /usr/bin&gt;
   &lt;IfVersion &gt;= 2.4&gt;
      Require all granted
   &lt;/IfVersion&gt;
   &lt;IfVersion &lt; 2.4&gt;
      Order allow,deny
      Allow from all
   &lt;/IfVersion&gt;
&lt;/Directory&gt;
```
If you run `nova-status upgrade check` now, it will work.
![Nova verification][31]
(Aaron John Canlas, [CC BY-SA 4.0][8])
5. Networking service (Neutron)
1. [Controller node installation][32]
2. [Controller for Option 2: Self-service network installation][33]
To enable the `br_netfiler` module: [code]
[root@rpi4b4-0 ~]# modprobe br_netfilter
[root@rpi4b4-0 ~]# echo "br_netfilter" &gt; /etc/modules-load.d/br_netfilter.conf
[root@rpi4b4-0 ~]# lsmod|grep br_netfilter
```
3. [Compute node installation][34]
4. [Compute for Option 2: Self-service network installation][35]
To enable the `br_netfiler` module: [code]
[root@rpi4b4-X ~]# modprobe br_netfilter
[root@rpi4b4-X ~]# echo "br_netfilter" &gt; /etc/modules-load.d/br_netfilter.conf
[root@rpi4b4-X ~]# lsmod|grep br_netfilter
```
5. [Verify operation][36]
6. [Verify operation for Option 2: Self-service network installation][37]
![Neutron verification][38]
(Aaron John Canlas, [CC BY-SA 4.0][8])
6. Dashboarding service (Horizon)
1. [Controller node installation][39]
TIP: Upon restarting the httpd service, you will get a 404 error. To resolve it, add this line to the end of the `/etc/openstack-dashboard/local_settings`: [code]`WEBROOT = '/dashboard'`[/code] Then restart httpd as usual: [code]`[root@rpi4b4-X ~]# systemctl restart httpd.service`
```
2. [Verify operation][40]
![Horizon verification][41]
(Aaron John Canlas, [CC BY-SA 4.0][8])
### How well does it work?
This was a fun and successful experiment. In terms of performance, it's quite slow considering that my controller only has four cores and 4GB RAM, but it's useful for managing multiple computers in one dashboard. My next step will be to try this with a [TripleO][42] deployment and a [Ceph][43] storage cluster to enable live migration. I might try using the Raspberry Pi's Ethernet if I have a larger cluster and workload in mind; for now, [Grafana][44] is working fine for internet monitoring.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/openstack-raspberry-pi
作者:[AJ Canlas][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/ajscanlas
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/life-raspberrypi_0.png?itok=Kczz87J2 (Raspberries with pi symbol overlay)
[2]: https://opensource.com/article/20/6/kubernetes-raspberry-pi
[3]: https://opensource.com/article/20/3/kubernetes-raspberry-pi-k3s
[4]: https://opensource.com/article/20/8/kubernetes-raspberry-pi
[5]: https://www.raspberrypi.org/software/
[6]: http://mirror.centos.org/altarch/
[7]: https://opensource.com/sites/default/files/uploads/balenaetcher.png (balenaEtcher)
[8]: https://creativecommons.org/licenses/by-sa/4.0/
[9]: https://opensource.com/sites/default/files/uploads/ssh_console.png (SSH console in CentOS 7 AArch64)
[10]: https://opensource.com/sites/default/files/uploads/openstack_train.png (Confirming OpenStack Train's availability)
[11]: https://docs.openstack.org/install-guide/environment-ntp-controller.html
[12]: https://docs.openstack.org/install-guide/environment-ntp-other.html
[13]: https://docs.openstack.org/install-guide/environment-ntp-verify.html
[14]: https://docs.openstack.org/install-guide/environment-packages-rdo.html
[15]: https://docs.openstack.org/install-guide/environment-sql-database-rdo.html#install-and-configure-components
[16]: https://docs.openstack.org/install-guide/environment-messaging-rdo.html
[17]: https://docs.openstack.org/install-guide/environment-memcached-rdo.html
[18]: https://docs.openstack.org/keystone/train/install/keystone-install-rdo.html
[19]: https://docs.openstack.org/keystone/train/install/keystone-verify-rdo.html
[20]: https://opensource.com/sites/default/files/uploads/keystone_verification.png (Keystone verification)
[21]: https://docs.openstack.org/glance/train/install/install-rdo.html
[22]: https://docs.openstack.org/glance/train/install/verify.html
[23]: http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-aarch64-disk.img
[24]: https://opensource.com/sites/default/files/uploads/glance_verification.png (Glance verification)
[25]: https://docs.openstack.org/placement/train/install/install-rdo.html
[26]: https://docs.openstack.org/placement/train/install/verify.html
[27]: https://opensource.com/sites/default/files/uploads/placement_verification.png (Placement verification)
[28]: https://docs.openstack.org/nova/train/install/controller-install-rdo.html
[29]: https://docs.openstack.org/nova/train/install/compute-install-rdo.html
[30]: https://docs.openstack.org/nova/train/install/verify.html
[31]: https://opensource.com/sites/default/files/uploads/nova_verification.png (Nova verification)
[32]: https://docs.openstack.org/neutron/train/install/controller-install-rdo.html
[33]: https://docs.openstack.org/neutron/train/install/controller-install-option2-rdo.html
[34]: https://docs.openstack.org/neutron/train/install/compute-install-rdo.html
[35]: https://docs.openstack.org/neutron/train/install/compute-install-option2-rdo.html
[36]: https://docs.openstack.org/neutron/train/install/verify.html
[37]: https://docs.openstack.org/neutron/train/install/verify-option2.html
[38]: https://opensource.com/sites/default/files/uploads/neutron_verification.png (Neutron verification)
[39]: https://docs.openstack.org/horizon/train/install/install-rdo.html
[40]: https://docs.openstack.org/horizon/train/install/verify-rdo.html
[41]: https://opensource.com/sites/default/files/uploads/horizon_verification.png (Horizon verification)
[42]: https://docs.openstack.org/tripleo-docs/latest/index.html
[43]: https://en.wikipedia.org/wiki/Ceph_(software)
[44]: https://grafana.com/

View File

@ -0,0 +1,372 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Vagrant beyond the basics)
[#]: via: (https://fedoramagazine.org/vagrant-beyond-basics/)
[#]: author: (Andy Mott https://fedoramagazine.org/author/amott/)
Vagrant beyond the basics
======
![][1]
Photo by [Kelli McClintock][2] on [Unsplash][3]
There are, like most things in the Unix/Linux world, many ways of doing things with Vagrant, but here are some examples of ways to grow your Vagrantfile portfolio and increase your knowledge and use.
If you have not yet installed vagrant you can follow the first part of this series.
> [Installing and running Vagrant using qemu-kvm][4]
### Some Vagrantfile basics
All Vagrantfiles start with “**Vagrant.configure(“2”) do |config|**” and finish with a corresponding “**end**”:
```
```
Vagrant.configure("2") do |config|
  ...
  ...
end
```
```
The “2” represents the version of Vagrant, and is currently either 1 or 2. Unless you need to use the older version simply stick with the latest.
The config structure is broken down into namespaces:
**config.vm** modify the configuration of the machine(s) that Vagrant manages.
**config.ssh** for configuring how Vagrant will access your machine over SSH.
**config.winrm** configuring how Vagrant will access your Windows guest over WinRM.
**config.winssh** the WinSSH communicator is built specifically for the Windows native port of OpenSSH.
**config.vagrant** modify the behavior of Vagrant itself.
Each line in a namespace begins with the word config:
**config.vm.box = “fedora/32-cloud-base”
config.vm.network “private_network”**
There are many options here, and a read of the documentation pages is strongly recommended. They can be found at <https://www.vagrantup.com/docs/vagrantfile>
Also in this section you can configure provider-specific options. In this case the provider is libvirt, and the specific config looks like this:
```
```
config.vm.provider :libvirt do |libvirt|
  libvirt.cpus = 1
  libvirt.memory = 512
```
```
In the example above, all libvirt VMs will be created with a single CPU and 512Mb of memory unless specifically overridden.
The VM namespace is where you define all machines you want this Vagrantfile to build. Notice that this is still a part of the config section, and lines should therefore begin with config. All sections or parts of sections have an end statement to close them off.
### Creating multiple machines at once
Depending on what you need to achieve, this can be a simple loop or multiple machine definitions. To create any number of machines in a series, with the same settings but perhaps different names and/or IP addresses, you can just provide a range as shown here:
```
```
(1..5).each do |i|
  config.vm.define "server#{i}" do |server|
    server.vm.hostname = "server#{i}.example.com"
  end
end
```
```
This will create 5 servers, named server1, server2, server3 etc.
Of note, using Ruby style “**for i in 1..3 do**” doesnt work despite Vagrantfile syntax actually being Ruby, so use the method from the example above.
If you need servers with different hostnames, different hardware etc then youll need to specify them individually, or at least in groups if the situation lends itself to that. Lets say you need to create a typical web/db/load balancer infrastructure, with 2 web servers, a single database server and a load balancer for the web traffic. Ignoring the specific software setup for this, to simply create the virtual machines ready for provisioning you could use something like this:
```
```
# Load Balancer
config.vm.define "loadbal", primary: true do |loadbal|
  loadbal.vm.hostname = "loadbal"
end
# Database
config.vm.define "db", primary: true do |db|
  db.vm.hostname = "db"
end
# Web Servers x2
(1..2).each do |i|
  config.vm.define "web#{i}" do |web|
    web.vm.hostname = "web#{i}"
  end
end
```
```
This uses a combination of multiple machine calls and a small loop to build 4 VMs with a single vagrant up command.
### Networking
Vagrant generally creates its own network for VM access, and you use this with vagrant ssh. If you create more than one VM then you must use the VM name to identify which one you wish to connect to **vagrant ssh** _**vmname**_.
There are a number of configuration options available which allow you to interact with your VMs in various ways.
The vagrant-libvirt plugin creates a network for the guests to use. This is automated and will always be present even if you define your own networks. The network is named “vagrant-libvirt” and can be seen either in the Virtual Networks tab of virt-managers connection details or by issuing a **sudo virsh net-list** command.
If you use dhcp for your guests, you can find the individual IP addresses with the virsh net-dhcp-list command: **sudo virsh net-dhcp-leases vagrant-libvirt**
#### Port Forwarding
The simplest change to default networking is port forwarding. This uses a simple format like most Vagrant config: **config.vm.network “forwarded_port”, guest: 80, host: 8080**
This listens to port 8080 on your local machine and forwards connections to port 80 on the Vagrant machine. If you need to use a UDP port, simply add **, protocol: “udp”** to the end of that line (notice that comma which should come immediately after the second port number).
Obviously for more complex configurations this might not be ideal, as you need to specify every single port you want to forward. If you then add multiple machines the complexity can really become too much.
In addition to this, anyone on your network can access these ports if they know your IP address, so thats something you should be aware of.
#### Public Network
This creates a network card for the Vagrant VM which connects to your host network, and will therefore be visible to all machines on that network. As Vagrant is not designed to be secure, you should be aware of any vulnerabilities and take steps to protect against them.
To configure a public network, add **config.vm.network “public_network”** to your Vagrantfile. This will use DHCP to obtain a network address.
If you wish to assign a static IP address, you can add one to the end of the network declaration: **config.vm.network “public_network”, ip: “192.168.0.1”**
If youre creating multiple guests you can put the network configuration in the vm namespace, and even allocate IPs based on iteration too:
```
```
Vagrant.configure("2") do |config|
  config.vm.box = "centos/8"
  config.vm.provider :libvirt do |libvirt|
    libvirt.qemu_use_session = false
  end
  # Servers x2
  (1..2).each do |i|
    config.vm.define "server#{i}" do |server|
      server.vm.hostname = "server#{i}"
      server.vm.network "public_network", ip: "192.168.122.20#{i}"
    end
  end
end
```
```
#### Private Network
This works very much like the Public Network option, only the network is only available to the host machine and the Vagrant guests. The syntax is almost identical too: **config.vm.network “private_network”, type: “dhcp”**
 To use a static IP address, simply add it**:**
```
```
config.vm.network "private_network", ip: "192.168.50.4"
```
```
This will create a new network in libvirt, usually named something like “vagrant-private-dhcp” you can see this with the command **sudo virsh net-list** while the VM is running. This network is created and destroyed along with the vagrant guests.
Again, the network config can be specified for all guests, or per guest as shown in the public network example above.
### Provisioning
Once you have your VMs defined, you can obviously then do whatever you want with them, but as soon as you issue a vagrant destroy command any changes will be lost. This is where automated provisioning comes in.
You can use several methods to provision your machines, from simple file copies to shell scripts, Ansible, Chef and Puppet. Many of the main methods can be used, but Ill cover the simple ones here if you need to use something else please read the documentation as its all covered.
#### File uploads
To copy a file to the Vagrant guest, add a line to the Vagrantfile like this:
```
```
config.vm.provision "file", source: "~/myfile", destination: "myfile"
```
```
You can copy directories too:
```
```
config.vm.provision "file", source: "~/path/to/host/folder", destination: "$HOME/remote/newfolder"
```
```
The directory structure should already exist on the Vagrant host, and will be copied in its entirety, including subdirectories and files.
Note: If you add a trailing slash to the destination path, the source path will be placed under this so make sure you only do this if you want that outcome. For example, if the above destination was **“$HOME/remote/newfolder/”,** then the result would see “$HOME/remote/newfolder/folder” created with the contents of the source placed here.
#### Shell commands
You can include individual commands, inline scripts or external scripts to perform provisioning tasks.
A single command would take this form, and any valid command line command can be used here: **config.vm.provision “shell”, inline: “sudo dnf update -y”**
An inline script is less common, and declared at the top of the Vagrantfile then called during provisioning:
```
```
$script = &amp;lt;&amp;lt;-SCRIPT
echo I am provisioning...
date &gt; /etc/vagrant_provisioned_at
SCRIPT
Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: $script
end
```
```
More common is the external shell script, which gives more flexibility and makes code more modular. Vagrant uploads the file to the guest then executes it. Simply call the script in the provisioning line:
**config.vm.provision “shell”, path: “script.sh”**
The file need not be local to the Vagrant host either:
**config.vm.provision “shell”, path: “<https://example.com/provisioner.sh>**
#### Ansible
To use Ansible to provision your VMs you must have it installed on the Vagrant host; see <https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-rhel-centos-or-fedora>.
You specify an Ansible playbook to provision your VM in the following way:
```
```
config.vm.provision "ansible" do |ansible|
  ansible.playbook = "playbook.yml"
end
```
```
This then calls the playbook, which will run as any externally-run ansible playbook would.
If youre building multiple VMs with your Vagrantfile then its likely you want different configurations for some of them, and in this case you should provision within the definition of each VM, as shown here:
```
```
# Web Servers x2
(1..2).each do |i|
  config.vm.define "web#{i}" do |web|
    web.vm.hostname = "web#{i}"
    web.vm.provision "ansible" do |ansible|
      ansible.playbook = "web.yml"
    end
  end
end
```
```
Ansible provisioners come in two formats ansible and ansible_local. The ansible provisioner requires that Ansible is installed on the Vagrant host, and will connect remotely to your guest VMs to provision them. This means all necessary ssh authentication must be in place for it to work. The ansible_local provisioner executes playbooks directly on the guest VMs, which therefore requires Ansible be installed on each of the guests you want to provision. Vagrant will try to install Ansible on the guests in order to do this, (This can be controlled with the **install** option, but is enabled by default). On RHEL-style systems like Fedora, Ansible is installed from the EPEL repository. Simply use either ansible or ansible_local in the **config_vm_provision** command to choose the style you need.
### Synced Folders
Vagrant allows you to sync folders between your Vagrant host and your guests, allowing access to configuration files, data etc. By default, the folder containing the Vagrant file is shared and mounted under /vagrant on each guest.
To configure additional synced folders, use the **config.vm.synced.folder** command:
```
```
config.vm.synced_folder "src/", "/srv/website"
```
```
The two parameters are the source folder on the Vagrant host and the mount directory on the guest. The destination folder will be created if it does not exist, recursively if necessary.
Options for synced folders allow you to configure them better, including the option to disable them completely. Other options allow you to specify a group owner of the folder (group), the folder owner (owner), plus mount options. There are others but these are the main ones.
You can disable the default share with the following command:
```
```
config.vm.synced_folder ".", "/vagrant", disabled: true
```
```
Other options are configured as follows:
```
```
config.vm.synced_folder "src/", "/srv/website",
  owner: "apache", group: "apache"
```
```
#### NFS synced folders
When using Vagrant on a Linux host, synced folders use NFS (with the exception of the default share which uses rsync; see below) so you must have NFS installed on the Vagrant host, and the guests also need NFS support installation. To use NFS with non-Linux hosts, simply specify the folder type as nfs:
```
```
config.vm.synced_folder ".", "/vagrant", type: "nfs"
```
```
#### RSync synced folders
These are the easiest to use as they usually work without any intervention on a Linux host. This is a one-way sync from host to guest performed at startup (**vagrant up**) or after a **vagrant reload** command is issued. The default share of the Vagrant project directory is done with rsync. To configure a synced folder with rsync, specify the type as rsync:
```
```
config.vm.synced_folder ".", "/vagrant", type: "rsync"
```
```
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/vagrant-beyond-basics/
作者:[Andy Mott][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/amott/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2020/11/vagrant_beyond_basics-816x345.png
[2]: https://unsplash.com/@kelli_mcclintock?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[3]: https://unsplash.com/s/photos/box?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[4]: https://fedoramagazine.org/vagrant-qemukvm-fedora-devops-sysadmin/

View File

@ -0,0 +1,95 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Why I love Emacs)
[#]: via: (https://opensource.com/article/20/12/emacs)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Why I love Emacs
======
Emacs isn't a mere text editor; it places you in control and allows you
to solve nearly any problem you encounter.
![Emoji keyboard][1]
I'm a habitual [Emacs][2] user. I didn't choose Emacs as much as it chose me. Back when I was first learning about Unix, I stumbled upon a little-known feature in a strange application called Emacs, which was apparently hidden away on my computer. Legend had it (and was proven true) that if you typed `emacs` into a terminal, pressed **Alt**+**X**, and typed `tetris`, you could play a falling-blocks game.
![Tetris in Emacs][3]
That was my introduction to GNU Emacs. While it was frivolous, it was also an accurate indication of what Emacs is all about—the idea that users can reprogram their (virtual) worlds and do _whatever_ they want with an application. Playing Tetris in your text editor is probably not your primary goal on an everyday basis, but it goes to show that Emacs is, proudly, a programming platform. In fact, you might think of it as a kind of precursor to [Jupyter][4], combining a powerful programming language (called `elisp`, to be exact) with its own live environment. As a consequence, Emacs is flexible as a text editor, customizable, and powerful.
Elisp (and Common Lisp, by extension) aren't necessarily the easiest languages to start out on, if you're used to Bash or Python or similar languages. But LISP dialects are powerful, and because Emacs is a LISP interpreter, you can build applications, whether they're Emacs plugins or prototypes of something you want to develop into a stand-alone project. The wildly popular [org-mode project][5] is just one example: it's an Emacs plugin as well as a markdown syntax with mobile apps to interpret and extend its capabilities. There are many examples of similarly useful applications-within-Emacs, including an email client, a PDF viewer, web browser, a shell, and a file manager.
### Two interfaces
GNU Emacs has at least two user interfaces: a graphical user interface (GUI) and a terminal user interface (TUI). This sometimes surprises people because Emacs is often pitted against Vi, which runs in a terminal (although gVim provides a GUI for a modern Vi implementation). If you want to run GNU Emacs as a terminal application, you can launch it with the `-nw` option:
```
`$ emacs -nw`
```
With a GUI, you can just launch Emacs from your application menu or a terminal.
You might think that a GUI renders Emacs less effective, as if "real text editors run in a terminal," but a GUI can make Emacs easier to learn because its GUI follows some typical conventions (a menu bar, adjustable widgets, mouse interaction, and so on).
In fact, if you run Emacs as a GUI application, you can probably get through the day without noticing you're in Emacs at all. Most of the usual conventions apply, as long as you use the GUI. For instance, you can select text with your mouse, navigate to the **Edit** menu, select **Copy**, and then place your cursor elsewhere and select **Paste**. To save a document, you can go to **File** and **Save** or **Save As**. You can press **Ctrl** and scroll up to make your screen font larger, you can use the scroll bar to navigate through your document, and so on.
Getting to know Emacs in its GUI form is a great way to flatten the learning curve.
### Emacs keyboard shortcuts
GNU Emacs is infamous for complex keyboard combinations. They're not only unfamiliar (**Alt**+**W** to copy? **Ctrl**+**Y** to paste?), they're also notated with arcane terminology ("Alt" is called "Meta"), and sometimes they come in pairs (**Ctrl**+**X** followed by **Ctrl**+**S** to save) and other times alone (**Ctrl**+**S** to search). Why would anyone willfully choose to use this?
Well, some don't. But those who do are fans of how these combinations easily flow into the rhythm of everyday typing (and often have the **Caps Lock** key serve as a **Ctrl** key). Those who prefer something different, however, have several options.
* The `evil` mode lets you use Vim keybindings in Emacs. It's that simple: You get to keep the key combinations you've committed to muscle memory, and you inherit the most powerful text editor available.
* Common User Access (CUA) keys keep all of the usual Emacs key combinations but the most jarring ones—copy, cut, paste, and undo—are all mapped to their modern bindings (**Ctrl**+**C**, **Ctrl**+**X**, **Ctrl**+**V**, and **Ctrl**+**Z**, respectively).
* The `global-set-key` function, part of the programming side of Emacs, allows you to define your own keyboard shortcuts. Traditionally, user-defined shortcuts start with **Ctrl**+**C**, but nothing is stopping you from inventing your own scheme. Emacs isn't precious of its own identity. You're welcome to bend it to your will.
### Learn Emacs
It takes time to get very good with Emacs. For me, that meant printing out a [cheat sheet][6] and keeping it next to my keyboard all day, every day. When I forgot a key combo, I looked it up on my cheat sheet. If it wasn't on my cheat sheet, I learned the keyboard combo, either by executing the function and noting how Emacs told me I could access it quicker or by using `describe-function`:
```
M-x describe-function: save-buffer
save-buffer is an interactive compiled Lisp function in files.el.
It is bound to C-x C-s, &lt;menu-bar&gt; &lt;file&gt; &lt;save-buffer&gt;.
[...]
```
As you use it, you learn it. And the more you learn about it, the more empowered you become to improve it and make it your own.
### Try Emacs
It's a common joke to say that Emacs is an operating system with a text editor included. Maybe that's meant to insinuate Emacs is bloated and overly complex, and there's certainly an argument that a text editor shouldn't require `libpoppler` according to its default configuration (you can compile Emacs without it).
But there's a greater truth lurking behind this joke, and it reveals a lot about what makes Emacs so fun. It doesn't make sense to compare Emacs to other text editors, like Vim, Nano, or even [VSCodium][7], because the really important part of Emacs isn't the idea that you can type stuff into a window and save it. That's basic functionality that even Bash provides. The true significance of Emacs is how it places you in control and how, through Emacs Lisp ([Elisp][8]), nearly any problem can be solved.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/12/emacs
作者:[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/emoji-keyboard.jpg?itok=JplrSZ9c (Emoji keyboard)
[2]: https://en.wikipedia.org/wiki/Emacs
[3]: https://opensource.com/sites/default/files/tetris.png (Tetris in Emacs)
[4]: https://opensource.com/article/20/11/surprising-jupyter
[5]: https://opensource.com/article/19/1/productivity-tool-org-mode
[6]: https://opensource.com/downloads/emacs-cheat-sheet
[7]: https://opensource.com/article/20/6/open-source-alternatives-vs-code
[8]: https://www.gnu.org/software/emacs/manual/html_node/elisp/

View File

@ -0,0 +1,104 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Watch Live TV on Linux With Hypnotix: A New IPTV Application Being Developed by Linux Mint Team)
[#]: via: (https://itsfoss.com/hypnotix-iptv-app/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
Watch Live TV on Linux With Hypnotix: A New IPTV Application Being Developed by Linux Mint Team
======
The rise of streaming services like [Netflix][1] made people speculate about the dim future of TV channels. While the newer generation might not watch TV anymore, TV channels are not out of fashion, yet.
Many streaming services like [Hulu][2] and Hotstar include TV channels in their offering. TV channels are also utilizing live streaming to broadcast their content to viewers on the internet.
Another way to watch live TV is by using IPTV. There are a number of TV channels available via IPTV so that viewers can use internet to watch the live broadcast. Some channels are available for free while some might require subscription.
There have been a few [applications on Linux to watch IPTV channels but most have been discontinued][3]. Linux Mint team [announced][4] that they are working on a new app that will allow you to watch TV channels via IPTV on your Linux system.
### Hypnotix: New IPTV application under development
![][5]
[Hypnotix][6] is an IPTV streaming application with support for live TV, movies and series. It supports IPTV providers using M3U URL, Xtream API or [local M3U playlist][7].
If none of the above make sense to you, dont worry. Hypnotix comes with FreeIPTV preconfigured. [FreeIPTV][8] is a project that has M3U for over 2,000 TV channels that are legally free to watch.
Which means that you can get a huge list of freely available TV channels from all over the world.
![][9]
You can click on the country or region of your choice. It will show you the list of channels in the left sidebar. Clicking on a channel will start playing the content in the right sidebar.
![][10]
You can also go full screen with F or F11 keyboard shortcut or use the button in the application.
There is also provision to handle VOD (Video on Demand) library but I couldnt figure out a way to use it.
Here are a few things to keep in mind:
* Viewing experience depends on your internet speed and the TV channels servers.
* Some TV channels might not work even if they are listed in the application.
* You may go back a few seconds or minutes but this depends upon the cache.
* You may also pause the live streaming and it will maintain a cache so that you can resume later. I dont know how big the cache could be.
* There is no way to control the video streaming quality as you do on YouTube and other video streaming websites.
* You wont get running programs detail in the player.
* This is TV broadcast so you get to see the same ads that are broadcasted during program breaks.
![Streaming is cached][11]
### Installing Hypnotix on Linux
_**Hypnotix is still in beta phase of development**_. The .deb file for the beta version is available for testing. On Ubuntu and Debian-based distributions, you can [install it from the DEB file][12].
[Download .DEB file for Hypnotix (Beta Version)][13]
At the time of writing this article, no other package is available for Hypnotix. This means Fedora and Arch users will have to wait.
### More features to come
Linux Mint development team plans to add more features in the future:
* EPG support (Live TV Program)
* PVR: pausing, time-shifting, recording, etc.
* Custom categories: To list channels in appropriate categories
* Favorites: so that you dont have to search for your favorite channels all the time.
* Hiding unused content
I like Linux Mint team. Unlike many other distributions, they are not just Ubuntu or Arch repackages with different theme and wallpapers. They put effort in developing not only the distribution but also applications like Hypnotix, Warpinator etc for their users. Other distribution maintainers should learn from Mint team.
Hypnotix provides a way to watch the IPTV channels with a simple and easy to use interface. Personally, I dont watch TV but I know many people do. Are you one of them? If yes, do you look forward to using it? Do share your views in the comment section.
--------------------------------------------------------------------------------
via: https://itsfoss.com/hypnotix-iptv-app/
作者:[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://www.netflix.com/
[2]: https://www.hulu.com/
[3]: https://itsfoss.com/watch-tv-channels-on-ubuntu-or-linux-mint/
[4]: https://blog.linuxmint.com/?p=3983
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/Hypnotix-iptv-app-linux-mint.png?resize=800%2C464&ssl=1
[6]: https://github.com/linuxmint/hypnotix
[7]: https://itsfoss.com/create-m3u-playlist-linux/
[8]: https://github.com/Free-IPTV/Countries
[9]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/Hypnotix-free-tv-channel-lists.png?resize=800%2C441&ssl=1
[10]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/12/live-tv-linux.png?resize=910%2C528&ssl=1
[11]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/12/hypnotix-cache.jpg?resize=800%2C444&ssl=1
[12]: https://itsfoss.com/install-deb-files-ubuntu/
[13]: https://github.com/linuxmint/hypnotix/releases

View File

@ -0,0 +1,103 @@
[#]: collector: (lujun9972)
[#]: translator: (robsean)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Dual booting Windows and Linux using UEFI)
[#]: via: (https://opensource.com/article/19/5/dual-booting-windows-linux-uefi)
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdoss/users/ckrzen)
使用 UEFI 双启动 Windows 和 Linux
======
在同一台机器上设置 Linux 和 Windows 双重启动的一份速成解释使用统一可扩展固件接口UEFI
![键盘上的 Linux 的按键字母][1]
我将强调一些重要点,而不是一步一步地指导你来如何配置你的系统以实现双重启动。作为一个示例,我将提到我在几个月之前新买的笔记本计算机。我首先安装 [Ubuntu Linux][2] 到整个硬盘中,这就摧毁了预装的 [Windows 10][3] 安装。几个月后,我决定安装一个不同的 Linux 发行版,也决定在双重启动配置中与 [Fedora Linux][4] 一起重新安装 Windows 10 。我将强调一些极其重要的实际情况。让我们开始吧!
### 固件
双重启动不仅仅是软件问题。或者说它算是软件的问题, 因为它需要更改你的固件,以告诉你的机器如何开始启动程序。这里有一些和固件相关的重要议题要铭记于心。
#### UEFI vs BIOS
在尝试安装前,确保你的固件配置是最佳的。现在出售的大多数计算机有一个名为 [统一可扩展固件接口 UEFI][5] 的新固件类型UEFI 差不多取代了另一个名为 [基本输入输出系统 (BIOS)][6] 的固件类型,(包括很多固件供应商在内的很多人)通常称 BIOS 为传统启动模式。
我不需要 BIOS ,使用我选择了 UEFI 模式。
#### 安全启动
另一个重要的设置是安全启动。这个功能将检测启动路径是否被篡改,并阻止未经批准的操作系统的启动。现在,我禁用这个选项来确保我能够安装 Fedora Linux 。依据 Fedora 项目维基 [功能/安全启动][7] 的介绍可知Fedora Linux 在安全启动选项启用的时候也可以工作。这对其它的 Linux 发行版来说可能有所不同 — 我打算今后重新研究这项设置。
简而言之,如果你发现在这项设置启用时你不能安装你的 Linux 操作系统,那么禁用安全启动并再次重新尝试安装。
### 分区启动驱动器
如果你选择双重启动并且两个操作相同都在同一个驱动器上,那么你必须将你分成多个分区。即使你使用两个不同的驱动器进行双重启动,出于各种各样的原因,大多数 Linux 安装也最好分成几个基本的分区。这里有一些选项值得考虑。
#### GPT vs MBR
如果你决定手动分区你的启动驱动器,在动手前,我建议使用 [GUID 分区表 (GPT)][8] ,而不是使用旧的 [主启动记录 (MBR)][9] 。这种更改的原因之一是MBR 有两个特定的限制,而 GPT 却没有:
* MBR 可以最多拥有 15 个分区,而 GPT 可以最多拥有 128 个分区。
* MBR 最多仅支持 2 TB ,而 GPT 使用 64 位地址,这使得它最多支持 800 万 TB 的磁盘。
如果你最近购买过硬盘,那么你可能会知道现代的很多硬盘都超过了 2 TB 的限制。
#### EFI 系统分区
I如果你正在进行一次全新的安装或使用一块新的驱动器那么这里可能没有可以开始的分区。在这种情况下操作系统安装程序将先创建一个分区即 [EFI 系统分区 (ESP)][10] 。如果你选择使用一个诸如 [gdisk][11] 之类的工具来手动分区你的驱动器,你将需要使用一些参数来创建这个分区。基于现有的 ESP ,我设置它为约 500 MB 的大小,并分配它为 ef00 EFI 系统 分区类型。UEFI 规范要求格式为 FAT32/msdos ,很可能是因为这种格式被大量的操作系统所支持。
![分区][12]
### 操作系统安装
在你完成先前的两个任务后,你就可以安装你的操作系统了。虽然我在这里关注的是 Windows 10 和 Fedora Linux ,当安装其它组合时的过程也是非常相似。
#### Windows 10
我开始 Windows 10 的安装,并创建了一个 20 GB的 Windows 分区。因为我先前在我的笔记本计算机上安装了 Linux ,所以驱动器已经有了一个 ESP ,我选择保留它。我删除所有的现有 Linux 和 swap 分区来开始 fresh ,然后开始我的 Windows 安装。Windows 安装程序自动创建另一个小分区—16 MB—称为 [Microsoft 保留分区 (MSR)][13] 。在这完成后,在 512 GB 启动分区上仍然有大约 400 GB 的b未分配空间。
接下来,我继续完成了 Windows 10 安装过程。随后我重新启动到 Windows 来确保它是工作的,在操作系统第一次启动时,创建我的用户账号,设置 wi-fi ,并完成其它必须的任务。
#### Fedora Linux
接下来,我将心思转移到安装 Linux 。当安装重新到到磁盘配置的步骤时,我开始了这个过程,我确保不更改 Windows 的 NTFS 和 MSR 分区。我也不更改 EPS ,但是我设置它的挂载点位 **/boot/efi** 。然后我创建常用的 ext4 格式分区, **/** (root) **/boot** ,和 **/home** 。我创建的最后一个分区是 Linux 的 **swap**
像安装 Windows 一样,我继续完成了 Linux 安装,随后重新启动。令我高兴的是,在启动时 [GRand][14] [统一启动加载程序 (GRUB)][14] 菜单提供选择 Windows 或 Linux 的选项,这意味着我不需要再做任何额外的配置。我选择 Linux 并完成了诸如创建我的用户账号等常规步骤。
### 总结
总体而言,这个过程是不难的,在过去的几年里,从 UEFI 到 BIOS 有一些不同的成功克服困难的更改,加上诸如安全启动等功能的引入。我相信我们现在已经克服了这些障碍,可以可靠地设置多重启动系统。
我不再怀念 [Linux LOader (LILO)][15]
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/5/dual-booting-windows-linux-uefi
作者:[Alan Formy-Duval][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/alanfdoss/users/ckrzen
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/linux_keyboard_desktop.png?itok=I2nGw78_ (Linux keys on the keyboard for a desktop computer)
[2]: https://www.ubuntu.com
[3]: https://www.microsoft.com/en-us/windows
[4]: https://getfedora.org
[5]: https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface
[6]: https://en.wikipedia.org/wiki/BIOS
[7]: https://fedoraproject.org/wiki/Features/SecureBoot
[8]: https://en.wikipedia.org/wiki/GUID_Partition_Table
[9]: https://en.wikipedia.org/wiki/Master_boot_record
[10]: https://en.wikipedia.org/wiki/EFI_system_partition
[11]: https://sourceforge.net/projects/gptfdisk/
[12]: /sites/default/files/u216961/gdisk_screenshot_s.png
[13]: https://en.wikipedia.org/wiki/Microsoft_Reserved_Partition
[14]: https://en.wikipedia.org/wiki/GNU_GRUB
[15]: https://en.wikipedia.org/wiki/LILO_(boot_loader)

View File

@ -0,0 +1,115 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: (wxy)
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Day 2: Rails associations & dragging divs around)
[#]: via: (https://jvns.ca/blog/2020/11/10/day-2--rails-associations---dragging-divs-around/)
[#]: author: (Julia Evans https://jvns.ca/)
Rails 之旅第 2 天Rails 关联和拖动 div
======
大家好!今天是我搭建这个玩具项目的第 2 天。下面再来记录一下关于 Rails 的一些有趣的事情吧!
### 目标:做一个冰箱诗歌论坛
我想做一种无聊的标准网站来学习 Rails并且其他人可以与之互动就像一个论坛一样! 但如果人们真的可以在网站上打字,那就会产生各种各样的问题(如果他们是垃圾邮件发送者怎么办?又或者只是言语刻薄?)。
我想到的第一个想法是,可以让人们与网站互动,但实际上却不能在网站上打字,那就是一个“冰箱诗歌论坛”,只给你一组固定的字,你就可以随意组合。
所以,这就是我们的计划!
我这个项目的目标是想知道我是否能用 Rails 来做其他的小型网络项目(而不是像我通常做的那样,使用一些更基本的东西,比如 Flask或者放弃后端用 Javascript 来写所有东西)。
### 怎么把字拖来拖去呢jQuery 的可拖放 UI
我想让大家能够把文字拖动起来,但我又不想写很多 Javascript。结果发现这超级简单 —— 有一个 jQuery 库可以做到,它叫做 `draggable`!一开始,拖动并不成功。
一开始拖动在手机上是不行的,但是有一个技巧可以让 jQuery UI 在手机上工作,叫做 [jQuery UI touch punch][1]。下面是它的样子(有兴趣看工作原理的可以查看源码,代码很少)。
> `banana` `forest` `cake` `is`
### 一个有趣的 Rails 功能:关联
我以前从来没有使用过关系型 ORM对于 Rails我很兴奋的一件事就是想看看使用 Active Record 是什么样子的!今天我了解了 Rails 的 ORM 功能之一:[关联][2]。如果你像我一样对 ORM 完全不了解的话,那就来看看是怎么回事吧。
在我的论坛中,我有:
* 用户
* 话题(我本来想把它叫做“线索”,但显然这在 Rails 中是一个保留词,所以现在叫做“话题”)。
* 帖子
当显示一个帖子时,我需要显示创建该帖子的用户的用户名。所以我想我可能需要写一些代码来加载帖子,并为每个帖子加载用户,就像这样(在 Rails 中,`Post.where` 和 `User.find` 将会运行 SQL 语句,并将结果转化为 Ruby 对象):
```
@posts = Post.where(topic_id: id)
@posts.each do |post|
user = User.find(post.user_id)
post.user = user
end
```
这还不够好,它要为每个帖子做一次单独的 SQL 查询!我知道有一个更好的方法,我发现它叫做[关联][2]。这个链接是来自 <https://guides.rubyonrails.org> 的指南,到目前为止,它对我很有帮助。
基本上我需要做的就是:
1. 在 `User` 模型中添加一行 `has_many :post`
2. 在 `Post` 模型中添加一行 `belongs_to :user`
3. Rails 现在知道如何将这两个表连接起来,尽管我没有告诉它要连接到什么列上!我认为这是因为我按照它所期望的惯例命名了 `posts` 表中的 `user_id` 列。
4. 对 `User``Topic` 做完全相同的事情(一个主题也有很多帖子:`has_many :posts`)。
然后我加载每一个帖子和它的关联用户的代码就变成了只有一行! 就是这一行:
```
@posts = @topic.posts.order(created_at: :asc).preload(:user)
```
比起只有一行更重要的是,它不是单独做一个查询来获取每个帖子的用户,而是在 1 个查询中获取所有用户。显然,在 Rails 中,有一堆[不同的方法][3]来做类似的事情(预加载、急切加载、联接和包含?),我还不知道这些都是什么,但也许我以后会知道的。
### 一个有趣的 Rails 功能:脚手架!
Rails 有一个叫 `rails` 的命令行工具,它可以生成很多代码。例如,我想添加一个 `Topic` 模型/控制器。我不用去想在哪里添加所有的代码,可以直接运行
```
rails generate scaffold Topic title:text
```
并生成了一堆代码,这样我已经有了基本的端点来创建/编辑/删除主题(`Topic`)。例如,这是我的[现在的主题控制器][4],其中大部分我没有写(我只写了高亮的 3 行)。我可能会删除很多内容,但是有一个起点,让我可以扩展我想要的部分,删除我不想要的部分,感觉还不错。
### 数据库迁移!
`rails` 工具还可以生成数据库迁移! 例如,我决定要删除帖子中的 `title` 字段。
下面是我要做的:
```
rails generate migration RemoveTitleFromPosts title:string
rails db:migrate
```
就是这样 —— 只要运行几个命令行咒语就可以了! 我运行了几个这样的迁移,因为我改变了对我的数据库模式的设想。它是相当直接的,到目前为止 —— 感觉很神奇。
当我试图在一列中的某些字段为空的地方添加一个“不为空”(`not null`)约束时,情况就变得有点有趣了 —— 迁移失败。但我可以修复违例的记录,并轻松地重新运行迁移。
### 今天就到这里吧!
明天,如果我有更多的进展,也许我会把它放在互联网上。
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2020/11/10/day-2--rails-associations---dragging-divs-around/
作者:[Julia Evans][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lujun9972
[1]: https://github.com/furf/jquery-ui-touch-punch
[2]: https://guides.rubyonrails.org/association_basics.html
[3]: https://blog.bigbinary.com/2013/07/01/preload-vs-eager-load-vs-joins-vs-includes.html
[4]: https://github.com/jvns/refrigerator-forum/blob/776b3227cfd7004cb1efb00ec7e3f82a511cbdc4/app/controllers/topics_controller.rb#L13-L15

View File

@ -0,0 +1,102 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Keep track of multiple Git remote repositories)
[#]: via: (https://opensource.com/article/20/11/multiple-git-repositories)
[#]: author: (Peter Portante https://opensource.com/users/portante)
跟踪多个 Git 远程仓库
======
拥有一致的命名标准是保持本地和上游 Git 仓库保持直线的关键。
![Digital hand surrounding by objects, bike, light bulb, graphs][1]
当本地 Git 仓库的名称与远程仓库不一致时,与远程仓库协作就会变得很混乱。
解决此问题的一个方法是标准化两个词的使用和含义:`origin` 指的是你个人的 `example.com/<USER>/*` 仓库,而 `upstream` 指的是你从 `origin` 仓库分叉出来的 `example.com` 仓库。换句话说,`upstream` 指的是公开提交工作的上游仓库,而 `origin` 指的是你在上游仓库的本地分叉,例如,你从那里生成拉取请求 PR
以 [pbench][2] 仓库为例,下面是一个逐步建立新的本地克隆的方法,其中 `origin``upstream` 的定义是一致的。
1. 在大多数 Git 托管服务上,当你想在上面工作时,必须对它进行分叉。当你运行自己的 Git 服务器时,这并不是必要的,但对于一个公开的代码库来说,这是一个在贡献者之间传输差异的简单方法。
创建一个 Git 仓库的分叉。在这个例子中,假设你的分叉位于 `example.com/<USER>/pbench`
2. 接下来,你必须获得一个统一资源标识符 [URI][3]),以便通过 SSH 进行克隆。在大多数 Git 托管服务上,比如 GitLab 或 GitHub它在一个标有 **Clone****Clone over SSH** 的按钮或面板上。将克隆 URI 复制到剪贴板中。
3. 在你的开发系统中,使用你复制的文本克隆仓库:
```
`$ git clone git@example.com:<USER>/pbench.git`
```
这将克隆 Git 仓库,默认名称为 `origin`,作为 pbench 仓库的分叉副本。
4. 切换到刚才克隆的目录:
```
`$ cd ~/pbench`
```
5. 下一步,获取源码仓库的 SSH URI你最初分叉的那个。这可能和上面的方法一样。找到 **Clone** 按钮或面板,复制克隆地址。在软件开发中,这通常被称为“上游”,因为(理论上)这是大多数提交发生的地方,而你打算让这些提交流向下游的仓库。
6. 将 URI 添加到你的本地仓库中。是的将有_两个不同_的远程分配给你的本地仓库副本
```
`$ git remote add upstream \ git@example.com:bigproject/pbench.git`
```
7. 现在你有两个命名远程仓库:`origin` 和 `upstream`。 你可以用远程子命令查看你的远程仓库:
```
`$ git remote -v`
```
现在,你的本地 `master` 分支正在跟踪 `origin` master这不一定是你想要的。你可能想跟踪这个分支的 `upstream` 版本,因为大多数开发都在上游进行。 这个想法是,你要在从上游获得的内容的基础上添加更改。
8. 将你的本地的 master 分支改成跟踪 `upstream/master`
```
$ git fetch upstream
$ git branch --set-upstream-to=upstream/master master
```
你可以对任何你想要的分支这样做,而不仅仅是 `master`。例如,有些项目使用 `dev` 分支来处理所有不稳定的变化,而将 `master` 保留给已批准发布的代码。
9. 一旦你设置了你的跟踪分支,一定要 `rebase` 你的 master 分支,使它与上游仓库的任何新变化保持一致:
```
$ git remote update
$ git checkout master
$ git rebase
```
这是一个保持 Git 仓库在不同分叉之间同步的好方法。如果你想自动完成这项工作,请阅读 Seth Kenlon 关于[使用 Ansible 托管 Git 仓库][4]的文章。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/11/multiple-git-repositories
作者:[Peter Portante][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://opensource.com/users/portante
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003588_01_rd3os.combacktoschoolseriesk12_rh_021x_0.png?itok=fvorN0e- (Digital hand surrounding by objects, bike, light bulb, graphs)
[2]: https://github.com/distributed-system-analysis/pbench
[3]: https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
[4]: https://opensource.com/article/19/11/how-host-github-gitlab-ansible