安装swoole扩展

1
2
3
wget http://luopengtest.gotoip2.com/wdcp/php/swoole-src-swoole-1.7.6-stable.tar.gz
tar xzf swoole-1.7.6-stable.tar.gz
cd swoole-src-swoole-1.7.6-stable

1
2
3
./configure --with-php-config=/www/wdlinux/phps/56/bin/php-config --enable-openssl
make
make install

1
2
3
vi /www/wdlinux/phps/56/etc/php.ini
添加extension=swoole.so
/www/wdlinux/phps/56/bin/php-fpm restart

分享Shell模板

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
#!/bin/bash
rsname=Template #shell名称
rsver=1.0 #shell版本号
base_dir=/usr/local #运行初始目录
mirrorLink=https://www.idiyrom.com #下载地址
flag=$1 #参数

#格式化显示函数
Echo()
{
case $1 in
success) flag="\033[1;32m"
;;
failure) flag="\033[1;31m"
;;
warning) flag="\033[1;33m"
;;
msg) flag="\033[1;34m"
;;
*) flag="\033[1;34m"
;;
esac
if [[ $LANG =~ [Uu][Tt][Ff] ]]
then
echo -e "${flag}${2}\033[0m"
else
echo -e "${flag}${2}\033[0m" iconv -f utf-8 -t gbk
fi
}
#调用方法
#绿色 Echo "success" "成功信息"
#蓝色 Echo "msg" "提示信息"
#红色 Echo "failure" "错误信息"
#黄色 Echo "warning" "警告信息"

Check_OS() {
if [ -n "$(grep 'Aliyun Linux release' /etc/issue)" -o -e /etc/redhat-release ]; then
OS=CentOS
[ -n "$(grep ' 7\.' /etc/redhat-release 2> /dev/null)" ] && CentOS_RHEL_version=7
[ -n "$(grep ' 6\.' /etc/redhat-release 2> /dev/null)" -o -n "$(grep 'Aliyun Linux release6 15' /etc/issue)" ] && CentOS_RHEL_version=6
[ -n "$(grep ' 5\.' /etc/redhat-release 2> /dev/null)" -o -n "$(grep 'Aliyun Linux release5' /etc/issue)" ] && CentOS_RHEL_version=5
elif [ -n "$(grep 'Amazon Linux AMI release' /etc/issue)" -o -e /etc/system-release ]; then
OS=CentOS
CentOS_RHEL_version=6
fi
}

#shell介绍信息
header()
{
printf "
###################################################################
# $rsname version $rsver Author: Ropon <idiyrom.com> #
# For more information please visit https://idiyrom.com/83.html #
#-----------------------------------------------------------------#
# Copyright @2017-2018 idiyrom.com. All rights reserved. #
###################################################################

"
}

#帮助提示
showhelp()
{
header
Echo "msg" "Usage: $rsname [OPTIONS]"
echo
Echo "msg" "OPTIONS:"
Echo "msg" "-h --help : Show help of $rsname"
Echo "msg" "-u --update : update Check for $rsname"
Echo "msg" "-i --install : install $rsname version $rsver to This System"
Echo "msg" "-U --uninstall : Uninstall $rsname from This System"
echo
}

#下载子函数
Download_src() {
[ -s "${src_url##*/}" ] && Echo "msg" "[${src_url##*/}] found" { wget --tries=6 -c --no-check-certificate $src_url; sleep 1; } #判断下载是否已存在
if [ ! -e "${src_url##*/}" ]; then
Echo "msg" "${src_url##*/} download failed, Please check!"
kill -9 $$
fi
}

#调用方法
#src_url=资源URL地址 && Download_src

Install()
{
pushd ${base_dir}/src
Echo "success" "安装完成"
popd
}

Uninstall()
{

Echo "success" "卸载完成"
}

Update()
{
Echo "msg" "暂未开通"
}

#主函数,脚本入口
Main()
{
case $flag in
'-h' '--help' '?' )
showhelp
exit
;;
'--install' '-i' )
Install
exit
;;
'--uninstall' '-U' )
Uninstall
exit
;;
'--update' '-u' )
Update
exit
;;
* )
showhelp
exit
;;
esac
}

Main

Python学习代码记录

1
2
3
4
5
6
7
8
9
10
#!/usr/bin/python
# -*- coding: UTF-8 -*-

num1 = input("Pls input a number: ")
num2 = input("Pls input a number: ")

print "%s + %s = %s" % (num1, num2, num1+num2)
print "%s - %s = %s" % (num1, num2, num1-num2)
print "%s * %s = %s" % (num1, num2, num1*num2)
print "%s / %s = %s" % (num1, num2, num1/num2)

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import redis

#r = redis.Redis(host='127.0.0.1', port=6379,db=0)
#r.set('name', 'zhangsan')
#print (r.get('name'))

pool = redis.ConnectionPool(host='127.0.0.1', port=6379)
r = redis.Redis(connection_pool=pool)
r.set('name', 'lisi') #添加
print (r.get('name')) #获取

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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#coding:utf-8

# 字典创建 while开关 字典添加 字典寻找
dictionary = {}
flag = 'a'
pape = 'a'
off = 'a'
while flag == 'a' or 'c' :
flag = raw_input("添加或查找单词 ?(a/c)")
if flag == "a" : # 开启
word = raw_input("输入单词(key):")
defintion = raw_input("输入定义值(value):")
dictionary[str(word)] = str(defintion) # 添加字典
print "添加成功!"
pape = raw_input("您是否要查找字典?(a/0)") #read
if pape == 'a':
print dictionary
else :
continue
elif flag == 'c':
check_word = raw_input("要查找的单词:") # 检索
for key in sorted(dictionary.keys()): # yes
if str(check_word) == key:
print "该单词存在! " ,key, dictionary[key]
break
else: # no
off = 'b'
if off == 'b':
print "抱歉,该值不存在!"
else: # 停止
print "error type"
break

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
#!/usr/bin/python
# -*- coding: UTF-8 -*-

#num1 = input("Pls input a number: ")
#num2 = input("Pls input a number: ")

#print "%s + %s = %s" % (num1, num2, num1+num2)
#print "%s - %s = %s" % (num1, num2, num1-num2)
#print "%s * %s = %s" % (num1, num2, num1*num2)
#print "%s / %s = %s" % (num1, num2, num1/num2)

#var = 101

#if ( var == 100 ) : print "变量 var 的值为100"

#print "Good bye!"

#x = int(raw_input("pls input a number: "))
#y = int(raw_input("pls input a number: "))
#z = int(raw_input("pls input a number: "))

#aa = [x,y,z]
#list(aa)

#aa.sort()
#print aa

#for i in xrange(10):
# if i == 5:
#print "id:%s" %i
#continue ##当i==3的时候就会跳出此次循环,也就是下面的程序不会再次执行。
# if i == 4: ##当i ==5的时候就直接跳出整个循环。
# break
# print i
#else:
# print "main end"

#import time #插入一个time对象(一切皆对象,)
#import sys #插入一个sys对象

#for i in xrange(10):
# if i == 3:
# continue
# elif i == 5:
# continue
# elif i == 6:
# sys.exit() ## 当i==6的时候主动退出整个脚本。
# print i
#else:
# print "main end"

#import random
#import sys

#bb = random.randint(1,20)
#print bb
#for i in xrange(1,7):
# aa = int(raw_input("pls input a number: "))
# if aa == bb:
# print "you're so smart!!"
# sys.exit()
# elif aa > bb:
# print "pls input a small number."
# else:
# print "pls input a big number."
#else:
# print "time is end!"


#for i in xrange(1,10):
# for j in xrange(1,i+1):
# print "%sx%s=%s" % (j, i, j*i), ## ,的原因是不让程序自动换行
# print

#count=0
#for i in '1234':
# for j in '1234':
# for m in '1234':
# if (i != j) and (j != m) and (i != m):
# print "%s %s %s" % (i, j, m)
#count+=1
#print
#print count

#for i in xrange(100,1000):
# unit = i % 10
# ten = i // 10 % 10
# hundred = i // 100
# if unit ** 3 + ten ** 3 + hundred ** 3 == i:
# print(i)

#for a in 'xyz':
# for b in 'xyz':
# for c in 'xyz':
# if a != b and b != c and c != a:
# if a != 'x' and c != 'x' and c != 'z':
# print "a vs %s b vs %s c vs %s" % (a, b, c)

#list1 = ['x','y','z']
#for a in list1: # a 从 xyz中挑一个对手
# for b in list1: # b 挑一个对手
# if a != b: # a的对手和b的对手不相同
# for c in list1: # c挑一个对手
# if a != c and b != c: # a,b,c,对手互不相同
# if a != 'x' and c != 'x' and c != 'z': # a的对手不是x,c的对手不是x,c的对手不是z
# print "a-{0} b-{1} c-{2}".format(a, b, c) # 打印出结果

#aa = open('/root/study/python/vm.ini')
#for line in aa:
# print line,

#aa = open('/root/study/python/vm.ini')
#while True:
#line=aa.readline()
#if not line:
#break
#print line,


#with open('/proc/meminfo') as aa:
# for line in aa:
# if line.startswith('MemTotal'):
# MemTotal = line.split()[1]
# continue
# if line.startswith('MemFree'):
# MemFree = line.split()[1]
# break
# print "The Memory Total: {:.2f}".format(int(MemTotal)/1024.0) + 'M'
# print "The Memory left: {:.2f}".format(int(MemFree)/1024.0) + 'M'
# print "The Memory left percent: {:.2f}".format((int(MemFree)/1024.0)/(int(MemTotal)/1024.0)*100) + '%'


#mac = '00:0c:29:9c:dc:41' ##本地电脑的Mac地址
#mac_prefix = mac[:-3] ##取出Mac地址的前缀
#last_two = mac[-2:] ##取出MAC地址的后三位
#plus_one = int(last_two, 16) + 1 ##把16进制的mac转换成10进制并+1
#new_last_two = hex(plus_one)[-2:] ##再次把10进制的mac地址转换成原来的16进制,如果不加[-2:],则会出现 0x的前缀
#new_mac = mac_prefix + ':' + new_last_two ##把刚刚整理好的前缀和新的后两位拼接起来。
#print new_mac


#import codecs

'''
/etc/passwd 查找用户,对用户优先级进行排序
'''
#3with codecs.open("passwd", "r") as f:
# result = sorted(f.readlines(), key=lambda x: int(x.split(':')[2]))
# print result
#with codecs.open("sortPasswd", "w") as f:
# f.writelines(result)



#def Jianjia(x):
# y =0.5
# x = x * y
# return x
#print(Jianjia(100))
#print(Jianjia(50))

shell例子

ABCD乘9=DCBA,A=? B=? C=? D=?


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
#!/bin/bash

#A=1
#D=9
for A in `seq 1 1 9`
do
for B in `seq 0 1 9`
do
for C in `seq 0 1 9`
do
for D in `seq 0 1 9`
do
((TEMPA=($A*1000+$B*100+$C*10+$D)*9))
((TEMPB=$D*1000+$C*100+$B*10+$A))
if [ $TEMPA == $TEMPB ];then
echo $A
echo $B
echo $C
echo $D
exit
fi
done
done
done
done

优化shell程序,因ABCD乘9=DCBA ,相乘后还是4位数,A不能大于2,也不能等于0,那么A=1,从而D=9,9*9=81

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

A=1
D=9
for B in `seq 0 1 9`
do
for C in `seq 0 1 9`
do
((TEMPA=($A*1000+$B*100+$C*10+$D)*9))
((TEMPB=$D*1000+$C*100+$B*10+$A))
if [ $TEMPA == $TEMPB ];then
echo $A
echo $B
echo $C
echo $D
exit
fi
done
done

OpenStack实战系列--搭建基本环境

  • 安装Centos7.4系统及优化

安装系统步骤,这里就不赘述,以下优化流程

1
2
3
4
5
6
7
8
cat > /etc/sysconfig/grub <<EOF
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet"
GRUB_DISABLE_RECOVERY="true"
EOF

grub2-mkconfig -o /boot/grub2/grub.cfg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
yum install -y wget

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum install -y net-tools vim tcpdump
systemctl disable firewalld
systemctl stop firewalld
systemctl disable NetworkManager
systemctl stop NetworkManager
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0
echo ' * - nofile 100000 ' >>/etc/security/limits.conf
yum update -y

cat > /etc/hosts <<EOF
172.16.6.220 controller
172.16.6.230 compute1
172.16.6.240 block1
172.16.6.250 object1
EOF

yum install https://rdoproject.org/repos/rdo-release.rpm -y yum install centos-release-openstack-newton python-openstackclient -y   参看官方文档https://docs.openstack.org/mitaka/zh\_CN/install-guide-rdo/

Centos6/7、Ubuntu、Debain 系统盘扩容方法

CentOS6 需要使用gdisk工具,若无可使用yum -y install gdisk命令安装 开始扩容 gdisk /dev/vda p #查看分区 d #删除分区 n #新建分区 p #默认选择主要分区 1 #分区编号 2048 #开始扇区(默认直接回车) xxxxx #结束扇区(默认直接回车) w #保存分区表并退出   Centos7 与Centos6相同,只不过可以直接使用fdisk工具  

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
#!/bin/bash
rsnamedir="/root/auto_expansion.sh"
rclocal_cmd="/root/autodisksystem.sh"
rclocal_dir="/etc/rc.d/rc.local"
fstab_dir="/etc/fstab"
Swapdir="/www/swap"
rsname=auto_expansion #shell名称
LOCKfile=/root/.$(basename $0).lock
LOGfile=/root/.$(basename $0).log
devname="/dev/vda"

Echo()
{
case $1 in
success) flag="\033[1;32m"
;;
failure) flag="\033[1;31m"
;;
warning) flag="\033[1;33m"
;;
msg) flag="\033[1;34m"
;;
*) flag="\033[1;34m"
;;
esac
if [[ $LANG =~ [Uu][Tt][Ff] ]]
then
echo -e "${flag}${2}\033[0m"
else
echo -e "${flag}${2}\033[0m" iconv -f utf-8 -t gbk
fi
#写日志
[ "${3}A" == "LogA" ] && Shell_log $2
}

Shell_log(){
LOG_INFO=$1
Echo "msg" "$(date "+%Y-%m-%d") $(date "+%H:%M:%S"):$rsname:$LOG_INFO" >> $LOGfile
}

Shell_lock(){
touch $LOCKfile
}
Shell_unlock(){
rm -f $LOCKfile
}
Exit(){
Shell_unlock
exit
}

Check_OS()
{
if [ -e /etc/redhat-release ]; then
OS=CentOS
[ -n "$(grep ' 7\.' /etc/redhat-release 2> /dev/null)" ] && OS_Ver=7
[ -n "$(grep ' 6\.' /etc/redhat-release 2> /dev/null)" ] && OS_Ver=6
elif [ -n "$(grep -i 'Debian' /etc/issue 2> /dev/null)" ]; then
OS=Debian
elif [ -n "$(grep -i 'Ubuntu' /etc/issue 2> /dev/null)" ]; then
OS=Ubuntu
else
Echo "failure" "不支持此系统" "Log"
Exit
fi

}

CentOS6()
{
which gdisk >/dev/null 2>&1
[ $? -ne 0 ] && yum -y install gdisk
gdisk $1 << EOF
p
d
n
1
2048


w
y
y
EOF
sed -i "/^nohup \/root\/.*/a$rclocal_cmd" $rclocal_dir
}


CentOS7()
{
fdisk $1 << EOF
p
d
n
p
1
2048

w
EOF
sed -i "/^nohup \/root\/.*/a$rclocal_cmd" $rclocal_dir
}

Debian()
{
fdisk $1 << EOF
p
d
n
p
1
2048

w
EOF
rclocal_dir="/etc/rc.local"
sed -i "/^nohup \/root\/.*/a$rclocal_cmd" $rclocal_dir
}

Ubuntu()
{
fdisk $1 << EOF
p
d
n
p
1
2048

w
EOF
rclocal_dir="/etc/rc.local"
sed -i "/^\/root\/.*/a$rclocal_cmd" $rclocal_dir
}

SwapOff()
{
Swapdir=$(cat /etc/fstab grep swapawk '{print $1}')
swapoff $Swapdir
cp ${fstab_dir}{,_bak}
temp="#${Swapdir} swap swap defaults 0 0"
sed -i "s@${Swapdir}.*@$temp@" $fstab_dir
}

Main()
{
Check_OS
Swap=`free -m awk '/Swap:/{print $2}'`
[ "$Swap" -ne '0' ] && Echo "msg" "根分区存在交换分区,正在关闭。" "Log" && SwapOff
Echo "msg" "当前系统是$OS$OS_Ver,开始扩容。" "Log"
$OS$OS_Ver $devname
Echo "msg" "扩容完成,将创建重启后处理脚本$rclocal_cmd。" "Log"
cat > $rclocal_cmd <<EOF
#!/bin/bash
resize2fs -f /dev/vda1
sed -i '/^\/root\/autodisksystem.sh/d' $rclocal_dir
if [ "$Swap" -ne "0" ]; then
sed -i "s@#${Swapdir}.*@${Swapdir} swap swap defaults 0 0@" $fstab_dir
swapon $Swapdir
fi
[ -e /root/autodisksystem.sh ] && rm -f /root/autodisksystem.sh
[ -e /root/auto_expansion.sh ] && rm -f /root/auto_expansion.sh
EOF
chmod +x $rclocal_cmd
Echo "success" "所有准备工作完成,3秒后自动重启并完成扩容大小" "Log"
Shell_unlock
sleep 3
reboot
}
if [ -f "$LOCKfile" ];then
Echo "warning" "核实脚本正在运行中,请勿重复运行,若是之前强行中断引起的,请手工清理$LOCKfile" "Log" && exit
else
Echo "msg" "首次运行脚本,将自动创建锁文件然后继续,避免在执行中重复运行脚本。" "Log"
Shell_lock
fi
Main

mysql5.5、5.6打包rpm

1、安装rpm工具包

1
yum install rpmbuild rpmdevtools -y

2、初始化rpm基础目录,目录结构如下

1
2
3
4
5
6
7
8
rpmdev-setuptree
ll /root/rpmbuild/
total 20
drwxr-xr-x 2 root root 4096 Jul 5 15:29 BUILD
drwxr-xr-x 2 root root 4096 Jul 5 15:29 RPMS
drwxr-xr-x 2 root root 4096 Jul 5 15:29 SOURCES
drwxr-xr-x 2 root root 4096 Jul 5 15:29 SPECS
drwxr-xr-x 2 root root 4096 Jul 5 15:29 SRPMS

BUILD RPM构建包的地方,编译、配置等操作都在这个目录下执行

RPMS 打包完成RPM包存放路径

SOURCES MySql源码存放路径

SPECS spec文件存放路径(自动应答文件)


3、本次分享打包mysql-5.6.40,将mysql-5.6.40.tar.gz源码文件上传到SOURCES目录下

具体代码 文章末尾


4、执行命令打包

1
rpmbuild -bb rpmbuild/SPECS/mysql.spec

5、完成后在rpmbuild/RPM目录下就会两个rpm包

1
2
-rw-r--r-- 1 root root 52939316 7月 6 10:10 MySQL-5.6.40-1.el6.x86_64.rpm
-rw-r--r-- 1 root root 93863140 7月 6 10:11 MySQL-debuginfo-5.6.40-1.el6.x86_64.rpm

6、直接安装,安装完成后会直接启动Mysql

1
2
3
4
rpm -ivh MySQL-5.6.40-1.el6.x86_64.rpm

不关闭服务直接卸载
rpm -e --nodeps MySQL-5.6.40-1.el6.x86_64
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
#语法:
#TagName: value
#tag名大小写不敏感。

#自定义宏语法:
#%define ropon 2
#使用%{ropon}或者%ropon调用

#RPM包名称,文件中可使用%{name}调用。
Name:mysql
#RPM包版本号,文件中可使用%{version}调用
Version:5.7.25
#打包特定版本号,常指第几次打包,其中dist centos6下是.el6,centos7下是.el7。
Release:1%{?dist}
#RPM包摘要,简单描述RPM包
Summary: %{name}-%{version} RPM
prefix: /usr/local/mysql%{version}

Group: applications/database
License: GPL
URL: http://www.mysql.com

#指定构建需要的源代码,多个源码包,使用Source1,2...,n
Source0: %{name}-%{version}.tar.gz
#_tmppath是/var/tmp
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires: gcc-c++ cmake perl ncurses ncurses-devel libaio numactl numactl-libs perl-Module-Install
Requires: ncurses ncurses-devel libaio numactl numactl-libs perl-Module-Install
Packager: ropon@west.cn

#autoreqprov用来指定自动产生RPM依赖关系
AutoReqProv: no

#RPM包详细描述
%description
%{name} %{version}

%define _mysqlflag 57
%define _runuser mysql
%define _rungroup mysql
%define _dbrootpwd West.cn2020
%define _prefix /local/mysql%{version}
%define _datadir /home/panel/mysql%{_mysqlflag}_data
%define mysqlpath /usr/local/mysql
#对于mysql5.5特殊设置
%define temp #explicit_defaults_for_timestamp

#setup 不加任何选项,仅将软件包打开。
#setup -n newdir 将软件包解压在newdir目录。
#setup -c 解压缩之前先产生目录。
#setup -b num 将第num个source文件解压缩。
#setup -T 不使用default的解压缩操作。
#setup -T -b 0 将第0个源代码文件解压缩。
#setup -c -n newdir 指定目录名称newdir,并在此目录产生rpm套件。

#构建前的准备
%prep
%setup -n mysql-%{version}

#构建
%build
if [ "%{version}" == "5.7.25" ]; then
cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMYSQL_DATADIR=%{_datadir} -DSYSCONFDIR=/etc -DWITH_BOOST=boost
else
cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMYSQL_DATADIR=%{_datadir} -DSYSCONFDIR=/etc
fi
make %{?_smp_mflags}

#安装
%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}

#rpm安装前执行的脚本
%pre
id -u %{_runuser} >/dev/null 2>&1
[ $? -ne 0 ] && useradd -M -s /sbin/nologin %{_runuser}
[ ! -d %{_datadir} ] && mkdir -p %{_datadir}
chown -R %{_runuser}:%{_rungroup} %{_datadir}
chmod -R 744 %{_datadir}

#rpm安装后执行的脚本
%post
service mysqld stop
mv %{mysqlpath} %{mysqlpath}_bak
ln -sf %{_prefix} %{mysqlpath}
if [ "%{version}" == "5.7.25" ]; then
%{_prefix}/bin/mysqld --initialize-insecure --basedir=%{_prefix} --datadir=%{_datadir} --user=%{_runuser}
else
%{_prefix}/scripts/mysql_install_db --basedir=%{_prefix} --datadir=%{_datadir} --user=%{_runuser}
fi
/bin/cp %{_prefix}/support-files/mysql.server /etc/init.d/mysqld
sed -i "s@^basedir=.*@basedir=%{_prefix}@" /etc/init.d/mysqld
sed -i "s@^datadir=.*@datadir=%{_datadir}@" /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
wget -O /etc/my.cnf --no-check-certificate http://panel.ropon.top/panel/lnmp/config/my.txt
[ "%{version}" == "5.5.62" ] && sed -i "s@explicit_defaults_for_timestamp@%{temp}@" /etc/my.cnf
sed -i "s@/usr/local/mysql@%{_prefix}@" /etc/my.cnf
sed -i "s@/home/mysql@%{_datadir}@" /etc/my.cnf
service mysqld start

[ -z "$(grep ^'export PATH=' /etc/profile)" ] && echo "export PATH=%{_prefix}/bin:\$PATH" >> /etc/profile
[ -n "$(grep ^'export PATH=' /etc/profile)" -a -z "$(grep %{_prefix} /etc/profile)" ] && sed -i "s@^export PATH=\(.*\)@export PATH=%{_prefix}/bin:\1@" /etc/profile
source /etc/profile

%{_prefix}/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"%{_dbrootpwd}\" with grant option;"
%{_prefix}/bin/mysql -uroot -p%{_dbrootpwd} -e "delete from mysql.user where Password='';"
%{_prefix}/bin/mysql -uroot -p%{_dbrootpwd} -e "delete from mysql.db where User='';"
%{_prefix}/bin/mysql -uroot -p%{_dbrootpwd} -e "delete from mysql.proxies_priv where Host!='localhost';"
%{_prefix}/bin/mysql -uroot -p%{_dbrootpwd} -e "drop database test;"
%{_prefix}/bin/mysql -uroot -p%{_dbrootpwd} -e "reset master;"

rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona,alisql}*.conf
[ -e "%{_prefix}/my.cnf" ] && rm -rf %{_prefix}/my.cnf
echo "%{_prefix}/lib" > /etc/ld.so.conf.d/mysql.conf
ldconfig
service mysqld restart
echo "mysql root:%{_dbrootpwd}" >> /root/mysql%{_mysqlflag}_password.txt

#rpm卸载前执行的脚本
%preun
service mysqld stop
chkconfig --del mysqld
id -u %{_runuser} >/dev/null 2>&1
[ $? -eq 0 ] && userdel %{_runuser}

#卸载后执行的脚本
%postun
Deldir() {
[ -d $1 ] && rm -rf $1
}

Deldir %{_prefix}
Deldir %{_datadir}
rm -rf /usr/local/mysql

%clean
rm -rf %{buildroot}

%files
%defattr(-, %{_runuser}, %{_rungroup})
%attr(744, %{_runuser}, %{_rungroup}) %{_prefix}/*

%changelog

Linux系统最小文件结构

/boot grub /bin /sbin /etc rc.d init.d sysconfig networking-scripts /lib modules /lib64 /usr local bin sbin lib lib64 bin sbin lib lib64 /proc /sys /dev /var log run lock /tmp 好用的几个命令 stat 显示文件或文件系统详细信息 理解atime ctime mtime atime 指文件被访问的时间 ctime 指文件状态被修改的时间 mtime 指文件被修改的时间 wc,sort,uniq,cut

巧用历史命令--Linux

bash调用命令历史列表中的命令:

!#: 执行命令历史中的第#条命令

!!: 执行上一条命令

!string: 执行命令历史中最近一次以string开头的命令;

!$: 调用上一条命令的最后一个参数

cd /root

netstat -tunpl

ping www.idiyrom.com

ps auxmore

1 2018-06-14 14:42:18 root cd /root/

2 2018-06-14 14:42:22 root netstat -tunpl

3 2018-06-14 14:42:34 root ping www.idiyrom.com

4 2018-06-14 14:42:50 root ps auxmore

5 2018-06-14 14:42:59 root history

!3

ping www.idiyrom.com

w

!!

执行w命令

!net

执行netstat -tunpl

!$

就会把tunpl作为命令执行