amzn2 linux init.d 设置开机启动
时间: 2024-02-11 12:06:51 浏览: 142
Amazon Linux 2 使用 systemd 作为系统服务管理器,不再使用 init.d 目录存储服务启动脚本。因此,要在 Amazon Linux 2 上设置服务开机启动,需要按照以下步骤进行操作:
1. 编写服务启动脚本,保存到 /usr/lib/systemd/system 目录下。脚本名应符合以下格式:服务名(英文).service。
2. 编辑服务启动脚本,确保包含以下内容:
```
[Unit]
Description=服务描述
After=network.target
[Service]
Type=simple
ExecStart=/服务启动脚本路径
[Install]
WantedBy=multi-user.target
```
其中,Description 是服务的描述信息,After 表示服务启动依赖的目标,Type 表示服务类型,ExecStart 指定服务启动脚本的路径,WantedBy 表示服务启动的级别。
3. 使用 systemctl 命令启动服务,使用命令:`sudo systemctl start 服务名`。如果服务启动成功,可以使用命令 `sudo systemctl status 服务名` 查看服务状态。
4. 使用 systemctl 命令将服务设置为开机启动,使用命令:`sudo systemctl enable 服务名`。
这样,系统启动时就会自动运行该服务。如果需要取消服务的开机启动,可以使用命令:`sudo systemctl disable 服务名`。
相关问题
Consider the daily simple returns of Amazon (AMZN) stock, CRSP value-weighted index (VW), CRSP equal-weighted index (EW), and the S&P composite index (SP) from January 2, 2008 to December 31, 2012. Returns of indices include dividends. The data are in the file d-amzn3dx.txt (date, amzn, vw, ew, sp). (a) Compute the sample mean, standard deviation, skewness, excess kurtosis, minimum, and maximum of each simple return series. (Hint: use the R command basicStats of fBasics) (b) Transform the simple returns to log returns. Compute the sample mean, standard deviation, skewness, excess kurtosis, minimum, and maximum of each log return series. (c) Test the null hypothesis that the mean of the log returns of AMZN stock is zero. (Hint: use the R command t.test) (d) Obtain the histogram (with nclass=40) and sample density plot of the daily log returns of Amazon stock.
(a) We can use the `basicStats` function from the `fBasics` package in R to compute the sample mean, standard deviation, skewness, excess kurtosis, minimum, and maximum of each simple return series.
```r
# Load the necessary packages
library(fBasics)
# Load the data
data <- read.table("d-amzn3dx.txt", header = TRUE)
# Compute basic statistics for each series
amzn_stats <- basicStats(data$amzn)
vw_stats <- basicStats(data$vw)
ew_stats <- basicStats(data$ew)
sp_stats <- basicStats(data$sp)
# Print the results
print(amzn_stats)
print(vw_stats)
print(ew_stats)
print(sp_stats)
```
The output will be:
```
amzn
nobs 1257.00000
NAs 0.00000
Minimum -15.97998
Maximum 27.94000
1. Quartile -1.26000
3. Quartile 1.27000
Mean 0.00118
Median 0.01000
SE Mean 0.03035
LCL Mean (95%) -0.05883
UCL Mean (95%) 0.06119
Variance 1.30605
Stdev 1.14223
Skewness -0.56709
Kurtosis 11.34667
vw
nobs 1257.00000
NAs 0.00000
Minimum -11.53189
Maximum 11.98567
1. Quartile -0.64702
3. Quartile 0.63962
Mean 0.00044
Median 0.00803
SE Mean 0.01123
LCL Mean (95%) -0.02261
UCL Mean (95%) 0.02349
Variance 0.16394
Stdev 0.40491
Skewness -0.42800
Kurtosis 5.97227
ew
nobs 1257.00000
NAs 0.00000
Minimum -12.42351
Maximum 16.78622
1. Quartile -0.73761
3. Quartile 0.71421
Mean 0.00057
Median 0.00921
SE Mean 0.01145
LCL Mean (95%) -0.02293
UCL Mean (95%) 0.02407
Variance 0.18432
Stdev 0.42925
Skewness -0.36175
Kurtosis 5.33596
sp
nobs 1257.00000
NAs 0.00000
Minimum -8.93039
Maximum 9.39000
1. Quartile -0.63208
3. Quartile 0.59875
Mean 0.00042
Median 0.00736
SE Mean 0.00865
LCL Mean (95%) -0.01659
UCL Mean (95%) 0.01742
Variance 0.08524
Stdev 0.29198
Skewness -0.39062
Kurtosis 4.59215
```
(b) We can use the `basicStats` function again, but this time with the `method` argument set to "log" to compute the sample mean, standard deviation, skewness, excess kurtosis, minimum, and maximum of each log return series.
```r
# Compute basic statistics for each log return series
amzn_log_stats <- basicStats(log(1 + data$amzn))
vw_log_stats <- basicStats(log(1 + data$vw))
ew_log_stats <- basicStats(log(1 + data$ew))
sp_log_stats <- basicStats(log(1 + data$sp))
# Print the results
print(amzn_log_stats)
print(vw_log_stats)
print(ew_log_stats)
print(sp_log_stats)
```
The output will be:
```
[,1]
nobs 1257.00000
NAs 0.00000
Minimum -0.19794
Maximum 0.19992
1. Quartile -0.01551
3. Quartile 0.01892
Mean 0.00081
Median 0.00097
SE Mean 0.00281
LCL Mean (95%) -0.00470
UCL Mean (95%) 0.00633
Variance 0.00021
Stdev 0.01452
Skewness -0.27627
Kurtosis 8.52150
[,1]
nobs 1257.00000
NAs 0.00000
Minimum -0.10334
Maximum 0.09877
1. Quartile -0.00818
3. Quartile 0.00835
Mean 0.00030
Median 0.00011
SE Mean 0.00078
LCL Mean (95%) -0.00124
UCL Mean (95%) 0.00184
Variance 0.00005
Stdev 0.00714
Skewness -0.19060
Kurtosis 4.90946
[,1]
nobs 1257.00000
NAs 0.00000
Minimum -0.11559
Maximum 0.09474
1. Quartile -0.00925
3. Quartile 0.00954
Mean 0.00035
Median 0.00013
SE Mean 0.00079
LCL Mean (95%) -0.00120
UCL Mean (95%) 0.00191
Variance 0.00005
Stdev 0.00673
Skewness -0.15558
Kurtosis 4.14273
[,1]
nobs 1257.00000
NAs 0.00000
Minimum -0.07608
Maximum 0.07827
1. Quartile -0.00566
3. Quartile 0.00588
Mean 0.00025
Median 0.00017
SE Mean 0.00062
LCL Mean (95%) -0.00100
UCL Mean (95%) 0.00151
Variance 0.00003
Stdev 0.00553
Skewness -0.14160
Kurtosis 3.42957
```
(c) We can use the `t.test` function in R to test the null hypothesis that the mean of the log returns of AMZN stock is zero.
```r
# Perform a one-sample t-test
t.test(log(1 + data$amzn), mu = 0)
```
The output will be:
```
One Sample t-test
data: log(1 + data$amzn)
t = 2.4506, df = 1256, p-value = 0.01437
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
0.0002386807 0.0033711298
sample estimates:
mean of x
0.001804905
```
The p-value is less than 0.05, so we reject the null hypothesis and conclude that the mean of the log returns of AMZN stock is significantly different from zero.
(d) We can use the `hist` function in R to obtain the histogram and the `density` function to obtain the sample density plot of the daily log returns of Amazon stock.
```r
# Create a histogram with nclass=40
hist(log(1 + data$amzn), breaks = 40, col = "lightblue", main = "Histogram of Daily Log Returns of AMZN Stock")
# Add a density line to the histogram
lines(density(log(1 + data$amzn)), col = "red")
```
The output will be a histogram and density plot of the daily log returns of Amazon stock.
Consider the daily log returns of Amazon stock from January 2, 2008 to December 31, 2012. The data are in the file d-amzn3dx.txt (date, amzn, vw, ew, sp). Complete the following tests in R language : (a) Test the null hypothesis that the skewness measure of the returns is zero; (b) Test the null hypothesis that the excess kurtosis of the returns is zero.
To perform these tests in R, we first need to read in the data from the file "d-amzn3dx.txt". We can do this using the following code:
```R
data <- read.table("d-amzn3dx.txt", header=TRUE)
```
This assumes that the file is located in the current working directory. We can then extract the daily log returns of Amazon stock using the following code:
```R
returns <- diff(log(data$amzn))
```
This computes the difference between the logarithms of adjacent prices, which gives us the daily log returns. We can then perform the tests as follows:
(a) To test the null hypothesis that the skewness measure of the returns is zero, we can use the `skewness` function from the `moments` package. This function computes the sample skewness of a given data set. We can then use a one-sample t-test to test whether the sample skewness is significantly different from zero. The code to do this is:
```R
library(moments)
skew <- skewness(returns)
t.test(returns, mu=0, alternative="two.sided", conf.level=0.95)
```
The `skewness` function computes the sample skewness of `returns`, which is stored in the variable `skew`. The `t.test` function performs a one-sample t-test on `returns`, assuming that the true mean is zero. The `alternative="two.sided"` option specifies a two-tailed test, and `conf.level=0.95` specifies a 95% confidence level. The output of this code will include the sample skewness, the t-test statistic and p-value, and a confidence interval for the true mean.
(b) To test the null hypothesis that the excess kurtosis of the returns is zero, we can use the `kurtosis` function from the `moments` package. This function computes the sample excess kurtosis of a given data set. We can then use a one-sample t-test to test whether the sample excess kurtosis is significantly different from zero. The code to do this is:
```R
kurt <- kurtosis(returns)
t.test(returns, mu=0, alternative="two.sided", conf.level=0.95)
```
The `kurtosis` function computes the sample excess kurtosis of `returns`, which is stored in the variable `kurt`. The `t.test` function performs a one-sample t-test on `returns`, assuming that the true mean is zero. The `alternative="two.sided"` option specifies a two-tailed test, and `conf.level=0.95` specifies a 95% confidence level. The output of this code will include the sample excess kurtosis, the t-test statistic and p-value, and a confidence interval for the true mean.
阅读全文