普通视图

发现新文章,点击刷新页面。
昨天以前飞翔沫沫情博客

Centos 7安装配置NTP网络时间同步服务器

2021年5月12日 10:42

实验环境:

OS:Linux Centos 7.4 x86_64

1.查看当前服务器时区&列出时区并设置时区(如已是正确时区,请略过):

# timedatectl
# timedatectl list-timezones
# timedatectl set-timezone Asia/Shanghai

2.时间时区概念理解:

GMT、UTC、CST、DST

UTC:

整个地球分为二十四时区,每个时区都有自己的本地时间,在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC:Universal Time Coordinated)。

GMT:

格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线(UTC与GMT时间基本相同)。

CST:

中国标准时间 (China Standard Time)

GMT + 8 = UTC + 8 = CST

DST:

夏令时(Daylight Saving Time) 指在夏天太阳升起的比较早时,将时间拨快一小时,以提早日光的使用(中国不使用)。

2.使用 NTP 公共时间服务器池(NTP Public Pool Time Servers)http://www.pool.ntp.org 同步你的服务器时间。

查看是否安装:

# rpm -q ntp
ntp-4.2.6p5-25.el7.centos.2.x86_64

如已安装请略过此步,否则请执行以下命令安装:

# yum install ntpdate ntp -y

修改NTP配置:

 

# vim /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

#新增:日志目录.
logfile /var/log/ntpd.log

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery

# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1
#这一行的含义是授权所有机器可以从这台机器上查询和同步时间.
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).

#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

#新增:时间服务器列表.
server 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst
server ntp1.aliyun.com	iburst
server ntp2.aliyun.com	iburst
server ntp3.aliyun.com	iburst
server ntp4.aliyun.com	iburst
server ntp5.aliyun.com	iburst
server ntp6.aliyun.com	iburst
server ntp7.aliyun.com	iburst

#新增:当外部时间不可用时,使用本地时间193.168.151.6 为本机IP
#127.127.1.0 表示使用本机同步,必须是127.127.1.0!!!有坑
server 127.127.1.0
server 193.168.151.6 iburst
fudge 127.0.0.1 stratum 10

#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

#新增:允许上层时间服务器主动修改本机时间.
restrict 0.cn.pool.ntp.org nomodify notrap noquery
restrict 1.cn.pool.ntp.org nomodify notrap noquery
restrict 2.cn.pool.ntp.org nomodify notrap noquery

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

3.设置系统开机自启动:

# systemctl enable ntpd
# systemctl enable ntpdate
# systemctl is-enabled ntpd

在ntpd服务启动时,先使用ntpdate命令同步时间:

# ntpdate -u 1.cn.pool.ntp.org

原因之一:当服务端与客户端之间的时间误差过大时,此时修改时间可能对系统或应用带来不可预知问题,NTP会停止时间同步。若检查NTP启动后时间未同步时,应考虑可能是时间误差过大所致,此时需要先手动进行时间同步。

启动NTP服务器:

# systemctl start ntpdate
# systemctl start ntpd

4.加入防火墙:

# firewall-cmd --permanent --add-service=ntp
# firewall-cmd --reload

5.查看ntp连接状态如果没有问题

# ss -tlunp | grep ntp
# ntpq -p
 
将正确时间写入硬件【虚拟机,ECS 可以不用写入到硬件】
# hwclock -w

6.客户端:

以crontab任务计划同步时间(需安装ntpdate,每天24点更新同步时间):

[root@ecs-8611-0002 ~]# crontab -e
 
#ntp 时间同步
* */2 * * * /usr/sbin/ntpdate 193.168.151.6 > /dev/null 2>&1
 
#手动同步下,验证下时间是否同步过来
[root@ecs-8611-0002 ~]#  /usr/sbin/ntpdate 193.168.151.6 > /dev/null 2>&1
[root@ecs-8611-0002 ~]# date
Wed May 12 10:31:36 CST 2021

 

或者  使用chrony 来同步时间

 

一、编辑本地时间同步服务器地址

vim /etc/chrony.conf

server ntp1.aliyun.com iburst

server ntp2.aliyun.com iburst

server ntp3.aliyun.com iburst

server ntp4.aliyun.com iburst

server ntp5.aliyun.com iburst

server ntp6.aliyun.com iburst

server ntp7.aliyun.com iburst

 

systemctl start chronyd

systemctl enable chronyd

 

二、设置时区:

timedatectl set-timezone Asia/Shanghai

(date -s “YYYY-MM-DD HH:MM:SS”)手动设置时间

 

 

openeuler22.03 LTS 源码编译安装fastdfs-6.06

2023年6月28日 13:44

openeuler22.03 LTS 源码编译安装fastdfs-6.06

1、环境

名称 版本 备注
openeuler 22.03 LTS  
fastdfs 6.06  
libfastcommon 1.0.43 libfastcommon是一个开源的C语言库,用于实现高性能的分布式文件系统和分布式存储系统

2、准备安装包

fastdfs 官网: https://github.com/happyfish100/fastdfs/tree/V6.06

官网可参考的安装手册:https://github.com/happyfish100/fastdfs/blob/V6.06/INSTALL

#fastdfs下载地址
https://github.com/happyfish100/fastdfs/archive/refs/tags/V6.06.zip

# libfastcommon下载地址
https://github.com/happyfish100/libfastcommon/archive/refs/tags/V1.0.43.zip

3、安装源码编译相关依赖包:

[root@0003 ~]# yum -y install make gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel kernel-headers

4、安装libfastcommon :

#解压 
unzip  V1.0.43.zip
#并进入目录,执行 ./make.sh,执行./make.sh install

5、安装fastdfs

#解压 
unzip V6.06.zip
#并进入目录,执行./make.sh,执行./make.sh install

#安装成功后,根据模板创建3个配置文件
[root@0003 ~]#cd /etc/fdfs/

[root@0003 ~]# cp client.conf.sample client.conf  && cp storage.conf.sample storage.conf  &&  cp tracker.conf.sample tracker.conf   


#创建fastdfs数据目录
[root@0003 ~]# mkdir -p /home/application/fastdfs/

6、配置并启动tracker

[root@0003 ~]# vim /etc/fdfs/tracker.conf

..............
disabled=false                              #配置文件是否失效
port=22122                                     #默认端口号
base_path= /home/application/fastdfs/          #日志及运行数据存储目录
..............

添加自启动,并启动服务

[root@fastdfs 00]# chkconfig --add fdfs_trackerd

[root@0003 ~]# /etc/init.d/fdfs_trackerd start

7、配置并启动storage

[root@0003 ~]# vim /etc/fdfs/storage.conf

..............
disabled=false                                  #配置文件是否失效
group_name=group1                               #组名,根据实际情况修改
port=23000                                      #设置storage的端口号,默认是23000
base_path = /home/application/fastdfs/          #设置storage数据文件和日志目录
store_path_count=1                              #存储路径个数,需要和store_path个数匹配
store_path0 = /home/application/fastdfs/        #实际文件存储路径
tracker_server = 10.131.225.40:22122            #如果有多个tracker, tracker_server可以写多行
..............

添加自启动,并启动服务

[root@fastdfs 00]# chkconfig --add fdfs_storaged

[root@0003 ~]# /etc/init.d/fdfs_storaged start

8、配置client.conf 配置文件

[root@0003 ~]#vim /etc/fdfs/client.conf

  • 只保留如下内容,默认的文件内容都可以清空
base_path=/tmp
tracker_server=10.131.225.40:22122

创建一个测试文件并上传

[root@0003 ~]# echo "hello openeuler" > /tmp/test

#指定client.conf配置文件,并指定需要上传的文件
[root@0003 ~]# fdfs_upload_file  /etc/fdfs/client.conf   /tmp/test
返回值如 group1/M00/00/00/wKgBY2SaRKOABUlXAAAAEAGd5Pk2122913, 在 storage server1上相应目录中均能查看到该文件


具体的文件应该在: /home/application/fastdfs/data/00/00/wKgBY2SaRKOABUlXAAAAEAGd5Pk2122913

图片[1]-飞翔沫沫情

9、需注意!Fastdfs预留空间问题!

注意FastDFS中有预留空间的概念,在tracker.conf中设置,配置项为:reserved_storage_space,为磁盘总空间的20%,请酌情设置reserved_storage_space这个参数,配合监控系统来监控文件系统大小

 

 
 
 
 
 
 
 
 
 
 
 
 

 

关于在Jenkins 的job 中隐藏shared library 共享库相关的Git信息

2023年6月26日 13:20

关于在Jenkins 的job 中隐藏shared library 共享库相关的Git信息

需求:

jenkins 中因为使用了shared library 共享库,当每次去修改共享库中的配置的时候,job 在发布时,总会带出 changes 变更信息,怎么能够不输出共享库的git 变更信息,只打印业务代码 的变更记录

image-20230626130909492

解决:

只需要在 jenkins 系统管理 / System 系统配置中 , 找到shared library 配置的地方,取消勾选 Include @Library changes in job recent changes 即可

image-20230626131153831

参考:

openEuler普通用户su root时Permission denied

2023年6月23日 11:22

openEuler普通用户su root时Permission denied.md

背景:

openEuler默认普通用户是不能通过su切换到root用户的,
官方解释: su命令用于在不同帐户之间切换。为了增强系统安全性,有必要对su命令的使用权进行控制,只允许root和wheel群组的帐户使用su命令,限制其他帐户使用。

image-20230623112608683

如果想普通用户 通过su切换到root,有以下两个解决办法

1、修改/etc/pam.d/su 文件 【不推荐】
[root@localhost ~]#  vim /etc/pam.d/su
#修改21行,将“auth required pam_wheel.so use_uid”注释

image-20230623112755186

2、将用户添加到whell用户组里 【推荐】

当我们在部署openeuler 系统的时候,系统会提示创建个普通用户,且这个用户可以su切换到root用户下,因为这个用户就是在whell用户组里的

#将devops用户加入wheel组
[root@localhost ~]# usermod -G wheel devops

[root@localhost ~]# id devops
uid=1000(devops) gid=1000(devops) groups=1000(devops),10(wheel)

Centos7 使用nvm配置 多Node.js环境

2023年5月7日 22:22
 

背景

  • 新项目 使用Node.js-v16.17.1
  • 旧项目 使用Node.js- v14.18.0 【且依赖于node-saas模块,根据 node-sass 的官方文档,目前最新版本的 node-sass(即 v5.0.0)支持的 Node.js 版本范围是 Node.js 10.x、Node.js 12.x、Node.js 14.x。并没有明确支持 Node.js 16.x 版本】
  • Centos7.9

nvm(Node Version Manager)管理工具

nvm 介绍

nvm是一个用于管理多个 Node.js 版本的工具。它可以让你在同一台机器上安装和切换不同版本的 Node.js,而不会相互干扰。使用 nvm,你可以轻松地安装、切换和删除 Node.js 版本。你可以在同一台机器上同时安装多个版本的 Node.js,并且可以在项目中使用不同的 Node.js 版本,以确保项目的兼容性和稳定性。例如,你可以在一台机器上同时安装 Node.js 10.x、Node.js 12.x 和 Node.js 14.x 版本。然后,你可以使用 nvm 命令来切换到不同的版本,以便在不同的项目中使用不同的 Node.js 版本。

总之,nvm 是一个非常方便的工具,可以帮助你管理 Node.js 版本,提高开发效率。

在 Centos7 上安装 nvm 和 Node.js

  • 安装必要的依赖项:
[root@localhost ~]#yum install -y curl git
  • 下载并安装 nvm:

官网仓库地址: https://github.com/nvm-sh/nvm.git

[root@localhost ~]# wget https://github.com/nvm-sh/nvm/archive/refs/tags/v0.39.3.tar.gz
[root@localhost ~]# tar -xf nvm-0.39.3.tar
[root@localhost ~]# mv nvm-0.39.3 /root/.nvm
  • 配置环境变量
root@localhost ~]# echo ". ~/.nvm/nvm.sh" >> /etc/profile
root@localhost ~]# source /etc/profile
  • 重新打开终端窗口,运行以下命令以验证 nvm 是否正确安装:

    如果输出了 nvm,则说明 nvm 已经正确安装。

[root@localhost ~]# command -v nvm
nvm
  • 验证nvm版本
[root@localhost ~]# nvm -v
0.39.3
  • 在线查看Nodejs所有版本
[root@localhost ~]# nvm list-remote
  • 安装所需的 Node.js版本
[root@localhost ~]# nvm install 16.17.1
[root@localhost ~]# nvm install v14.18.0
  • 查看安装的 Node.js版本
[root@localhost ~]# nvm ls
    v14.18.0
    v16.17.1
  • 切换到指定Node.js版本上
[root@localhost ~]# nvm use v14.18.0
Now using node v14.18.0 (npm v6.14.15)

[root@localhost ~]# node -v
v14.18.0

[root@localhost ~]# npm -v
6.14.15
[root@localhost ~]# nvm use   v16.17.1
Now using node v16.17.1 (npm v8.15.0)
[root@localhost ~]# node -v
v16.17.1
[root@localhost ~]# npm -v
8.15.0

拓展(一): 安装yarn 包管理工具

yarn 介绍:

Yarn 是一个快速、可靠、安全的 JavaScript 包管理器,由 Facebook、Google、Exponent 和 Tilde 公司共同开发。它可以替代 npm,用于管理 JavaScript 包的依赖关系、版本号和安装。与 npm 相比,Yarn 具有以下优点:

  • 快速:Yarn 使用并行下载,可以显著提高安装包的速度。
  • 可靠:Yarn 使用一个锁文件(yarn.lock)来确保在不同的环境中安装相同的依赖项。这可以避免意外升级或降级依赖项,从而保证项目的稳定性。
  • 安全:Yarn 使用 SHA-1 哈希值来验证每个依赖项的完整性,以确保安装的包没有被篡改。
  • 支持离线模式:Yarn 可以缓存所有的包和依赖项,从而可以在没有网络连接的情况下安装依赖项。
  • 易于使用:Yarn 具有与 npm 类似的命令行界面,易于学习和使用。

总之,Yarn 是一个强大的 JavaScript 包管理器,可以帮助开发人员更快、更可靠、更安全地管理 JavaScript 包的依赖关系和版本号。

  • 先使用nvm切换到指定的nodejs 版本上
[root@localhost ~]# nvm use v14.18.0
Now using node v14.18.0 (npm v6.14.15)
  • 设置淘宝npm加速
   [root@localhost ~]# npm config set registry https://registry.npm.taobao.org

   #通过这个命令进行测试
    [root@localhost ~]# npm config get registry
    https://registry.npm.taobao.org/
  • 安装yarn并设置加速
[root@jenkins-new ~]# npm install -g yarn

#全局修改
[root@jenkins-new ~]# yarn config set registry https://registry.npm.taobao.org/


#过这个命令进行测试
[root@jenkins-new ~]# yarn -v
1.22.15

需要注意的是,每一个nodejs 版本 再安装yarn 的时候,都需要重复上面的操作,先切换到指定nodejs,再安装yarn

拓展(二): jenkins 使用nvm 工具打包前端代码

上面介绍过我们需要使用多个nodejs 环境来分别打包不同的项目

jenkinsfile 入口文件: 定义nodejs 的版本

map.put('npm_version','v16.17.1')//定义nodejs打包的版本,目前仅支持v14.18.0【默认】和v16.17.1

jenkins 前端发布模板:

  stage("打包编译"){
   steps{
                timeout(time: 5, unit: 'MINUTES') {
              script {
                tools.PrintMes("打包编译!nodejs版本为:${npm_version}",'green')
                try {
                    sh '''
                    source /etc/profile && nvm use "${npm_version}" && yarn && yarn build:release"
                    '''
                }catch (err) {
                    echo "编译失败,请检查"
                    exit 3
                        }
                    }
                }
      }
  }

效果:
图片[1]-飞翔沫沫情

❌
❌