<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Centos &#8211; wqh博客</title>
	<atom:link href="https://wangqianhong.com/tag/centos/feed/" rel="self" type="application/rss+xml" />
	<link>https://wangqianhong.com</link>
	<description>和而不同</description>
	<lastBuildDate>Sat, 14 Sep 2024 07:45:15 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wangqianhong.com/wp-content/uploads/2020/09/cropped-1-1-1-32x32.png</url>
	<title>Centos &#8211; wqh博客</title>
	<link>https://wangqianhong.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>mkcert 自签名证书</title>
		<link>https://wangqianhong.com/2022/08/mkcert-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/</link>
					<comments>https://wangqianhong.com/2022/08/mkcert-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Fri, 05 Aug 2022 08:07:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=3226</guid>

					<description><![CDATA[<p>在本地开发中，有时候经常需要模拟https环境，以前这些步骤需要一系列繁琐的openssl命令生成，&#8230; <a href="https://wangqianhong.com/2022/08/mkcert-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">mkcert 自签名证书</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/08/mkcert-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/">mkcert 自签名证书</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>在本地开发中，有时候经常需要模拟https环境，以前这些步骤需要一系列繁琐的<code>openssl</code>命令生成，尽管有脚本化的方案帮助简化输入这些命令。但是仍然觉得对本地开发不那么友好，有些繁重了。</p>



<p>本文将介绍一种更加简单友好的方式生成本地https证书，并且信任自签CA的方案——<a href="https://github.com/FiloSottile/mkcert" target="_blank" rel="noreferrer noopener">mkcert</a>。</p>



<h3>安装</h3>



<p>先安装certutil：</p>



<pre class="wp-block-code"><code>yum install nss-tools</code></pre>



<p>再安装mkcert：</p>



<pre class="wp-block-preformatted"><code>curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64"</code>
<code>chmod +x mkcert-v1.4.4-linux-amd64</code>
<code>mv mkcert-v1.4.4-linux-amd64 /usr/local/bin/mkcert</code></pre>



<p>运行mkcert，看到下面内容就表示安装成功：</p>



<pre class="wp-block-preformatted">Usage of mkcert:

$ mkcert -install
Install the local CA in the system trust store.

$ mkcert example.org
Generate "example.org.pem" and "example.org-key.pem".

$ mkcert example.com myapp.dev localhost 127.0.0.1 ::1
Generate "example.com+4.pem" and "example.com+4-key.pem".

$ mkcert "*.example.it"
Generate "_wildcard.example.it.pem" and "_wildcard.example.it-key.pem".

$ mkcert -uninstall
Uninstall the local CA (but do not delete it).</pre>



<p>使用install将mkcert使用的根证书加入了本地可信CA中，以后由该CA签发的证书在本地都是可信的。</p>



<pre class="wp-block-preformatted"><code>mkcert -install</code>
Created a new local CA 💥
The local CA is now installed in the system trust store! ⚡️
The local CA is now installed in the Firefox and/or Chrome/Chromium trust store (requires browser restart)! 🦊</pre>



<h3>生成证书</h3>



<pre class="wp-block-preformatted"><code>mkcert -key-file localhost.key -cert-file localhost.cert localhost 127.0.0.1 ::1</code>

Note: the local CA is not installed in the system trust store.
Note: the local CA is not installed in the Firefox and/or Chrome/Chromium trust store.
Run "mkcert -install" for certificates to be trusted automatically ⚠️

Created a new certificate valid for the following names 📜
- "localhost"
- "127.0.0.1"
- "::1"

The certificate is at "localhost.cert" and the key at "localhost.key" ✅

It will expire on 27 September 2026 🗓</pre>



<p>可以看到生成了localhost.key和localhost.cert，直接在server中使用就可以了</p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/08/mkcert-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/">mkcert 自签名证书</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2022/08/mkcert-%e8%87%aa%e7%ad%be%e5%90%8d%e8%af%81%e4%b9%a6/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Docker运行MongoDB</title>
		<link>https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/</link>
					<comments>https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Sat, 19 Feb 2022 05:31:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[MongoDB]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=2841</guid>

					<description><![CDATA[<p>MongoDB是NoSQL类型的数据库。它支持的数据结构非常松散，是类似json的bson格式，因此&#8230; <a href="https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Docker运行MongoDB</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/">Docker运行MongoDB</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>MongoDB是NoSQL类型的数据库。它支持的数据结构非常松散，是类似json的bson格式，因此可以存储比较复杂的数据类型。</p>



<h3>拉取镜像</h3>



<pre class="wp-block-code"><code>docker pull mongodb/mongodb-community-server</code></pre>



<h3>配置文件</h3>



<p>创建文件<code>/mnt/mongodb/mongo.conf</code></p>



<pre class="wp-block-preformatted"><code>systemLog:
  destination: file
  path: /var/log/mongodb/mongod.log
  logAppend: true
storage:
  dbPath: /data/db
net:
  port: 27017
  bindIp: 0.0.0.0
security:
  authorization: enabled</code>

systemLog 写入日志文件的地址是容器中的路径
storage 数据库目录是容器中的路径
net 指定容器mongodb启动监听27017端口, 0.0.0.0 是为了让宿主机可以访问容器的mongodb服务
security 开启账号密码登录验证方式</pre>



<h3>运行镜像</h3>



<pre class="wp-block-code"><code>docker run --name mongodb -p 27017:27017 -e TZ=Asia/Shanghai -v /mnt/mongodb/mongo.conf:/etc/conf/mongo.conf -v /data/mongodb:/data -d mongodb/mongodb-community-server:latest -f /etc/conf/mongo.conf</code></pre>



<h3>新增账号</h3>



<pre class="wp-block-code"><code> docker exec -it mongo mongosh</code></pre>



<p>切换的admin</p>



<pre class="wp-block-preformatted">test&gt; <code>use admin</code>
switched to db admin
admin&gt; <code>db.createUser({user:"账号",pwd:"密码",roles:["root"]})</code>
{ ok: 1 }</pre>



<p>验证账号</p>



<pre class="wp-block-preformatted">admin&gt; <code>db.auth("账号","密码")</code>
{ ok: 1 }</pre>



<p></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/">Docker运行MongoDB</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Docker如何增加端口映射</title>
		<link>https://wangqianhong.com/2022/01/%e5%9c%a8linux%e4%b8%8b%e7%9a%84docker%e5%a6%82%e4%bd%95%e5%a2%9e%e5%8a%a0%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84/</link>
					<comments>https://wangqianhong.com/2022/01/%e5%9c%a8linux%e4%b8%8b%e7%9a%84docker%e5%a6%82%e4%bd%95%e5%a2%9e%e5%8a%a0%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Fri, 28 Jan 2022 11:04:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<category><![CDATA[Docker]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=2807</guid>

					<description><![CDATA[<p>docker容器在运行时，有时候需要新增容器的端口映射 Linux环境 首先找出容器ID，使用命令d&#8230; <a href="https://wangqianhong.com/2022/01/%e5%9c%a8linux%e4%b8%8b%e7%9a%84docker%e5%a6%82%e4%bd%95%e5%a2%9e%e5%8a%a0%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Docker如何增加端口映射</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/01/%e5%9c%a8linux%e4%b8%8b%e7%9a%84docker%e5%a6%82%e4%bd%95%e5%a2%9e%e5%8a%a0%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84/">Docker如何增加端口映射</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>docker容器在运行时，有时候需要新增容器的端口映射</p>



<h3>Linux环境</h3>



<p>首先找出容器ID，使用命令<code>docker ps -a</code></p>



<p>找到容器的ID，这里是b7cf937a67e857aa04a120e172b79d152d5946b93f2851068cdaa4c054cd4941 然后找到config.v2.json配置文件</p>



<pre class="wp-block-code"><code>/var/lib/docker/containers/b7cf937a67e857aa04a120e172b79d152d5946b93f2851068cdaa4c054cd4941/config.v2.json</code></pre>



<p id="block-c3728f70-c84b-469f-a38f-a69ddb0d6e5c">在ExposedPorts下面新增<code>"9848/tcp":{},"9849/tcp":{}</code>，9848和9849就是新增的服务器端口</p>



<p>&#8220;ExposedPorts&#8221;:{&#8230;&#8230;<code>"9848/tcp":{},"9849/tcp":{</code>}}</p>



<p>  最后修改hostconfig.json配置文件</p>



<pre class="wp-block-code"><code>/var/lib/docker/containers/b7cf937a67e857aa04a120e172b79d152d5946b93f2851068cdaa4c054cd4941/hostconfig.json</code></pre>



<p> 在PortBindings下面新增<code>"9848/tcp":[{"HostIp":"","HostPort":"11006"}],"9849/tcp":[{"HostIp":"","HostPort":"11007"}]</code></p>



<p>9848和9849就是新增的服务器端口，11006和11007就是映射出来的端口 </p>



<pre class="wp-block-preformatted">"PortBindings":{......"9848/tcp":[{"HostIp":"","HostPort":"11006"}],"9849/tcp":[{"HostIp":"","HostPort":"11007"}] }</pre>



<p>修改完之后，重启docker</p>



<pre class="wp-block-code"><code>systemctl restart docker</code></pre>



<h3>Windows环境</h3>



<p>找到配置文件路径</p>



<pre class="wp-block-code"><code>\\wsl.localhost\docker-desktop-data\data\docker\containers\</code></pre>



<p>其它操作和linux下面是一样的</p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/01/%e5%9c%a8linux%e4%b8%8b%e7%9a%84docker%e5%a6%82%e4%bd%95%e5%a2%9e%e5%8a%a0%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84/">Docker如何增加端口映射</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2022/01/%e5%9c%a8linux%e4%b8%8b%e7%9a%84docker%e5%a6%82%e4%bd%95%e5%a2%9e%e5%8a%a0%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Centos安装TypeScript环境</title>
		<link>https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85typescript%e7%8e%af%e5%a2%83/</link>
					<comments>https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85typescript%e7%8e%af%e5%a2%83/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Sat, 15 Jan 2022 02:26:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<category><![CDATA[Node.js]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=2733</guid>

					<description><![CDATA[<p>在安装TypeScript之前，需要先安装NodeJs，可以参考下面的网站进行安装 接下来使用npm&#8230; <a href="https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85typescript%e7%8e%af%e5%a2%83/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Centos安装TypeScript环境</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85typescript%e7%8e%af%e5%a2%83/">Centos安装TypeScript环境</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>在安装TypeScript之前，需要先安装NodeJs，可以参考下面的网站进行安装</p>



<figure class="wp-block-embed-wordpress wp-block-embed is-type-wp-embed is-provider-wqh博客"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="MHweV80YWI"><a href="https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85nodejs%e7%a8%b3%e5%ae%9a%e7%89%88lts/">Centos安装nodejs稳定版(LTS)</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" title="《Centos安装nodejs稳定版(LTS)》—wqh博客" src="https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85nodejs%e7%a8%b3%e5%ae%9a%e7%89%88lts/embed/#?secret=MHweV80YWI" data-secret="MHweV80YWI" width="500" height="282" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



<p>接下来使用npm安装</p>



<pre class="wp-block-preformatted"><code>npm install -g typescript</code>

added 1 package, and audited 2 packages in 10s
found <strong>0</strong> vulnerabilities</pre>



<p>使用下面命令验证是否安装成功</p>



<pre class="wp-block-preformatted"><code>tsc --version</code>

Version 5.0.4

<code>tsc --help</code>

tsc: The TypeScript Compiler - Version 5.0.4
TS
<strong>COMMON COMMANDS</strong>

tsc
Compiles the current project (tsconfig.json in the working directory.)

tsc app.ts util.ts
Ignoring tsconfig.json, compiles the specified files with default compiler options.

tsc -b
Build a composite project in the working directory.

tsc --init
Creates a tsconfig.json with the recommended settings in the working directory.

tsc -p ./path/to/tsconfig.json
Compiles the TypeScript project located at the specified path.

tsc --help --all
An expanded version of this information, showing all possible compiler options

tsc --noEmit
tsc --target esnext
Compiles the current project, with additional settings.

<strong>COMMAND LINE FLAGS</strong>

--help, -h Print this message.

--watch, -w Watch input files.

--all Show all compiler options.

--version, -v Print the compiler's version.

--init Initializes a TypeScript project and creates a tsconfig.json file.

--project, -p Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.

--build, -b Build one or more projects and their dependencies, if out of date

--showConfig Print the final configuration instead of building.

<strong>COMMON COMPILER OPTIONS</strong>

--pretty Enable color and formatting in TypeScript's output to make compiler errors easier to read.
type: boolean
default: true

--declaration, -d Generate .d.ts files from TypeScript and JavaScript files in your project.
type: boolean
default: `false`, unless `composite` is set

--declarationMap Create sourcemaps for d.ts files.
type: boolean
default: false

--emitDeclarationOnly Only output d.ts files and not JavaScript files.
type: boolean
default: false

--sourceMap Create source map files for emitted JavaScript files.
type: boolean
default: false

--target, -t Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
one of: es3, es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext
default: es5

--module, -m Specify what module code is generated.
one of: none, commonjs, amd, umd, system, es6/es2015, es2020, es2022, esnext, node16, nodenext
default: undefined

--lib Specify a set of bundled library declaration files that describe the target runtime environment.
one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, esnext, dom, dom.iterable, webworker, webworker.importscript
s, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflec
t, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarra
ys, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es
2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.stri
ng, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl
, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.sharedmemory, es2022.string/esnext.string, es2022.regexp, es2023.array/esnext.ar
ray, esnext.intl, decorators, decorators.legacy
default: undefined

--allowJs Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files.
type: boolean
default: false

--checkJs Enable error reporting in type-checked JavaScript files.
type: boolean
default: false

--jsx Specify what JSX code is generated.
one of: preserve, react, react-native, react-jsx, react-jsxdev
default: undefined

--outFile Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output.

--outDir Specify an output folder for all emitted files.

--removeComments Disable emitting comments.
type: boolean
default: false

--noEmit Disable emitting files from a compilation.
type: boolean
default: false

--strict Enable all strict type-checking options.
type: boolean
default: false

--types Specify type package names to be included without being referenced in a source file.

--esModuleInterop Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility.
type: boolean
default: false

You can learn about all of the compiler options at https://aka.ms/tsc</pre>



<p></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85typescript%e7%8e%af%e5%a2%83/">Centos安装TypeScript环境</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85typescript%e7%8e%af%e5%a2%83/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Centos安装nodejs稳定版(LTS)</title>
		<link>https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85nodejs%e7%a8%b3%e5%ae%9a%e7%89%88lts/</link>
					<comments>https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85nodejs%e7%a8%b3%e5%ae%9a%e7%89%88lts/#comments</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Fri, 07 Jan 2022 02:13:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<category><![CDATA[Node.js]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=2731</guid>

					<description><![CDATA[<p>查看可用的nodejs dnf module list nodejs CentOS Linux 8 &#8230; <a href="https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85nodejs%e7%a8%b3%e5%ae%9a%e7%89%88lts/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Centos安装nodejs稳定版(LTS)</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85nodejs%e7%a8%b3%e5%ae%9a%e7%89%88lts/">Centos安装nodejs稳定版(LTS)</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<h3>查看可用的nodejs</h3>



<pre class="wp-block-preformatted"><code>dnf module list nodejs</code>

<strong>CentOS Linux 8 - AppStream</strong>
Name Stream Profiles Summary
nodejs 10 [d] common [d], development, minimal, s2i Javascript runtime
nodejs 12 common [d], development, minimal, s2i Javascript runtime
nodejs 14 common [d], development, minimal, s2i Javascript runtime
nodejs 16 common [d], development, minimal, s2i Javascript runtime

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled</pre>



<p>可以看到一个有4个版本，分别是10、12、14和16，这里选择切换到最新的16版本</p>



<pre class="wp-block-code"><code>dnf module enable nodejs:16</code></pre>



<h3>命令安装</h3>



<p>切换到16版本，然后使用下面命令安装即可：</p>



<pre class="wp-block-code"><code>dnf install nodejs</code></pre>



<p>等待安装完成之后 ，使用下面命令验证安装是否成功：</p>



<pre class="wp-block-preformatted"><code>node --version</code>
v16.13.1</pre>



<p>如果想安装其他版本，可以使用下面命令进行安装</p>



<pre class="wp-block-code"><code>curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -</code></pre>



<p>等repo更新完成，直接安装即可</p>



<pre class="wp-block-code"><code>yum install nodejs</code></pre>



<h3>修改国内镜像</h3>



<pre class="wp-block-code"><code>npm config set registry https://registry.npmmirror.com</code></pre>



<p>验证命令</p>



<pre class="wp-block-code"><code>npm config get registry</code></pre>



<p>如果返回https://registry.npmmirror.com，说明镜像配置成功。</p>



<h3>安装yarn</h3>



<p>Yarn 是为了弥补 npm 的一些缺陷而出现的：</p>



<p>npm 安装包（packages）的速度不够快，拉取的 packages 可能版本不同</p>



<p>npm 允许在安装 packages 时执行代码，这就埋下了安全隐患</p>



<pre class="wp-block-code"><code>npm install --global yarn</code></pre>



<h3>卸载nodejs</h3>



<pre class="wp-block-code"><code>yum remove nodejs &amp;&amp; rm -r /etc/yum.repos.d/nodesource*.repo &amp;&amp; yum clean all</code></pre>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85nodejs%e7%a8%b3%e5%ae%9a%e7%89%88lts/">Centos安装nodejs稳定版(LTS)</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2022/01/centos%e5%ae%89%e8%a3%85nodejs%e7%a8%b3%e5%ae%9a%e7%89%88lts/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Linux命令&#124; Swap分区操作</title>
		<link>https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-swap%e5%88%86%e5%8c%ba%e6%93%8d%e4%bd%9c/</link>
					<comments>https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-swap%e5%88%86%e5%8c%ba%e6%93%8d%e4%bd%9c/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Wed, 22 Dec 2021 09:21:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=2662</guid>

					<description><![CDATA[<p>在物理内存不足的情况下，有时增加swap的大小可以在一定程度上缓解内存不足的问题，但是需要注意的是s&#8230; <a href="https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-swap%e5%88%86%e5%8c%ba%e6%93%8d%e4%bd%9c/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Linux命令&#124; Swap分区操作</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-swap%e5%88%86%e5%8c%ba%e6%93%8d%e4%bd%9c/">Linux命令| Swap分区操作</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>在物理内存不足的情况下，有时增加swap的大小可以在一定程度上缓解内存不足的问题，但是需要注意的是swap读写属于磁盘IO，要比物理内存慢的多。</p>



<h3>查看Swap分区</h3>



<p>用free命令可以查看内存情况和交换区大的情况</p>



<pre class="wp-block-preformatted">$ <code>free -h</code>
total used free shared buff/cache available
Mem: 7.6Gi 5.5Gi 124Mi 65Mi 2.0Gi 1.8Gi
Swap: 0B 0B 0B</pre>



<h3>创建Swap分区</h3>



<p>使用下命命令创建分区：</p>



<pre class="wp-block-code"><code>fallocate -l 1G /swapfile</code></pre>



<p>如果报错fallocate failed: Operation not supported，可以使用下面的命令：</p>



<pre class="wp-block-code"><code>dd if=/dev/zero of=/swapfile bs=1024 count=1048576</code></pre>



<p>设置只有root用户才可以读写：</p>



<pre class="wp-block-code"><code>chmod 600 /swapfile</code></pre>



<p>把swapfile文件设置为Linux交换区域</p>



<pre class="wp-block-code"><code>mkswap /swapfile</code></pre>



<p>启动交换区</p>



<pre class="wp-block-code"><code>swapon /swapfile</code></pre>



<p>用free再查看，就可以看到swap交换区：</p>



<pre class="wp-block-preformatted">total used free shared buff/cache available
Mem: 7.6Gi 5.6Gi 129Mi 73Mi 1.9Gi 1.7Gi
Swap: 1Gi 0.0Ki 1Gi</pre>



<h3>配置永久生效</h3>



<p>打开<code>/etc/fstab</code>，加入下面代码：</p>



<pre class="wp-block-code"><code>/swapfile swap swap defaults 0 0</code></pre>



<h3>删除Swap分区</h3>



<p>首先关闭交换区：</p>



<pre class="wp-block-code"><code>swapoff -v /swapfile</code></pre>



<p>然后在<code>/etc/fstab</code>中，删除/swapfile swap swap defaults 0 0这一行</p>



<p>最后删除swapfile文件即可：</p>



<pre class="wp-block-code"><code>rm /swapfile</code></pre>
<p><a rel="nofollow" href="https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-swap%e5%88%86%e5%8c%ba%e6%93%8d%e4%bd%9c/">Linux命令| Swap分区操作</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-swap%e5%88%86%e5%8c%ba%e6%93%8d%e4%bd%9c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Linux命令&#124; Split文件拆分</title>
		<link>https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-split/</link>
					<comments>https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-split/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Fri, 17 Dec 2021 08:58:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=2583</guid>

					<description><![CDATA[<p>有时候需要把大文件进行拆分合并，可以使用split命令 按照大小拆分 每个文件大小100m，生成的新&#8230; <a href="https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-split/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Linux命令&#124; Split文件拆分</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-split/">Linux命令| Split文件拆分</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>有时候需要把大文件进行拆分合并，可以使用split命令</p>



<h3>按照大小拆分</h3>



<pre class="wp-block-code"><code> split -b 100m log.txt newfile</code></pre>



<p>每个文件大小100m，生成的新文件的文件名是newfile后面加上按照aa，ab，ac……来排序的</p>



<p>新文件名也可以不设置，系统默认新文件以字母x开头，那么文件名就是xaa，xab，axc</p>



<h3>数字后缀</h3>



<p>如果觉得aa，ab，ac不好看，也可以使用数字后缀</p>



<pre class="wp-block-code"><code>split -b 100m -d log.txt newfile</code></pre>



<p>生成的文件就是newfile00，newfile01，newfile02</p>



<h3>按照行数拆分</h3>



<p>除了按照大小，也可以按照行数进行拆分</p>



<pre class="wp-block-code"><code>split -1000 -d log.txt newfile</code></pre>



<p>把log.txt按照每1000行拆分</p>



<h3>合并命令</h3>



<p>在Linux下的合并命令是：</p>



<pre class="wp-block-code"><code>cat newfile* > orifile</code></pre>



<p>如果是在 Windows 下的话，先运行 cmd，然后用 copy 命令来进行文件的合并：</p>



<pre class="wp-block-code"><code>copy /b xaa + xab log.txt</code></pre>
<p><a rel="nofollow" href="https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-split/">Linux命令| Split文件拆分</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2021/12/linux%e5%91%bd%e4%bb%a4-split/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Elasticsearch（一）&#124; Centos 安装 Elasticsearch 8.4</title>
		<link>https://wangqianhong.com/2021/09/elasticsearch%ef%bc%88%e4%b8%80%ef%bc%89centos-%e5%ae%89%e8%a3%85-elasticsearch-8-4/</link>
					<comments>https://wangqianhong.com/2021/09/elasticsearch%ef%bc%88%e4%b8%80%ef%bc%89centos-%e5%ae%89%e8%a3%85-elasticsearch-8-4/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Thu, 30 Sep 2021 09:53:02 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<category><![CDATA[Elasticsearch]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=2270</guid>

					<description><![CDATA[<p>Elaticsearch是一个开源的高扩展的分布式全文检索引擎，它可以近乎实时的存储、检索数据，官网&#8230; <a href="https://wangqianhong.com/2021/09/elasticsearch%ef%bc%88%e4%b8%80%ef%bc%89centos-%e5%ae%89%e8%a3%85-elasticsearch-8-4/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Elasticsearch（一）&#124; Centos 安装 Elasticsearch 8.4</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2021/09/elasticsearch%ef%bc%88%e4%b8%80%ef%bc%89centos-%e5%ae%89%e8%a3%85-elasticsearch-8-4/">Elasticsearch（一）| Centos 安装 Elasticsearch 8.4</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>Elaticsearch是一个开源的高扩展的分布式全文检索引擎，它可以近乎实时的存储、检索数据，官网地址：<a href="https://www.elastic.co/cn/" target="_blank" rel="noreferrer noopener">https://www.elastic.co/cn/</a></p>



<h3>安装</h3>



<p>Elasticsearch8.4自带了openjdk，所以不需要再安装java环境</p>



<p>首先安装GPG-KEY</p>



<pre id="block-3328977b-ca1e-4c74-9c5c-0eac6d5790e9" class="wp-block-code"><code>rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch</code></pre>



<p>第一种方式，使用root用户，进入目录<code>/etc/yum.repos.d/</code>，新建文件<code>elasticsearch.repo</code>，内容如下 ：</p>



<pre class="wp-block-code"><code>&#91;elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=0
type=rpm-md</code></pre>



<p>最后用yum命令安装即可：</p>



<pre class="wp-block-code"><code>yum install --enablerepo=elasticsearch elasticsearch</code></pre>



<p>系统会自动完成安装最新release版本</p>



<p>第二种方式，使用root用户wget手动下载需要的版本进行安装</p>



<pre class="wp-block-preformatted"><code>wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.1-x86_64.rpm</code>
<code>wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.1-x86_64.rpm.sha512</code>
<code>shasum -a 512 -c elasticsearch-8.4.1-x86_64.rpm.sha512</code>
<code>rpm --install elasticsearch-8.4.1-x86_64.rpm</code></pre>



<p>如果找不到命令shasum command not found，请先执行下面命令安装shasum</p>



<pre class="wp-block-code"><code>yum install perl-Digest-SHA -y</code></pre>



<h3>配置</h3>



<p>安装完成之后，可以找到系统自动生成的密码</p>



<pre class="wp-block-preformatted">The generated password for the elastic built-in superuser is : OKzrWoarTW8mnpfTcf_z</pre>



<p>也可以使用<code>/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic</code>重新自动生成密码</p>



<p>使用systemctl执行命令</p>



<pre class="wp-block-preformatted"><code>systemctl enable elasticsearch.service</code></pre>



<p>这里需要修改<code>/usr/lib/systemd/system/elasticsearch.service</code>中的TimeoutStartSec和ExecStart</p>



<p>ExecStart默认是前台启动，这里需要改成后台启动，不然用systemctl启动之后，到了TimeoutStartSec的时间，Elasticsearch服务就会超时关闭</p>



<pre class="wp-block-code"><code>ExecStart=/usr/share/elasticsearch/bin/systemd-entrypoint -d -p ${PID_DIR}/elasticsearch.pid</code></pre>



<p>TimeoutStartSec默认在是75秒，可以改成150秒，因为第一次加载的时间比较长，否则如果用<code>systemctl start elasticsearch.service</code>命令启动 ，会报错Start operation timed out. Terminating</p>



<pre class="wp-block-code"><code> TimeoutStartSec=150</code></pre>



<p>修改<code>/etc/elasticsearch/elasticsearch.yml</code>，注释掉<code>cluster.initial_master_nodes</code>，并把集群设置为单结点</p>



<pre class="wp-block-code"><code>cluster.name: test-cluster
node.name: test-node-1
discovery.type: single-node
#cluster.initial_master_nodes: &#91;"9a1ae7a91a36"]</code></pre>



<h3>运行</h3>



<p>一切就绪就好，就可以启动Elasticsearch</p>



<pre class="wp-block-code"><code>systemctl daemon-reload
systemctl start elasticsearch.service</code></pre>



<p>启动完成之后，systemctl有可能提示失败，这不影响Elasticsearch，可以使用命令查看Elasticsearch是否启动成功</p>



<pre class="wp-block-preformatted"><code>curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200</code>

输入上面自动生成的密码，看到如下的输出就表示启动成功了：
{
  "name" : "test-node-1",
  "cluster_name" : "test-cluster",
  "cluster_uuid" : "2_iEDUKHSR-EqsYkAKlZog",
  "version" : {
    "number" : "8.4.1",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "2bd229c8e56650b42e40992322a76e7914258f0c",
    "build_date" : "2022-08-26T12:11:43.232597118Z",
    "build_snapshot" : false,
    "lucene_version" : "9.3.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}</pre>



<p>如果启动失败，可以查看<code>/var/log/elasticsearch/test-cluster.log</code>日志文件来追踪问题。</p>
<p><a rel="nofollow" href="https://wangqianhong.com/2021/09/elasticsearch%ef%bc%88%e4%b8%80%ef%bc%89centos-%e5%ae%89%e8%a3%85-elasticsearch-8-4/">Elasticsearch（一）| Centos 安装 Elasticsearch 8.4</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2021/09/elasticsearch%ef%bc%88%e4%b8%80%ef%bc%89centos-%e5%ae%89%e8%a3%85-elasticsearch-8-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Centos 安装Chrome</title>
		<link>https://wangqianhong.com/2021/09/centos-%e5%ae%89%e8%a3%85chrome/</link>
					<comments>https://wangqianhong.com/2021/09/centos-%e5%ae%89%e8%a3%85chrome/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Tue, 21 Sep 2021 04:51:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=2366</guid>

					<description><![CDATA[<p>使用root账号新建文件/etc/yum.repos.d/chrome.repo，保存下面内容 如果&#8230; <a href="https://wangqianhong.com/2021/09/centos-%e5%ae%89%e8%a3%85chrome/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Centos 安装Chrome</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2021/09/centos-%e5%ae%89%e8%a3%85chrome/">Centos 安装Chrome</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>使用root账号新建文件<code>/etc/yum.repos.d/chrome.repo</code>，保存下面内容</p>



<pre class="wp-block-code"><code>&#91;Chrome]
name=Google Chrome - x86_64
baseurl=http://dl.google.com/linux/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub</code></pre>



<p>如果要装32位，使用下面内容：</p>



<pre class="wp-block-code"><code>&#91;Chrome]
name=Google Chrome - i386
baseurl=http://dl.google.com/linux/rpm/stable/i386
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub</code></pre>



<p>保存之后执行下面命令即可：</p>



<pre class="wp-block-preformatted">如果要安装stable(稳定版)
<code>yum install google-chrome-stable</code>

如果要安装beta
<code>yum install google-chrome-beta</code>

如果要安装unstable
<code>yum install google-chrome-unstable</code></pre>



<p>如果环境无法访问<a href="https://dl-ssl.google.com/linux/linux_signing_key.pub" target="_blank" rel="noreferrer noopener">https://dl-ssl.google.com/linux/linux_signing_key.pub</a>，可以使用命令跳过gpgcheck</p>



<pre class="wp-block-code"><code> yum install google-chrome-stable --nogpgcheck</code></pre>



<p></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2021/09/centos-%e5%ae%89%e8%a3%85chrome/">Centos 安装Chrome</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2021/09/centos-%e5%ae%89%e8%a3%85chrome/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Centos SSH PublicKey证书登录</title>
		<link>https://wangqianhong.com/2021/09/centos-ssh-publickey%e8%af%81%e4%b9%a6%e7%99%bb%e5%bd%95/</link>
					<comments>https://wangqianhong.com/2021/09/centos-ssh-publickey%e8%af%81%e4%b9%a6%e7%99%bb%e5%bd%95/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Sat, 18 Sep 2021 01:19:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=2354</guid>

					<description><![CDATA[<p>PublicKey相对于密码登录更安全。 PublicKey认证的基础在于一对密钥，public k&#8230; <a href="https://wangqianhong.com/2021/09/centos-ssh-publickey%e8%af%81%e4%b9%a6%e7%99%bb%e5%bd%95/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Centos SSH PublicKey证书登录</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2021/09/centos-ssh-publickey%e8%af%81%e4%b9%a6%e7%99%bb%e5%bd%95/">Centos SSH PublicKey证书登录</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>PublicKey相对于密码登录更安全。</p>



<p>PublicKey认证的基础在于一对密钥，public key和private key，public key对数据进行加密而且只能用于加密，private key 只能对所匹配的public key加密过的数据进行解密。</p>



<h3>.ssh目录</h3>



<p>在登录账号的目录下面新建.ssh目录，例如登录账号是test，就在/home/test目录下面新建并修改目录权限：</p>



<pre class="wp-block-preformatted"><code>mkdir .ssh</code>
<code>chmod 700 .ssh</code></pre>



<h3>生成密钥</h3>



<p>进入.ssh目录，使用ssh-keygen命令生成密钥：</p>



<pre class="wp-block-code"><code>ssh-keygen -t rsa -b 4096</code></pre>



<p>需要输入密钥文件名和密钥的密码，密钥文件名默认回车即可：</p>



<pre class="wp-block-preformatted">Generating public/private rsa key pair.
Enter file in which to save the key (/home/test/.ssh/id_rsa): //回车即可
Enter passphrase (empty for no passphrase): //密钥文件的密码
Enter same passphrase again: //密码确认</pre>



<p>执行完毕之后，可以看到两个文件id_rsa.pub和id_rsa，重命名id_rsa.pub</p>



<pre class="wp-block-preformatted"><code>mv id_rsa.pub authorized_keys</code>
<code>chmod 600 authorized_keys</code></pre>



<p>把id_rsa文件下载到本地，之后就可以使用这个文件登录。</p>



<h3>sshd_config</h3>



<p>修改<code>/etc/ssh/sshd_config</code>文件的配置:</p>



<pre class="wp-block-preformatted"><code>PermitRootLogin no</code>
<code>PubkeyAuthentication yes</code>
<code>PasswordAuthentication no</code>
<code>X11Forwarding no</code>
<code>AuthorizedKeysFile .ssh/authorized_keys</code></pre>



<p>PermitRootLogin 使用root账号登录<br>PubkeyAuthentication pubkey登录<br>PasswordAuthentication 密码登录<br>X11Forwarding 如果不使用图形界面，可以把这个禁掉<br>AuthorizedKeysFile 就是开始生成的密钥文件路径，一般不用修改<br>保存修改之后，就可以重启sshd:</p>



<pre class="wp-block-code"><code>systemctl restart sshd</code></pre>



<h3>id_rsa</h3>



<p>打开远程连接的客户端，比如这里使用的是xshell，配置publiekey登录，把下载到本地的id_rsa文件导入即可，导入时需要输入密钥文件的密码：</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="828" height="644" src="https://wangqianhong.com/wp-content/uploads/2022/10/centos-ssh.png" alt="" class="wp-image-2359" srcset="https://wangqianhong.com/wp-content/uploads/2022/10/centos-ssh.png 828w, https://wangqianhong.com/wp-content/uploads/2022/10/centos-ssh-768x597.png 768w, https://wangqianhong.com/wp-content/uploads/2022/10/centos-ssh-386x300.png 386w" sizes="(max-width: 828px) 100vw, 828px" /></figure>



<p></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2021/09/centos-ssh-publickey%e8%af%81%e4%b9%a6%e7%99%bb%e5%bd%95/">Centos SSH PublicKey证书登录</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2021/09/centos-ssh-publickey%e8%af%81%e4%b9%a6%e7%99%bb%e5%bd%95/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
