存档

文章标签 ‘Linux’

CentOS 一键安装Cacti 1.2.3脚本

2019年5月19日 没有评论
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
 
echo "this script requires git"
yum install -y git 
 
echo "This script will download all Cacti dependecies and download the chosen cacti version from the cacti github"
echo "Dont forget to support cacti @ cacti.net!"
 
echo "set selinux to disabled"
setenforce 0 
sed -i 's/enforcing/disabled/g' /etc/selinux/config /etc/selinux/config
 
#Download chosen release
echo "here are some of the current cacti release versions \n
release/1.2.3
release/1.2.2
release/1.2.1
release/1.2.0
"
 
echo  "which release would you like to download ? Hit enter for latest"
read version
 
if  [ "$version" == "" ]
then
git clone https://github.com/Cacti/cacti.git
 
else 
yum install -y wget unzip
wget https://github.com/Cacti/cacti/archive/release/$version.zip
unzip $version 
mv cacti-release-$version cacti
fi
 
echo "will you be using the spine poller enter 1 for yes 2 for no"
read answer
if [ $answer == "1" ]
then
##Download packages needed for spine
yum install -y gcc mysql-devel net-snmp-devel autoconf automake libtool dos2unix help2man
echo "downloading and compling spine"
git clone https://github.com/Cacti/spine.git
cd spine
./bootstrap
./configure
make
make install
chown root:root /usr/local/spine/bin/spine
chmod u+s /usr/local/spine/bin/spine
cd ..
 
else
echo "spine dependecies  will not be installed"
fi
 
echo "On Centos systems we need to enable EPEL repos"
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum install yum-utils -y
yum-config-manager --enable remi-php72
 
echo "Downloading PHP modules needed for Cacti install"
 
yum install  -y rrdtool mariadb-server net-snmp-utils net-snmp  snmpd php php-mysql  php-snmp php-xml php-mbstring php-json php-gd php-gmp php-zip php-ldap php-mc php-posix 
 
###Start services 
 
systemctl enable httpd
systemctl enable mariadb
systemctl start mariadb
systemctl start httpd
 
####Open Port 80 and 443 on firewalld
 
echo "Open http and https ports on firewalld"
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
 
##Timezone settings needed for cacti
echo "Enter your PHP time zone i.e America/Toronto  Default is US/Central "
read timezone
if [ $timezone == "" ] 
then
 
echo "date.timezone =" US/Central >> /etc/php.ini
else
 
echo "date.timezone =" $timezone >> /etc/php.ini
 
fi  
 
echo "Where would you like to install cacti default location is /var/www/html hit enter for default location"
read location
if [$location = ""]
then
 
location="/var/www/html"
 
mv cacti /var/www/html
else
mv cacti $location
fi
 
#Create cacti user and change permission of directory
echo "Which user would you like to run Cacti under (Default is www-data) hit enter for default"
read user
if [$user = ""]
then 
user="apache"
echo  "cacti will be run under apache"
chown -R  apache:apache $location/cacti
else 
useradd $user
chown -R $user:$user $location/cacti
fi
 
#assign permissions for cacti installation
 
chown -R apache:apache $location/cacti/resource/snmp_queries/          
chown -R apache:apache $location/cacti/resource/script_server/
chown -R apache:apache $location/cacti/resource/script_queries/
chown -R apache:apache $location/cacti/scripts/
chown -R apache:apache $location/cacti/cache/boost/
chown -R apache:apache $location/cacti/cache/mibcache/
chown -R apache:apache $location/cacti/cache/realtime/
chown -R apache:apache $location/cacti/cache/spikekill/
touch $location/cacti/log/cacti.log
chmod 777 $location/cacti/log/cacti.log
chown -R apache:apache   $location/cacti/log/
cp $location/cacti/include/config.php.dist $location/cacti/include/config.php
 
##Create database 
echo "would you like to customize the database name and user ? hit enter for defaults"
read customize
 
if [[ $customize = "" ]] 
then
 
mysql -uroot <<MYSQL_SCRIPT
CREATE DATABASE cacti DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
GRANT ALL PRIVILEGES ON cacti.* TO 'cacti'@'localhost' IDENTIFIED BY 'cacti'; ;
GRANT SELECT ON mysql.time_zone_name TO cacti@localhost;
USE mysql;
ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
FLUSH PRIVILEGES;
MYSQL_SCRIPT
 
#pre populate cacti db
mysql -u root  cacti < $location/cacti/cacti.sql
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root  mysql
 
sed -i -e 's@^$database_type.*@$database_type = "mysql";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_default.*@$database_default = "cacti";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_hostname.*@$database_hostname = "127.0.0.1";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_username.*@$database_username = "cacti";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_password.*@$database_password = "cacti";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_port.*@$database_port = "3306";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^$database_ssl.*@$database_ssl = "false";@g' /var/www/html/cacti/include/config.php
sed -i -e 's@^//$url_path@$url_path@g' /var/www/html/cacti/include/config.php
 
echo "default database setup with following details"
echo "database name cacti\n
database username cacti\n
database password cacti"
 
else
 
echo "enter db name"
read customdbname
echo "enter db user"
read customdbuser
echo "enter db password"
read customdbpassword
 
mysql -u root <<MYSQL_SCRIPT
CREATE DATABASE $customdbname;
GRANT ALL PRIVILEGES ON $customdbname.* TO '$customdbuser'@'localhost' IDENTIFIED BY '$customdbpassword';
GRANT SELECT ON mysql.time_zone_name TO $customdbuser@localhost;
ALTER DATABASE $customdbname CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
FLUSH PRIVILEGES;
MYSQL_SCRIPT
 
echo "Pre-populating cacti DB"
mysql -u root  $customdbname < $location/cacti/cacti.sql
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root  mysql
 
sed -i -e 's@^$database_type.*@$database_type = "mysql";@g' $location/cacti/include/config.php
sed -i -e 's@^$database_default.*@$database_default = '$customdbname'\;@g' $location/cacti/include/config.php
sed -i -e 's@^$database_hostname.*@$database_hostname = "127.0.0.1";@g' $location/cacti/include/config.php
sed -i -e 's@^$database_username.*@$database_username = '$customdbuser';@g' $location/cacti/include/config.php
sed -i -e 's@^$database_password.*@$database_password = '$customdbpassword';@g' $location/cacti/include/config.php
sed -i -e 's@^$database_port.*@$database_port = "3306";@g' "$location"/cacti/include/config.php
sed -i -e 's@^$database_ssl.*@$database_ssl = "false";@g' "$location"/cacti/include/config.php
sed -i -e 's@^//$url_path@$url_path@g' $location/cacti/include/config.php
 
fi
 
###Adding recomended PHP settings 
sed -e 's/max_execution_time = 30/max_execution_time = 60/' -i /etc/php.ini
sed -e 's/memory_limit = 128M/memory_limit = 400M/' -i /etc/php.ini
 
echo "Applying recommended DB settings"
echo "
innodb_file_format = Barracuda
character_set_client = utf8mb4
max_allowed_packet = 16777777
join_buffer_size = 32M
innodb_file_per_table = ON
innodb_large_prefix = 1
innodb_buffer_pool_size = 250M
innodb_additional_mem_pool_size = 90M
innodb_flush_log_at_trx_commit = 2
" >> /etc/my.cnf.d/server.cnf
 
echo "this script can download the following plugins monitor,thold would you like to install them  ?
type yes to download hit enter to skip"
read plugins
 if [ $plugins == "yes" ]
  then
   git clone https://github.com/Cacti/plugin_thold.git
    git clone https://github.com/Cacti/plugin_monitor.git
mv plugin_thold thold
  mv plugin_monitor monitor
   chown -R $user:$user thold
    chown -R $user:$user monitor
     mv thold $location/cacti/plugins
      mv monitor $location/cacti/plugins
else
 echo "plugins will not be installed"
fi
 
touch /etc/cron.d/$user
echo "*/5 * * * * $user php $location/cacti/poller.php > /dev/null 2>&1" > /etc/cron.d/$user 
 
echo "refreshing services"
systemctl restart httpd
systemctl restart mariadb
 
echo "Installation completed !"
分类: Linux, 编程实践 标签: , ,

centos7 firewall-cmd

2019年4月4日 没有评论
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#删除端口规则
firewall-cmd --zone=public --remove-port=22/tcp --permanent
 
#查看列表规则
firewall-cmd --zone=public --list-ports
 
#开设端口
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
 
firewall-cmd --reload
systemctl enable firewalld
systemctl restart firewalld
 
#限制指定ip地址访问端口,例如ssh端口22
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.11.11" port protocol="tcp" port="22" accept"
 
#删除限制规则
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.11.11" port protocol="tcp" port="11300" accept"
 
#开通端口范围规则
firewall-cmd --permanent --add-port=1000-2000/tcp
 
#添加指定网段对ssh所用的端口访问权限
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="112.112.112.0/24" port protocol="tcp" port="22" accept"
 
#以上是一些实用新版本防火墙笔记,希望对大家有用

查看网线是否接上及mii-tool使用(转)

2019年3月26日 没有评论

==================================Debian=======================================
1、发行版本
cat /etc/debian_version
5.0.2

2、内核
uname -r
2.6.18-6-amd64

3、机型
dmidecode -s system-product-name
PowerEdge R710

4、安装软件包
apt-get -y install net-tools

5、使用ip命令查看网络接口状态
1)ip a
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth0: mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 84:2b:2b:48:ab:12 brd ff:ff:ff:ff:ff:ff
3: eth1: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 84:2b:2b:48:ab:14 brd ff:ff:ff:ff:ff:ff
inet 192.168.35.133/24 brd 192.168.35.255 scope global eth1
4: eth2: mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 84:2b:2b:48:ab:16 brd ff:ff:ff:ff:ff:ff
5: eth3: mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 84:2b:2b:48:ab:18 brd ff:ff:ff:ff:ff:ff
查看结果是eth1已经有ip 但eth0还没有ip及网络接口也没有打开

2)参数说明
qdisc pfifo_fast #Priority queueing
qlen #默认接口传输队列的默认长度
mtu #最大传输单元
qdisc noop #表示网络接口还没有up状态
up #设备处于运行状态,能接收和发送数据包
down #设备处于关闭状态,不能接收和发送数据包
qdisc mq #Multiqueue

6、如果没打开eth0网络接口的话使用mii-tool命令后结果是这样的
mii-tool
SIOCGMIIPHY on ‘eth0′ failed: Resource temporarily unavailable
eth1: negotiated 1000baseT-FD flow-control, link ok
SIOCGMIIPHY on ‘eth2′ failed: Resource temporarily unavailable
SIOCGMIIPHY on ‘eth3′ failed: Resource temporarily unavailable

7、使用ifconfig命令打开eth0网络接口
ifconfig eth0 up

8、再次使用mii-tool命令查看网线是否连接,这次看到显示eth0是no link状态 判定网线没接上
eth0: no link
eth1: negotiated 1000baseT-FD flow-control, link ok
eth2: no link
eth3: no link

9、找idc工程师让他们接上网线

==================================Centos=======================================
1、发行版本
cat /etc/redhat-release
CentOS release 6.5 (Final)

2、内核
uname -r
2.6.32-431.el6.x86_64

3、机型
dmidecode -s system-product-name
PowerEdge R610

4、安装软件包
yum -y install net-tools

5、使用ip命令查看网络接口状态
ip a
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc mq state UP qlen 1000
link/ether 00:22:19:63:97:5e brd ff:ff:ff:ff:ff:ff
inet 111.222.333.444/24 brd 111.222.333.444 scope global eth0
inet6 fe80::222:19ff:fe63:975e/64 scope link
valid_lft forever preferred_lft forever
3: eth1: mtu 1500 qdisc mq state UP qlen 1000
link/ether 00:22:19:63:97:60 brd ff:ff:ff:ff:ff:ff
inet 10.18.22.190/24 brd 10.18.22.255 scope global eth1
inet6 fe80::222:19ff:fe63:9760/64 scope link
valid_lft forever preferred_lft forever
4: eth2: mtu 1500 qdisc mq state UP qlen 1000
link/ether 00:22:19:63:97:62 brd ff:ff:ff:ff:ff:ff
inet 111.222.333.444/25 brd 111.222.333.444 scope global eth2
inet6 fe80::222:19ff:fe63:9762/64 scope link
valid_lft forever preferred_lft forever
5: em4: mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 00:22:19:63:97:64 brd ff:ff:ff:ff:ff:ff

6、如果没打开em4网络接口的话使用mii-tool命令后结果是这样的
mii-tool em4
SIOCGMIIPHY on ‘em4′ failed: Resource temporarily unavailable

7、使用ifconfig命令打开eth0网络接口
ifconfig em4 up

8、找idc工程师让他们接上网线后查看
mii-tool em4
em4: negotiated 100baseTx-FD flow-control, link ok

参考文章

http://events.linuxfoundation.org/sites/events/files/slides/Linux_traffic_control.pdf

分类: 解决方案 标签: ,

CentOS7使用firewalld打开关闭防火墙与端口

2019年3月10日 没有评论

1、firewalld的基本使用
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld

2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl –failed

3.配置firewalld-cmd

查看版本: firewall-cmd –version
查看帮助: firewall-cmd –help
显示状态: firewall-cmd –state
查看所有打开的端口: firewall-cmd –zone=public –list-ports
更新防火墙规则: firewall-cmd –reload
查看区域信息: firewall-cmd –get-active-zones
查看指定接口所属区域: firewall-cmd –get-zone-of-interface=eth0
拒绝所有包:firewall-cmd –panic-on
取消拒绝状态: firewall-cmd –panic-off
查看是否拒绝: firewall-cmd –query-panic

那怎么开启一个端口呢
添加
firewall-cmd –zone=public –add-port=80/tcp –permanent (–permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd –reload
查看
firewall-cmd –zone= public –query-port=80/tcp
删除
firewall-cmd –zone= public –remove-port=80/tcp –permanent

分类: Linux 标签: , ,

centos7重新调整分区大小

2019年1月14日 没有评论

cenos 7 最小化安装完成后,分区是自动的。默认都会很多分到home目录,这很不合理。建议一般大家都分给/目录,也就是根目录。这样比较方便。

查看磁盘的空间大小: df -h

备份/home : cp -r /home/ homebak/
卸载​ /home : umount /home

如果出现 home 存在进程,使用 fuser -m -v -i -k /home 终止 home 下的进程,最后使用 umount /home 卸载 /home
删除/home所在的lv : lvremove /dev/mapper/centos-home

扩展/root所在的lv,增加4430G : lvextend -L +4430G /dev/mapper/centos-root
扩展/root文件系统 : xfs_growfs /dev/mapper/centos-root

重新创建home lv : lvcreate -L 167G -n home centos

重新创建home lv 分区的大小,根据 vgdisplay 中的free PE 的大小确定
创建文件系统: mkfs.xfs /dev/centos/home
挂载 home: mount /dev/centos/home /home

重新调整大小后,/home 下的东西将丢失,注意做好备份。。。

分类: 解决方案 标签: ,

ssh 连接缓慢解决方法

2019年1月12日 没有评论

瞬间登陆。。。

vi /etc/ssh/sshd_config

关闭 SSH 的 DNS 反解析,添加下面一行:

UseDNS no

虽然配置文件中[UseDNS yes]被注释

但默认开关就是yes。。。SSH服务默认启用了DNS反向解析的功能

分类: Linux, 解决方案 标签: , ,

CentOS7 linux系统中修改swap虚拟内存大小

2018年12月28日 没有评论

linux中安装oracle的时候要求swap是ram的1.5倍。自己部署的虚拟机linux系统,通过free命令查看,该要求不达标,需要手动调整swap

用命令cd /usr,先进入usr路径中

在usr路径中,新建一个文件夹swap
命令为:mkdir swap,创建后用ls命令可以看到新创建的swap文件夹

创建后进行进入到该swap文件夹路径,命令为:cd /swap,用命令ll查看使用量为0

这里我们创建swap文件,命令为:dd if=/dev/zero of=swapfile bs=1G count=3
这条命令从硬盘里分出一个1×3G 大小的空间,挂在swapfile上。

常见swapfile文件完成后,用命令ll查看用量为3G

也可以用命令:du -sh /usr/swap/swapfile命令查看文件大小

swapfile文件创建后,需要构建swap格式于/usr/swap/swapfile 上
命令为:mkswap /usr/swap/swapfile

用命令激活swap,立即启用交换分区文件
命令为:swapon /usr/swap/swapfile
但是这样的设置重启后就失效了,为了保证每次启动都能启用该交换空间,需要手动编辑文件/etc/fstab中的swap行
命令为:vi /etc/fstab

将原来的一行注释掉,添加命令行:
/usr/swap/swapfile swap swap defaults 0 0

重启centos后,用free查看,swap就是设置后的3G了

分类: Linux, 解决方案 标签: ,

shell脚本输出带颜色字体

2018年12月14日 没有评论

经常shell下都有需要使用到特殊标记的提示字符。以下很全,网上找来的。转发一下。

输出特效格式控制:
\033[0m 关闭所有属性
\033[1m 设置高亮度
\03[4m 下划线
\033[5m 闪烁
\033[7m 反显
\033[8m 消隐
\033[30m — \033[37m 设置前景色
\033[40m — \033[47m 设置背景色

光标位置等的格式控制:
\033[nA 光标上移n行
\03[nB 光标下移n行
\033[nC 光标右移n行
\033[nD 光标左移n行
\033[y;xH设置光标位置
\033[2J 清屏
\033[K 清除从光标到行尾的内容
\033[s 保存光标位置
\033[u 恢复光标位置
\033[?25l 隐藏光标

\33[?25h 显示光标

整理:
编码 颜色/动作
  0 重新设置属性到缺省设置
  1 设置粗体
  2 设置一半亮度(模拟彩色显示器的颜色)
  4 设置下划线(模拟彩色显示器的颜色)
  5 设置闪烁
  7 设置反向图象
  22 设置一般密度
  24 关闭下划线
  25 关闭闪烁
  27 关闭反向图象
  30 设置黑色前景
  31 设置红色前景
  32 设置绿色前景
  33 设置棕色前景
  34 设置蓝色前景
  35 设置紫色前景
  36 设置青色前景
  37 设置白色前景
  38 在缺省的前景颜色上设置下划线
  39 在缺省的前景颜色上关闭下划线
  40 设置黑色背景
  41 设置红色背景
  42 设置绿色背景
  43 设置棕色背景
  44 设置蓝色背景
  45 设置紫色背景
  46 设置青色背景
  47 设置白色背景
  49 设置缺省黑色背景
特效可以叠加,需要使用“;”隔开,例如:闪烁+下划线+白底色+黑字为 \033[5;4;47;30m闪烁+下划线+白底色+黑字为\033[0m
下面是一段小例子

#!/bin/bash
#
#下面是字体输出颜色及终端格式控制
#字体色范围:30-37
echo -e “\033[30m 黑色字 \033[0m”
echo -e “\033[31m 红色字 \033[0m”
echo -e “\033[32m 绿色字 \033[0m”
echo -e “\033[33m 黄色字 \033[0m”
echo -e “\033[34m 蓝色字 \033[0m”
echo -e “\033[35m 紫色字 \033[0m”
echo -e “\033[36m 天蓝字 \033[0m”
echo -e “\033[37m 白色字 \033[0m”
#字背景颜色范围:40-47
echo -e “\033[40;37m 黑底白字 \033[0m”
echo -e “\033[41;30m 红底黑字 \033[0m”
echo -e “\033[42;34m 绿底蓝字 \033[0m”
echo -e “\033[43;34m 黄底蓝字 \033[0m”
echo -e “\033[44;30m 蓝底黑字 \033[0m”
echo -e “\033[45;30m 紫底黑字 \033[0m”
echo -e “\033[46;30m 天蓝底黑字 \033[0m”
echo -e “\033[47;34m 白底蓝字 \033[0m”

#控制选项说明
#\033[0m 关闭所有属性
#\033[1m 设置高亮度
#\033[4m 下划线
echo -e “\033[4;31m 下划线红字 \033[0m”
#闪烁
echo -e “\033[5;34m 红字在闪烁 \033[0m”
#反影
echo -e “\033[8m 消隐 \033[0m ”

#\033[30m-\033[37m 设置前景色
#\033[40m-\033[47m 设置背景色
#\033[nA光标上移n行
#\033[nB光标下移n行
echo -e “\033[4A 光标上移4行 \033[0m”
#\033[nC光标右移n行
#\033[nD光标左移n行
#\033[y;xH设置光标位置
#\033[2J清屏
#\033[K清除从光标到行尾的内容
echo -e “\033[K 清除光标到行尾的内容 \033[0m”
#\033[s 保存光标位置
#\033[u 恢复光标位置
#\033[?25| 隐藏光标
#\033[?25h 显示光标
echo -e “\033[?25l 隐藏光标 \033[0m”
echo -e “\033[?25h 显示光标 \033[0m”

Centos7 设置时区

2018年11月25日 没有评论

从centos7开始,我们设置和调整时区不需要像以前那样麻烦要改文件内容。直接运行以下命令就可以了。很方便。

1
2
3
timedatectl list-timezones
 
timedatectl set-timezone Asia/Shanghai

firewalld对指定IP开放指定端口的配置

2018年10月5日 没有评论

1.打开firewalld防火墙

systemctl start firewalld.service
2.添加防火墙规则(对指定ip开放指定端口)
(以下红色字体需要根据实际情况修改)

#(1) Postgresql端口设置。允许192.168.142.166访问5432端口
firewall-cmd –permanent –add-rich-rule=”rule family=”ipv4″ source address=”192.168.142.166″ port protocol=”tcp” port=”5432″ accept”
#(2)redis端口设置。允许192.168.142.166访问6379端口
firewall-cmd –permanent –add-rich-rule=”rule family=”ipv4″ source address=”192.168.142.166″ port protocol=”tcp” port=”6379″ accept”
#(3)beanstalkd端口设置。允许192.168.142.166访问11300端口
firewall-cmd –permanent –add-rich-rule=”rule family=”ipv4″ source address=”192.168.142.166″ port protocol=”tcp” port=”11300″ accept”
3.重启防火墙,使配置生效

systemctl restart firewalld.service
4.查看配置结果,验证配置

firewall-cmd –list-all
5.删除规则

示例:

firewall-cmd –permanent –remove-rich-rule=”rule family=”ipv4″ source address=”192.168.142.166″ port protocol=”tcp” port=”11300″ accept”
systemctl restart firewalld.service

分类: Linux, 解决方案 标签: ,