[root@test-huanqiu ~]# visudo
.....
# User privilege specification
pang ALL=(ALL) ALL
[root@test-huanqiu ~]# visudo
.......
# User privilege specification
pang localhost=(root) /bin/chown,/bin/chmod
#这里的NOPASSWD就是配置支持免密执行的字段
pang ALL=(root) NOPASSWD:/usr/bin/vim
# 切换至root用户
sudo su - root
# 修改/etc/sudoers文件权限
chmod 744 /etc/sudoers
# 修改/etc/sudoers文件,添加如下内容,ubuntu为当前用户
ubuntu ALL=(ALL:ALL) NOPASSWD:ALL
# 保存,并恢复权限
chmod 440 /etc/sudoers
# 重启系统
reboot
新启动一个terminal, 测试没有生效。# User privilege specification
root ALL=(ALL:ALL) ALL
pang ALL=(ALL:ALL) NOPASSWD:ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
pang ALL=(ALL:ALL) NOPASSWD:ALL
[root@test-huanqiu ~]# visudo
.....
# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move it further down)
%sudo ALL=(ALL) ALL
和授权给单个用户类似,只不过将用户名在这里换成%组名,所有在该组中的用户都按照此规则进行授权。[pang@localhost ~]$ cat test
cat: test: Permission denied
[pang@localhost ~]$ sudo !!
sudo cat test
lala
xiixixi'
nihao
[pang@localhost ~]$ sudo cd /sys/kernel/debug/
sudo: cd: command not found
[pang@localhost ~]$ sudo bash //或者sudo su - 或者 sudo -s,其实就使用sudo命令从当前用户切换到root用户
[root@localhost debug]# cd /sys/kernel/debug/
[root@localhost debug]#
4.3 sudo操作记入日志[pang@localhost ~]$ sudo touch /var/log/sudo.log
修改/etc/rsyslog.conf配置文件(有些版本系统的这个文件名为/etc/syslog.conf),在该文件加入下面一行[pang@localhost ~]$ sudo vim /etc/rsyslog.conf
.........
local2.debug /var/log/sudo.log //空白不能用空格,必须用tab
[pang@localhost ~]$ sudo vim /etc/sudoers
........
Defaults logfile=/var/log/sudo.log
重启 syslog 服务[pang@localhost ~]$ sudo service rsyslog restart
验证groupadd sudo #因为没有指定gid,所以就按着文件中的gid往后推的
sudo:x:504: #添加完之后在该文件中就出现了这条字段。
sudo:x:504:batman,test #此时,用户batman和test的附属组就是sudo了
此时再visudo%sudo ALL=(root) NOPASSWD:/usr/bin/vim
%sudo ALL=(root) NOPASSWD:/bin/cat
-rw-------. 1 root root 1595 Jul 24 05:00 rsyncd.conf
-rw-------. 1 root root 8 Jul 24 05:00 rsyncd.pass
-rw-------. 1 root root 14 Jul 24 05:00 rsyncd.pwd
[pang@localhost]$ sudo vim rsyncd.conf
发现也是ok的。(1) 重启电脑,进入ubuntu 恢复模式Grub(一直按esc或shift)
(2) 在Grub的菜单中选择root
(3) 重新输入命令 chown root /etc/sudoers
(4) reboot
command sudo visudo
2、在文件末尾,增加如下内容www-data ALL=NOPASSWD: /sbin/iptables, /usr/bin/du
假设你希望使用超级用户(root)权限运行iptables和du命令。但是,如果你想使用超级用户权限运行每一个应用,添加以下命令来代替上面的命令。 www-data ALL=NOPASSWD: ALL
3、就是这样,现在像下面这种方式在你的php脚本中使用exec()函数redis-cli -h ip -p 6401 -a password cluster info<br>
2.集群节点信息redis-cli -h ip -p 6401 -a password cluster nodes<br>
3.节点内存、cpu、key数量等信息(每个节点都需查看)redis-cli -h ip -p 6401 -a password info<br>
4.从redis集群中查看key(只需要连接master节点查看)redis-cli -h ip -p 6401 -a password keys *<br>
b.查看key的value值redis-cli -h ip -p 6401 -a password -c get key<br>
c.查看key值得有效期redis-cli -h ip -p 6401 -a password -c ttl key
ssh root@ip
Password: password
keys *
查看存储的数据剩余过期时间
ttl key<br>
查看key的类型(string,set,list,hash)
type key<br>
查看key的值(string类型)
get key<br>
查看key的值(set类型)
scard key //获取 set 集合中元素的数量
smembers key //查看 set 中的内容<br>
查看key的值(hash类型)
hlen key //获取 key 键的字段数量
hgetall key //返回 key 键的所有字段及其值
hkeys key //获取 key 键中所有字段的名字
hvals key //获取 key 键中所有字段的值
nohup Command [ Arg ... ] [ & ]
参数说明:nohup /root/runoob.sh &
在终端如果看到以下输出说明运行成功:appending output to nohup.out
这时我们打开 root 目录 可以看到生成了 nohup.out 文件。ps -aux | grep "runoob.sh"
参数说明:kill -9 进程号PID
以下命令在后台执行 root 目录下的 runoob.sh 脚本,并重定向输入到 runoob.log 文件:nohup /root/runoob.sh > runoob.log 2>&1 &
2>&1 解释:0 – stdin (standard input,标准输入)
1 – stdout (standard output,标准输出)
2 – stderr (standard error,标准错误输出)
yum install -y epel-release
yum install -y supervisor
systemctl enable supervisord # 开机自启动
systemctl start supervisord # 启动supervisord服务
# systemctl status supervisord # 查看supervisord服务状态
supervisord
运行supervisor时会启动一个进程supervisord,它负责启动所管理的进程,并将所管理的进程作为自己的子进程来启动,而且可以在所管理的进程出现崩溃时自动重启systemctl restart supervisord
supervisorctl (命令管理工具)
可以用来执行start、stop、restart等命令,来对这些子进程进行管理supervisorctl start hyperf
# 重启 hyperf 应用supervisorctl restart hyperf
# 停止 hyperf 应用supervisorctl stop hyperf
# 查看所有被管理项目运行状态supervisorctl status
# 重新加载配置文件supervisorctl update
# 重新启动所有程序supervisorctl reload
网页管理vim /etc/supervisor.conf
[inet_http_server]
port=127.0.0.1:9001
;username=test
;password=123456
systemctl start supervisord
# sudo /usr/bin/supervisord -n -c /etc/supervisord.conf
打开浏览器,输入地址127.0.0.1:9001help
help <action>
shutdown
重载配置文件并重启supervisord和programreload
读取当前运行配置和program配置文件的差异reread
重载配置文件并重启受影响的programupdate
重启program(不会重载配置文件)restart <name>
restart <name> <name>
restart all
clear <name>
clear <name> <name>
clear all
fg <name>
显示supervisord或program IDpid
pid <name>
pid all
start <name>
start <name> <name>
start all
停止programstop <name>
stop <name> <name>
stop all
status <name>
status <name> <name>
status
tail [-f] <name> [stdout|stderr] (default stdout)
输出supervisord最新日志(Ctrl+C退出)maintail [-f]
$stream_opts = [
"ssl" => [
"verify_peer"=>false,
"verify_peer_name"=>false,
]
];
$response = file_get_contents($url, false, stream_context_create($stream_opts));
dd if=/dev/zero of=swapfile bs=1024 count=500000
500000+0 records in
500000+0 records out
512000000 bytes (512 MB) copied, 0.847481 s, 604 MB/s
ll
total 500000
-rw-r--r-- 1 root root 512000000 Sep 11 16:24 swapfile
[root@dics-no iflytek]# mkswap swapfile
Setting up swapspace version 1, size = 499996 KiB
no label, UUID=bf7c48ab-d829-4291-a477-f75cdd33f72a
[root@dics-no iflytek]#
[root@dics-no iflytek]# swapon swapfile
swapon: swapfile: insecure permissions 0644, 0600 suggested.
[root@dics-no iflytek]#
[root@dics-no iflytek]# free -h
total used free shared buffers cached
Mem: 31G 918M 30G 8.3M 704K 589M
-/+ buffers/cache: 328M 30G
Swap: 488M 0B 488M
[root@dics-no iflytek]#
删除swapfile[root@i-5608690E /]# swapoff swapfile
然后再执行删除文件操作[root@i-5608690E /]# rm swapfile
注:如果没有执行swapoff操作,就执行执行删除文件的操作,系统会报错,不给删除。swapoff相当于是卸载swap分区。ls -l | grep "^-"
我们可以用wc命令进行统计:ls -l ./|grep "^-"|wc -l
3.统计文件夹中目录个数ls -l ./|grep "^d"|wc -l
4.统计文件夹下文件个数,包括子文件ls -lR | grep "^-"| wc -l
5.统计文件夹下目录个数,包括子目录ls -lR | grep "^d"| wc -l
./yii migrate/create test_user
执行后,就会在/console/migrations/下面生成m160511_080937_test_user.php。[root@services datacenter_1000]# ./yii migrate/create test_user
Yii Migration Tool (based on Yii v2.0.7)
Create new migration '/www/web/datacenter/datacenter_1000/console/migrations/m160511_080937_test_user.php'? (yes|no) [no]:yes
New migration created successfully.
./yii migrate --migrationPath=@yii/log/migrations/
同样 down() , 采用 safeDown()方法。yii\db\Migration::execute(): 执行一条 SQL 语句
yii\db\Migration::insert(): 插入单行数据
yii\db\Migration::batchInsert(): 插入多行数据
yii\db\Migration::update(): 更新数据
yii\db\Migration::delete(): 删除数据
yii\db\Migration::createTable(): 创建表
yii\db\Migration::renameTable(): 重命名表名
yii\db\Migration::dropTable(): 删除一张表
yii\db\Migration::truncateTable(): 清空表中的所有数据
yii\db\Migration::addColumn(): 加一个字段
yii\db\Migration::renameColumn(): 重命名字段名称
yii\db\Migration::dropColumn(): 删除一个字段
yii\db\Migration::alterColumn(): 修改字段
yii\db\Migration::addPrimaryKey(): 添加一个主键
yii\db\Migration::dropPrimaryKey(): 删除一个主键
yii\db\Migration::addForeignKey(): 添加一个外键
yii\db\Migration::dropForeignKey(): 删除一个外键
yii\db\Migration::createIndex(): 创建一个索引
yii\db\Migration::dropIndex(): 删除一个索引
yii migrate 3
你也可以指定一个特定的迁移,按照如下格式使用 migrate/to 命令来指定数据库应该提交哪一个迁移:yii migrate/to 150101_185401 # using timestamp to specify the migration 使用时间戳来指定迁移
yii migrate/to "2015-01-01 18:54:01" # using a string that can be parsed by strtotime() 使用一个可以被 strtotime() 解析的字符串
yii migrate/to m150101_185401_create_news_table # using full name 使用全名
yii migrate/to 1392853618 # using UNIX timestamp 使用 UNIX 时间戳
yii migrate/down # revert the most recently applied migration 还原最近一次提交的迁移
yii migrate/down 3 # revert the most 3 recently applied migrations 还原最近三次提交的迁移
yii migrate/redo # redo the last applied migration 重做最近一次提交的迁移
yii migrate/redo 3 # redo the last 3 applied migrations 重做最近三次提交的迁移
yii migrate/history # 显示最近10次提交的迁移
yii migrate/history 5 # 显示最近5次提交的迁移
yii migrate/history all # 显示所有已经提交过的迁移
yii migrate/new # 显示前10个还未提交的迁移
yii migrate/new 5 # 显示前5个还未提交的迁移
yii migrate/new all # 显示所有还未提交的迁移
yii migrate/mark 150101_185401 # 使用时间戳来指定迁移
yii migrate/mark "2015-01-01 18:54:01" # 使用一个可以被 strtotime() 解析的字符串
yii migrate/mark m150101_185401_create_news_table # 使用全名
yii migrate/mark 1392853618 # 使用 UNIX 时间戳