29篇 linux related articles

CentOS7 之ifconfig, netstat 取代命令

官方wiki解释是

ifconfig 及 netstat 工具程序在 CentOS 5 及 6 的应用手册内被置标为降级已接近十年,而 Redhat 决定在 CentOS 7 不会缺省安装 net-tools 组件。其中一个转换的原因就是 ifconfig 不会显示界面卡所拥有的全部 IP 位置 —— 请改用 ip 指令。取而代之的工具是 ss 和 ip。假如你真的、真的很需要 ifconfig 和 netstat,你可执行 yum install net-tools。

那就熟悉用这些命令吧

ip 替代 ifconfig

ip a
ip route

ss 替代 netstat

比较好的格式化输出命令为:ss -ntulp | colume -t

Screen Shot 2019-08-20 at 22.22.58.png

还有 ss -nulp4 | cat -A

More ~

centos7 nginx php 访问本地redis报权限问题

事情是这样:nginx 反向代理 php-fpm, php脚本中使用php-redis,实例化Redis对象,并connect本地的redis服务器。本地root账号运行php xxx.php是没有问题的,结果使用http访问时报Permission denied。
如果不提示错误,有可能是php.ini的配置项display_errors是关闭的。

最终找到原因是selinux的安全设置。可以用这个getsebool -a | grep httpd 查看到
httpd_can_network_connect --> off

可以通过下述命令修改
SELinux命令,临时配置,重启后失效
setsebool httpd_can_network_connect=1

写入配置文件的命令,重启后保留
setsebool -P httpd_can_network_connect 1

其它配置项参考 https://wiki.centos.org/zh/TipsAndTricks/SelinuxBooleans

More ~

mac上定时提醒常喝水、多注意休息

Linux的定时功能crontab同样在macos上也可以用。

起因是之前检查过有尿结石,最近小腹疼,还尿出血,感觉又有结石了,所以还是要多喝水,所以写个定时提醒来时刻提醒自己。

先写段shell脚本来设置提醒内容
文件命令为 drink.sh

title="日常提醒"
content="常喝水,常排尿,远离疾病, 爱你的亲"
subtitle="记得喝水"
sound="Pon"
cmd=$(printf 'display notification "%s" with title "%s" subtitle "%s" sound name "%s"' "$content" "$title" "$subtitle" "$sound")
osascript -e "$cmd" 
say -v Ting-ting $content 
More ~

Ubuntu Server 19.04配置静态IP

这个/etc/netplan下默认有个文件50-cloud-init.yaml,直接修改它就行了

sudo vim /etc/netplan/50-cloud-init.yaml

网口名字enp0s3可以通过ip a查到。 这个文件默认已经有网口名字了,将dhcp关闭,填上ip、网关、DNS地址:

network:
    ethernets:
        enp0s3:
            dhcp4: false
            addresses:[192.168.0.201/24]
            gateway4: 192.168.0.1
            nameservers:
                addresses: [192.168.0.1, 8.8.8.8]
    version: 2

保存后,执行 sudo netplan --debug apply 应用更新。
静态IP即可。

More ~

为Ubuntu Server开启SSH

虚拟机安装的Ubuntu Server镜像,向导里需要设置用户账号,没有设置root密码.

1.登陆初始账号,修改root 密码
sudo passwd root

su切换root 试试

2.root 账号下修改配置文件
vi /etc/ssh/sshd_config
找到下面相关配置:

# Authentication:
LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes

更改为:

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

3.重启ssh
sudo service ssh restart

More ~

First start ansible on macos

I installed the ansible via pip install, and there are several issues here:

where is the config

Here you should create a file ~/.ansible.cfg

[defaults]
inventory =~/.ansible/hosts
sudo_user=root
remote_port=22
host_key_checking=False
remote_user=root
log_path=~/.ansible/log/ansible.log
module_name=command
private_key_file=~/.ssh/id_rsa
More ~

也谈华为鸿蒙系统 - Thinks About Huawei Hongmeng

linux_android_huawei.jpg

自从华为被ARM和Android"封锁令"一系列负面消息来袭之后,关于华为的鸿蒙系统新闻层出不穷。
另据国家知识产权局商标查询显示,华为今年5月份和6月份申请了商标名称为"鸿蒙"的多个类目商标。这个时间前后也有许多公司和个人开始抢注"鸿蒙"为关键字的不同类目的商标。
其实按照以往的营销策略,一开始大V如华为高管在微博散布消息,之后开始让媒体热炒,再加上用户的跟风等一系列炒作之后,基本上就可以看到具体上线时间了。不过对于研发一款多平台支持的OS来说并不是易事。

More ~