徐鼎 发布的文章

[root@localhost sh]# service httpd start
Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain for ServerName
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
  1. 查询到 80 端口被 nginx 占用:

    [root@localhost sh]# netstat -tulnp | grep ":80"
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1327/nginx

  2. 找到 nginx 的进程号:

    [root@localhost sh]# ps -ef | grep nginx
    root 1327 1 0 11:35 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    www 1329 1327 0 11:35 ? 00:00:00 nginx: worker process
    root 3902 1789 0 14:41 pts/0 00:00:00 grep --color=auto nginx

  3. 杀掉进程:

    [root@localhost sh]# kill -9 1327
    [root@localhost sh]# kill -9 1329

  4. 重新开启 Apache:

    [root@localhost sh]# service httpd start
    Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain for ServerName

                                                           [  OK  ]
    

问题:修改了hostname后,如何使其立即生效而不用重启操作系统。
推荐先修改network ,再进行下面操作
修改/etc/sysconfig/network下的HOSTNAME变量 --需要重启生效,永久性修改。

 方法1:修改了/etc/sysconfig/network下的HOSTNAME后,然后使用echo  servername > /proc/sys/kernel/hostname。

         [root@DB-Server ~]# echo Test >/proc/sys/kernel/hostname

          注意当前会话还是不会变化,但是后续新建会话则会生效。

方法2:修改了/etc/sysconfig/network下的HOSTNAME后,然后使用sysctl kernel.hostname命令使其立即生效

    [root@DB-Server ~]# sysctl kernel.hostname=Test2

    kernel.hostname = Test2

    注意当前会话还是不会变化,但是后续新建会话会生效。

方法3:修改了/etc/sysconfig/network下的HOSTNAME后,然后使用hostname命令使其生效

    [root@Test ~]# hostname DB-Server

    注意当前会话还是不会变化,但是后续新建会话会生效。
其实呢,这几种方式只是结合永久性修改和临时性修改hostname,使其不必重启Linux服务器,哈哈,不知道你明白没。

问题: 修改hostname有几种方式?

1:  hostname DB-Server                            --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改  
2:  echo DB-Server  > /proc/sys/kernel/hostname  --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改   
3: sysctl kernel.hostname=DB-Server              --运行后立即生效(新会话生效),但是在系统重启后会丢失所做的修改   
4: **修改/etc/sysconfig/network下的HOSTNAME变量     --需要重启生效,永久性修改。**

参考资料:

http://jblevins.org/log/hostname

http://www.ducea.com/2006/08/07/how-to-change-the-hostname-of-a-linux-system/

https://www.kernel.org/doc/Documentation/sysctl/kernel.txt

http://soft.chinabyte.com/os/281/11563281.shtml

https://www.cnblogs.com/kerrycode/p/3595724.html

一、编写shell脚本文件

 在shell中,$@和"$*"都表示命令行所有参数(不包含$0),但是"$*"将命令行的所有参数看成一个整体,而$@则区分各个参数 eg:

for i in "$@"
do
   echo $i   #会经历$#次循环
done

for i in "$*"
do
   echo $i  #只会进行一次循环,如果$*没有加双引号则会进行$#次循环
done

二、在命令行中输入 sh hello.sh 1 2 3 4 5 6 7

这时候的运行结果是
1
2
3
4
5
6
7
1 2 3 4 5 6 7

CentOS7中执行 service iptables start/stop
会出现iptables 找不到,一直都在Centos 6.x的环境中,发现这个问题挺尴尬的,
在CentOS 7或RHEL 7或Fedora中防火墙由firewalld来管理。
或则使用新的命令进行管理。

假如采用传统请执行一下命令:
systemctl stop firewalld
systemctl mask firewalld
并且安装iptables-services:
yum install iptables-services
systemctl enable iptables

iptables启动、关闭、保存:
systemctl [stop|start|restart] iptables
or
service iptables [stop|start|restart]
service iptables save
or
/usr/libexec/iptables/iptables.init save

如果要添加范围例外端口 如 1000-2000
语法命令如下:启用区域端口和协议组合
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
此举将启用端口和协议的组合。端口可以是一个单独的端口 <port> 或者是一个端口范围 <port>-<port> 。协议可以是 tcp 或 udp。
实际命令如下:
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent